-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotilib.py
106 lines (86 loc) · 2.41 KB
/
spotilib.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import win32gui
import win32api
import os
import re
import urllib.request, urllib.error, urllib.parse
###Virtual-KeyCodes###
Media_Next = 0xB0
Media_Previous = 0xB1
Media_Pause = 0xB3 ##Play/Pause
Media_Mute = 0xAD
###SpotifyInfo###
def getwindow(Title="SpotifyMainWindow"):
window_id = win32gui.FindWindow(Title, None)
return window_id
def song_info():
try:
song_info = win32gui.GetWindowText(getwindow())
except:
pass
return song_info
def artist():
try:
temp = song_info()
artist, song = temp.split("-",1)
artist = artist.strip()
return artist
except:
return "There is nothing playing at this moment"
def song():
try:
temp = song_info()
artist, song = temp.split("-",1)
song = song.strip()
return song
except:
return "There is nothing playing at this moment"
###SpotifyBlock###
def createfolder(folder_path="C:\SpotiBlock"):
if not os.path.exists(folder_path):
os.makedirs(folder_path)
else:
pass
def createfile(file_path="C:\SpotiBlock\Block.txt" ):
if not os.path.exists(file_path):
file = open(file_path, "a")
file.write("ThisFirstLineWillBeIgnoredButIsNecessaryForUse")
def blocklist(file_path="C:\SpotiBlock\Block.txt"):
block_list = []
for line in open(file_path, "r"):
if not line == "":
block_list.append(line.strip())
return block_list
def add_to_blocklist(file_path="C:\SpotiBlock\Block.txt"):
with open(file_path, 'a') as text_file:
if blocklist():
if blocklist()[-1] != song_info():
text_file.write("\n" + song_info())
else:
text_file.write("\n" + song_info())
def reset_blocklist(file_path="C:\SpotiBlock\Block.txt"):
with open(file_path, 'w') as text_file:
text_file.write("ThisFirstLineWillBeIgnored")
pass
def printSong():
if re.match("There is",artist()):
if blocklist():
print("Last Played: ", blocklist()[-1])
else:
createfolder()
add_to_blocklist()
print(artist()) #returns the artist of the current playing song
print(song()) #returns the song title of the current playing song
###Media Controls###
def hwcode(Media):
hwcode = win32api.MapVirtualKey(Media, 0)
return hwcode
def next():
win32api.keybd_event(Media_Next, hwcode(Media_Next))
def previous():
win32api.keybd_event(Media_Previous, hwcode(Media_Previous))
def pause():
win32api.keybd_event(Media_Pause, hwcode(Media_Pause))
def play():
win32api.keybd_event(Media_Pause, hwcode(Media_Pause))
def mute():
win32api.keybd_event(Media_Mute, hwcode(Media_Mute))