FoxxMD / multi-scrobbler

Scrobble plays from multiple sources to multiple clients
https://foxxmd.github.io/multi-scrobbler
MIT License
299 stars 14 forks source link

Mopidy tracks are not being scrobbled correctly to Maloja #110

Closed disi33 closed 5 months ago

disi33 commented 7 months ago

Describe the bug I just created the following setup:

Now when I listen to a song via Mopidy, I do see the multi-scrobbler Mopidy integration kicking in and attempting to scrobble the track, however, it is failing with an Internal Server Error at Maloja.

This is the error log from my multi-scrobbler instance:

2023-11-29T14:16:27-08:00 error   : [Scrobblers] [Maloja - unnamed-mlj] Error occurred while trying to scrobble
ErrorWithCause: 
    at f.doProcessing (CWD/build/server.js:1:45384)
    at async f.startScrobbling (CWD/build/server.js:1:42180)
    at async f.initScrobbleMonitoring (CWD/build/server.js:1:41708)

caused by: Error: Internal Server Error
    at Request.callback (CWD/node_modules/superagent/lib/node/index.js:845:17)
    at CWD/node_modules/superagent/lib/node/index.js:1070:18
    at IncomingMessage.<anonymous> (CWD/node_modules/superagent/lib/node/parsers/json.js:21:7)
    at IncomingMessage.emit (node:events:529:35)
    at endReadableNT (node:internal/streams/readable:1368:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2023-11-29T14:16:27-08:00 error   : [Scrobblers] [Maloja - unnamed-mlj] Scrobble processing interrupted
2023-11-29T14:16:27-08:00 error   : [Scrobblers] [Maloja - unnamed-mlj] Scrobble Error (New) {"payload":{"album":"Stonehenge","albumartists":[{"__model__":"Artist","name":"<artistname>","uri":"spotify:artist:ABCDEFG123456"}],"artists":["<artistname>"],"duration":231,"key":"OvT2rbda3YjgRrGb4cjm0CcX7BPiATiU9TrYYoeOTiCs6Aqe4bYPyCtAlUy5jn","length":234,"time":1701294125,"title":"<title>"},"playInfo":"<artistname> - <title>@ 2023-11-29T13:42:05-08:00"}
2023-11-29T14:16:27-08:00 error   : [Scrobblers] [Maloja - unnamed-mlj] API Call failed: Server Response => Internal Server Error {"response":{"error":{"desc":"The server has encountered an exception.","type":"unknown_error","value":"AttributeError(\"'dict' object has no attribute 'strip'\")"},"status":"failure"},"status":500}

This is the error log from my Maloja instance:

[database] Incoming scrobble [Client: multi-scrobbler | API: native/v1]: {'track_artists': ['<artistname>'], 'track_title': '<trackname>', 'album_title': '<albumname>', 'album_artists': [{'__model__': 'Artist', 'uri': 'spotify:artist:ABCDEFG123456', 'name': '<artistname>'}], 'scrobble_duration': 231, 'track_length': 234, 'scrobble_time': 1701294125}
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/maloja/apis/native_v1.py", line 109, in protector
    return func(*args,**kwargs)
  File "/usr/lib/python3.10/site-packages/maloja/apis/native_v1.py", line 614, in post_scrobble
    result = database.incoming_scrobble(
  File "/usr/lib/python3.10/site-packages/maloja/database/__init__.py", line 110, in incoming_scrobble
    scrobbledict = rawscrobble_to_scrobbledict(rawscrobble, fix, client)
  File "/usr/lib/python3.10/site-packages/maloja/database/__init__.py", line 157, in rawscrobble_to_scrobbledict
    scrobbleinfo['album_artists'] = cla.parseArtists(scrobbleinfo['album_artists'])
  File "/usr/lib/python3.10/site-packages/maloja/cleanup.py", line 87, in parseArtists
    res = [self.parseArtists(art) for art in a]
  File "/usr/lib/python3.10/site-packages/maloja/cleanup.py", line 87, in <listcomp>
    res = [self.parseArtists(art) for art in a]
  File "/usr/lib/python3.10/site-packages/maloja/cleanup.py", line 90, in parseArtists
    if a.strip() in malojaconfig["INVALID_ARTISTS"]:
AttributeError: 'dict' object has no attribute 'strip'

I believe the issue lies within the formatting of the payload that multi-scrobbler is sending to Maloja. Notice how the data of the album_artists property seems to be a list of dicts: "albumartists":[{"__model__":"Artist","name":"<artistname>","uri":"spotify:artist:ABCDEFG123456"}]

The respective code within Maloja that is responsible for parsing/sanitizing this data does not seem to be equipped to handle this case: cleanup.py

multi-scrobbler version used: v0.6.2 Maloja version used: v3.2.1

To Reproduce Set up an environment as described above.

Expected behavior I would expect this data to be properly sanitized into a format that Maloja is expecting. The Maloja API specification is defined here,

Logs See log snippets above.

Versions (please complete the following information): Provide version information for any related sources/clients.

Additional context Additionally, during my I noticed that even when I try to blacklist spotify URIs from being scrobbled through Mopidy using the configuration below, multi-scrobbler still attempts to scrobble any track listened to via the Mopidy-Spotify integration. Not sure if this issue is related.

[
  {
    "name": "MyMopidy",
    "enable": true,
    "data": {
      "url": "ws://mopidy.local:6680/mopidy/ws",
      "uriBlacklist": ["spotify"],
      "uriWhitelist": [],
      "albumBlacklist": []
    }
  }
]
FoxxMD commented 7 months ago

Thanks for the detailed info.

{"payload":{"album":"Stonehenge","albumartists":[{"__model__":"Artist","name":"<artistname>","uri":"spotify:artist:ABCDEFG123456"}],"artists":["<artistname>"],"duration":231,"key":"OvT2rbda3YjgRrGb4cjm0CcX7BPiATiU9TrYYoeOTiCs6Aqe4bYPyCtAlUy5jn","length":234,"time":1701294125,"title":"<title>"},"playInfo":"<artistname> - <title>@ 2023-11-29T13:42:05-08:00"}

Did you replace any of this info (EX substituting <artistname> for a real artist?) or is this exactly as it was in the log?

disi33 commented 7 months ago

I replaced that information, I just didn't want for the exact details what I was listening to to distract from the issue at hand 😂 In the logs themselves that data shows as the actual track/artist/album name and track URL, etc.

disi33 commented 7 months ago

Also, to avoid confusion, I noticed the issue title says "Spotify tracks", when it should actually day "Mopidy tracks". It was already late at night fore when I created it andust have gotten it wrong.

I edited the title to reflect the correct service.

FoxxMD commented 7 months ago

I'll be honest mopidy has been the most infuriating application to setup I've ever had the displeasure of working with. I run arch linux, docker, virtual machines, the works. I've debugged esoteric java webapplets that were easier to figure out than mopidy. So far mopidy, native, has failed to work with pulseaudio or pipewire. It doesn't work in docker with three different iris/built-in implementations I've tried. It worked at some point in the past but I spent the last 3 hours trying to get anything to play with constant errors.

I'm using the official mopidy js implementation and have made a change that may fix your issue but i cannot test it myself. Please use foxxmd/multi-scrobbler:develop docker image and let me know if that resolves things for you .

FoxxMD commented 7 months ago

@disi33 have you had a chance to test this?

disi33 commented 7 months ago

Thank you for addressing this, very much appreciated! Apologies, life kind of got in the way, I will try to confirm the fix in the next few days!

disi33 commented 6 months ago

hey @FoxxMD apologies again for the long wait - of course my homelab server died! I was just recently able to recover the server and I can confirm with your fix in the :develop image everything works like a charm!

Thanks for looking into this - very much appreciated! And sorry again for leaving you hanging there for a while!

FoxxMD commented 5 months ago

Fixed in 0.6.3