use tell current track and if the song is not known just make the progress bar a question mark and continue
This commit is contained in:
parent
5c6596b36d
commit
846beba1e8
1 changed files with 22 additions and 11 deletions
29
scrobbler.py
29
scrobbler.py
|
|
@ -27,22 +27,24 @@ on Playing()
|
|||
set iTunesRunning to is_running("Music")
|
||||
if iTunesRunning then
|
||||
tell application "Music"
|
||||
set songId to the database ID of the current track
|
||||
set songState to the player state
|
||||
set songTitle to the name of the current track
|
||||
set songArtist to the artist of the current track
|
||||
set songAlbum to the album of the current track
|
||||
set songAlbumArtist to the album artist of the current track
|
||||
set songDuration to the duration of the current track
|
||||
tell current track
|
||||
set songId to the database ID
|
||||
set songTitle to the name
|
||||
set songArtist to the artist
|
||||
set songAlbum to the album
|
||||
set songAlbumArtist to the album artist
|
||||
set songDuration to the duration
|
||||
set result to songId & songState & songArtist & songTitle & songAlbum & songDuration & songAlbumArtist
|
||||
return result
|
||||
end tell
|
||||
end tell
|
||||
end if
|
||||
end Playing
|
||||
""")
|
||||
old_id = tracked_id = -1
|
||||
runtime = 0
|
||||
progress = tqdm()
|
||||
progress = tqdm(dynamic_ncols=True)
|
||||
progress.set_postfix(scrobbled=False)
|
||||
|
||||
|
||||
|
|
@ -54,9 +56,17 @@ while True:
|
|||
time.sleep(1)
|
||||
try:
|
||||
out = tell_iTunes.call("Playing")
|
||||
except Exception as e:
|
||||
except applescript.ScriptError as e:
|
||||
if e._errorinfo["NSAppleScriptErrorMessage"] == "Music got an error: Can’t get database ID of current track.":
|
||||
progress.set_description("?")
|
||||
progress.set_postfix(scrobbled=False)
|
||||
progress.display()
|
||||
continue
|
||||
print(e)
|
||||
continue
|
||||
except Exception as e:
|
||||
print("ERR", type(e), repr(e))
|
||||
continue
|
||||
if not out:
|
||||
continue
|
||||
id, state, artist, song, album, duration, album_artist = out
|
||||
|
|
@ -67,10 +77,12 @@ while True:
|
|||
progress.set_postfix(scrobbled=False)
|
||||
runtime = 0
|
||||
old_id = id
|
||||
runtime += 1
|
||||
progress.n = runtime
|
||||
progress.total = round(duration)
|
||||
|
||||
if tracked_id == id:
|
||||
progress.display()
|
||||
continue
|
||||
if state.code != b"kPSP":
|
||||
continue
|
||||
|
|
@ -78,7 +90,6 @@ while True:
|
|||
print("not tracking", duration)
|
||||
old_id = tracked_id = id
|
||||
continue
|
||||
runtime += 1
|
||||
if (runtime >= duration / 2 or runtime > 4 * 60) and tracked_id != id:
|
||||
progress.set_postfix(scrobbled=True)
|
||||
tracked_id = id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue