From 846beba1e887b2477e898dbacab89fc3868de4f1 Mon Sep 17 00:00:00 2001 From: mugman Date: Thu, 20 Nov 2025 16:49:54 -0500 Subject: [PATCH] use tell current track and if the song is not known just make the progress bar a question mark and continue --- scrobbler.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/scrobbler.py b/scrobbler.py index 0b4660d..96014e9 100644 --- a/scrobbler.py +++ b/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 - set result to songId & songState & songArtist & songTitle & songAlbum & songDuration & songAlbumArtist - return result + 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