forked from Gust4Oliveira/Last.fm-Discord-Rich-Presence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscordRPC.py
66 lines (54 loc) · 1.79 KB
/
DiscordRPC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from pypresence import Presence
import datetime
client_id = '702984897496875072'
RPC = Presence(client_id)
already_enabled = False
already_disabled = True
start_time = None
LastTrack = None
def enable_RPC():
global already_enabled,already_disabled
if already_enabled == False:
RPC.connect()
print('Connected with Discord')
already_enabled = True
already_disabled = False
def update_Status(track, title, artist, time_remaining, username, artwork, buttonIsEnabled):
global start_time, LastTrack
if len(title) < 2:
title = title+" "
if LastTrack == track:
return
print("Now Playing: " + track)
start_time = datetime.datetime.now().timestamp()
LastTrack = track
time_remaining = str(time_remaining)[0:3]
if time_remaining == '0':
time_remaining = None
else:
time_remaining = float(time_remaining) + start_time
lastfmProfileButton = None
if buttonIsEnabled:
lastfmProfileButton = [{"label": "View Last.fm Profile", "url": str("https://www.last.fm/user/" + username)}]
RPC.update(details=title, state=track, end=time_remaining,
large_image=artwork, large_text=track, buttons=lastfmProfileButton)
def disable_RPC():
global already_enabled
global already_disabled
global LastTrack
if already_disabled == False:
RPC.clear()
RPC.close()
print('Disconnected from Discord due to inactivity on Last.fm')
already_disabled = True
already_enabled = False
LastTrack = None
def disconnect():
global already_enabled
global already_disabled
if already_disabled == False:
RPC.clear()
RPC.close()
print('Disconnected from Discord')
already_disabled = True
already_enabled = False