Skip to content

Commit

Permalink
performance & functionality improvements
Browse files Browse the repository at this point in the history
+ changed the way it finds spotify(by pid), you won't need to blacklist program names anymore & also it's way quicker now since it doesn't try to read the song title from the application itsself but actually just uses the window title. this should be as lightweight as possible 🎉
  • Loading branch information
Avnsx authored Jun 25, 2021
1 parent 4129373 commit e1a4594
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions spotify_song_title.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import pywinauto
import pywinauto,psutil,random
from pywinauto.application import Application
from pywinauto import Desktop
from time import sleep as s

blacklist=['Google','Chrome','Sublime','Discord','obs64','OBS','Taskleiste','Taskbar','Firefox','Opera','Edge','Blitz','Lautstärkemixer','File','Explorer','Program','Manager','League','Launcher']

while True:
window_titles=[w.window_text() for w in Desktop(backend="uia").windows()]
best_guess = [f for f in window_titles if all([word not in f for word in blacklist])]
for x in range (0,len(best_guess)):
try:
app_controls = Application(backend="uia").connect(title=best_guess[x])[best_guess[x]]
split_s=best_guess[x].split(' - ')
if split_s[1] or split_s[0] in str(app_controls.GroupBox.texts()[0]):
song_name=str('Song: '+split_s[1]+' by '+split_s[0]+' ♪')
print(song_name)
with open('song_name.txt', 'w', encoding="utf-8") as output:output.write(song_name)
s(10)
break
except:pass
try:
mylist=[]
for proc in psutil.process_iter():
if proc.name() == 'Spotify.exe':
mylist.append(proc.as_dict(attrs=['pid','num_threads'])) #windows only: 'num_handles'
song_name_raw=[w.window_text() for w in Desktop(backend='uia').windows(process=int(max(mylist, key=lambda x: x['num_threads'])['pid']))][0]
except:
input('Spotify not found; Press Enter once you have started Spotify back up...')
continue
if song_name_raw not in ('Spotify Free', 'Spotify Premium'):
song_name=str('Song: '+song_name_raw+' ♪')
print(song_name)
with open('song_name.txt', 'w', encoding='utf-8') as o:o.write(song_name)
s(random.uniform(8,15))

0 comments on commit e1a4594

Please sign in to comment.