Berulacks / yams

A Last.FM scrobbler for MPD (Yet Another Mpd Scrobbler)
GNU General Public License v3.0
46 stars 7 forks source link

KeyError: duration #3

Closed YodaEmbedding closed 5 years ago

YodaEmbedding commented 5 years ago

With Mopidy-Gmusic, I get the following error:

λ yams -N
/usr/lib/python3.7/site-packages/yams/configure.py:59: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read htt
ps://msg.pyyaml.org/load for full details.
  config = yaml.load(config_stream)
2019-07-30 21:45:31,070 - yams - INFO - Config found, reading from config at /home/mulhaq/.config/yams/yams.yml...
2019-07-30 21:45:31,070 - yams - INFO - Writing log to file: /home/mulhaq/.config/yams/yams.log
2019-07-30 21:45:31,070 - yams - INFO - Starting up YAMS v0.69
2019-07-30 21:45:31,071 - yams - INFO - Connected to mpd, version: 0.19.0
2019-07-30 21:45:31,071 - yams - INFO - Wrote PID to file: /home/mulhaq/.config/yams/yams.pid
2019-07-30 21:45:31,076 - yams - ERROR - Something went very wrong!
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/yams/scrobble.py", line 723, in cli_run
    mpd_watch_track(client,session,config)
  File "/usr/lib/python3.7/site-packages/yams/scrobble.py", line 550, in mpd_watch_track
    song_duration = float(song["duration"])
KeyError: 'duration'
2019-07-30 21:45:31,077 - yams - INFO - Shutting down...

Investigating a bit, I tried the following in my REPL:

>>> from pprint import pprint
>>> from mpd import MPDClient
>>> client = MPDClient()
>>> client.connect('localhost', 6600)
>>> pprint(client.currentsong())
{'album': 'Images And Words',
 'albumartist': 'Dream Theater',
 'artist': 'Dream Theater',
 'date': '1992',
 'disc': '1',
 'file': 'gmusic:track:Teweagnbwsk3meqqxqbrxbfwxxa',
 'id': '6',
 'pos': '5',
 'time': '423',
 'title': 'Under a Glass Moon',
 'track': '6',
 'x-albumimage': 'http://lh3.googleusercontent.com/f20b_maEQ1JYTPt4rnlbGA_cH2aT_X6U-qAT8atqoyAUQDvltB9tWDlXVut11LNAfh_5vwdXjw',
 'x-albumuri': 'gmusic:album:Bemiarb7y3je7rb6ifwwzodf37q'}

Looks like the key 'time' holds the duration value. Changing 'duration' to 'time' seems to fix things.

Berulacks commented 5 years ago

Ooph, well that's fun. I guess as a hack we can just check for time assuming the key duration isn't available, but that could be an issue later. Is it like this with all tracks reported by mopidy?

Edit: Okay, for some odd reason Mopidy is using an older version of the mpd protocol as it's using time as opposed to duration, and using time is deprecated.

I'll add a little hack there (later today) for mopidy so it works, but you should definitely go wag your finger at them :D they should be sending a duration parameter

Edit 2: Yep, here's where Mopidy's doing the no-bueno

Edit 3: In certain places I'm also using time as opposed to duration. Welp, guess I'll change those, too.

Edit 4: time is the deprecated form of elapsed in status/currentsong calls? But when querying for metadata via lsinfo, time is then the deprecated form of duration? And for some reason the MPD python client is returning the latter when querying the former? The fun never stops around here, I tell you.

Berulacks commented 5 years ago

Fixed with https://github.com/Berulacks/yams/commit/65e8ab8b7bf004677cab6f6b40668f6c89347d9f

Could you try running from master and let me know if it works for you? I'll prepare a release accordingly.

YodaEmbedding commented 5 years ago

Looks like it works.


Separate issue I encountered while installing via setup.py, but the latest version of PyYAML is 5.1.1 and requests is 2.21.0.

Berulacks commented 5 years ago

Any reason to upgrade PyYAML or requests? I tend to keep dependencies' versions stable unless I have a need to update.

Regardless, closing this issue as it seems sorted!

YodaEmbedding commented 5 years ago

So yams was running fine for a few days until this happened:

$ systemctl --user status --no-pager yams.service

Nov 05 06:14:02 PC-Mordor-Arch yams[2728]: 2019-11-05 06:14:02,785 - yams - INFO - Playing Rubylove, 0/157s (0.0%)
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]: 2019-11-05 06:14:07,927 - yams - ERROR - Something went very wrong!
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]: Traceback (most recent call last):
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]:   File "/usr/lib/python3.7/site-packages/yams/scrobble.py", line 841, in cli_run
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]:     mpd_watch_track(client,session,config)
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]:   File "/usr/lib/python3.7/site-packages/yams/scrobble.py", line 622, in mpd_watch_track
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]:     song_duration = float(song["duration"] if "duration" in song else song["time"])
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]: KeyError: 'time'
Nov 05 06:14:08 PC-Mordor-Arch yams[2728]: 2019-11-05 06:14:08,100 - yams - INFO - Shutting down...
Nov 05 06:14:09 PC-Mordor-Arch systemd[679]: yams.service: Succeeded.

Not entirely sure what caused it, since yams started working again after restarting yams.service.

Berulacks commented 5 years ago

That's really weird because the line "Playing Rubylove, 0/157s" uses the same float(song["duration"] if "duration" in song else song["time"]) code to grab the song's duration (157 seconds) in mpd_wait_for_play(). So it seems that something broke between both calls.

I wonder why the song would have been passed without a duration variable? Perhaps an mpd error?

Let me know if it happens again and I'll add some aggressive debug logging to that area, but I think it was most likely a Mopidy/MPD issue.

WurdahMekanik commented 4 years ago

That's really weird because the line "Playing Rubylove, 0/157s" uses the same float(song["duration"] if "duration" in song else song["time"]) code to grab the song's duration (157 seconds) in mpd_wait_for_play(). So it seems that something broke between both calls.

I wonder why the song would have been passed without a duration variable? Perhaps an mpd error?

Let me know if it happens again and I'll add some aggressive debug logging to that area, but I think it was most likely a Mopidy/MPD issue.

I repeatedly have issues where a song is passed without "duration" or "time" but have tracked it to occasions where I'm listening to podcasts. I don't know much about the mpd protocol, but it seems like there isn't necessarily a duration associated with a stream.

I'm using mpd v0.22

danielg0 commented 4 years ago

Yeah, you're right, you can have MPD streams that don't have a duration associated with it (online radio, podcasts). Helpfully, MPD provides a player status with a time value that is always present (it holds a value of 0 if there is no duration). Pull requests #6 and #5 use this to calculate progression through a song, so internet streams can be played without crashing yams (but they still can't be scrobbled as we can't see how long it is). There hasn't been a release since they were merged though, so you'd have to install manually from github in order to use the fix.

Berulacks commented 4 years ago

Yes, that's my bad - I'll make a release!

Berulacks commented 4 years ago

Okay, the PyPi and AUR packages have been updated to the new release (0.7.3), feel free to update and try again @WurdahMekanik

WurdahMekanik commented 4 years ago

Seems to work for me!