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
33
scrobbler.py
33
scrobbler.py
|
|
@ -27,22 +27,24 @@ on Playing()
|
||||||
set iTunesRunning to is_running("Music")
|
set iTunesRunning to is_running("Music")
|
||||||
if iTunesRunning then
|
if iTunesRunning then
|
||||||
tell application "Music"
|
tell application "Music"
|
||||||
set songId to the database ID of the current track
|
|
||||||
set songState to the player state
|
set songState to the player state
|
||||||
set songTitle to the name of the current track
|
tell current track
|
||||||
set songArtist to the artist of the current track
|
set songId to the database ID
|
||||||
set songAlbum to the album of the current track
|
set songTitle to the name
|
||||||
set songAlbumArtist to the album artist of the current track
|
set songArtist to the artist
|
||||||
set songDuration to the duration of the current track
|
set songAlbum to the album
|
||||||
set result to songId & songState & songArtist & songTitle & songAlbum & songDuration & songAlbumArtist
|
set songAlbumArtist to the album artist
|
||||||
return result
|
set songDuration to the duration
|
||||||
|
set result to songId & songState & songArtist & songTitle & songAlbum & songDuration & songAlbumArtist
|
||||||
|
return result
|
||||||
|
end tell
|
||||||
end tell
|
end tell
|
||||||
end if
|
end if
|
||||||
end Playing
|
end Playing
|
||||||
""")
|
""")
|
||||||
old_id = tracked_id = -1
|
old_id = tracked_id = -1
|
||||||
runtime = 0
|
runtime = 0
|
||||||
progress = tqdm()
|
progress = tqdm(dynamic_ncols=True)
|
||||||
progress.set_postfix(scrobbled=False)
|
progress.set_postfix(scrobbled=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,9 +56,17 @@ while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
try:
|
try:
|
||||||
out = tell_iTunes.call("Playing")
|
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)
|
print(e)
|
||||||
continue
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print("ERR", type(e), repr(e))
|
||||||
|
continue
|
||||||
if not out:
|
if not out:
|
||||||
continue
|
continue
|
||||||
id, state, artist, song, album, duration, album_artist = out
|
id, state, artist, song, album, duration, album_artist = out
|
||||||
|
|
@ -67,10 +77,12 @@ while True:
|
||||||
progress.set_postfix(scrobbled=False)
|
progress.set_postfix(scrobbled=False)
|
||||||
runtime = 0
|
runtime = 0
|
||||||
old_id = id
|
old_id = id
|
||||||
|
runtime += 1
|
||||||
progress.n = runtime
|
progress.n = runtime
|
||||||
progress.total = round(duration)
|
progress.total = round(duration)
|
||||||
|
|
||||||
if tracked_id == id:
|
if tracked_id == id:
|
||||||
|
progress.display()
|
||||||
continue
|
continue
|
||||||
if state.code != b"kPSP":
|
if state.code != b"kPSP":
|
||||||
continue
|
continue
|
||||||
|
|
@ -78,7 +90,6 @@ while True:
|
||||||
print("not tracking", duration)
|
print("not tracking", duration)
|
||||||
old_id = tracked_id = id
|
old_id = tracked_id = id
|
||||||
continue
|
continue
|
||||||
runtime += 1
|
|
||||||
if (runtime >= duration / 2 or runtime > 4 * 60) and tracked_id != id:
|
if (runtime >= duration / 2 or runtime > 4 * 60) and tracked_id != id:
|
||||||
progress.set_postfix(scrobbled=True)
|
progress.set_postfix(scrobbled=True)
|
||||||
tracked_id = id
|
tracked_id = id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue