-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
performance & functionality improvements
+ 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
Showing
1 changed file
with
16 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|