simonxciv / eavesdrop.fm

Eavesdrop.FM automagically takes Plex Webhooks and transmogrifies them into ListenBrainz... listens
https://eavesdrop.fm
MIT License
40 stars 7 forks source link

Add Track MBID if present in the Plex Webhook POST #199

Closed defvs closed 1 month ago

defvs commented 1 month ago

I sniffed the webhooks of Plex for fun... Turns out properly MBID-tagged tracks do have MBID UUIDs sent in the webhook... Weird that nobody noticed. Here's an example webhook POST content:

{
    "event": "media.play",
    "user": true,
    "owner": true,
    "Account": {
        [redacted]
    },
    "Server": {
        [redacted]
    },
    "Player": {
        [redacted]
    },
    "Metadata": {
        "librarySectionType": "artist",
        "ratingKey": "75741",
        "key": "/library/metadata/75741",
        "parentRatingKey": "75740",
        "grandparentRatingKey": "64551",
        "guid": "plex://track/6622d12bf03cec061155e4cb",
        "parentGuid": "plex://album/6622d11af03cec06115354f9",
        "grandparentGuid": "plex://artist/5d07bc87403c640290518e59",
        "parentStudio": "Drum&BassArena",
        "type": "track",
        "title": "Two Fang",
        "grandparentKey": "/library/metadata/64551",
        "parentKey": "/library/metadata/75740",
        "librarySectionTitle": "Drum and Bass",
        "librarySectionID": 12,
        "librarySectionKey": "/library/sections/12",
        "grandparentTitle": "Spor",
        "parentTitle": "Two Fang",
        "summary": "",
        "index": 1,
        "parentIndex": 1,
        "ratingCount": 1100,
        "userRating": 9.0,
        "viewCount": 1,
        "lastViewedAt": 1718401196,
        "lastRatedAt": 1718401097,
        "parentYear": 2024,
        "thumb": "/library/metadata/75740/thumb/1718401062",
        "parentThumb": "/library/metadata/75740/thumb/1718401062",
        "grandparentThumb": "/library/metadata/64551/thumb/1718310361",
        "addedAt": 1718401059,
        "updatedAt": 1718401062,
        "musicAnalysisVersion": "1",
        "Guid": [
            {
                "id": "mbid://d3c67e4c-6589-4612-9efb-d6fb6a7b4db4"
            }
        ]
    }
}

And indeed, Metadata.Guid[0].id contains a beautiful MBID for a track... Which means we can submit it to the API and get actual Album information to ListenBrainz!

Anyways, I've patched a few things to add support for that. I am not that big in the TS territory, so if there's any cleanup to do, I'd advise someone else help me with this!

Cheers.

netlify[bot] commented 1 month ago

Deploy Preview for eavesdropfm ready!

Name Link
Latest commit ee6d79ab1cd3cc3542add1d5447e50501a2083a8
Latest deploy log https://app.netlify.com/sites/eavesdropfm/deploys/667dad7696be670008426b36
Deploy Preview https://deploy-preview-199--eavesdropfm.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

defvs commented 1 month ago

Turns out ListenBrainz does not yet support reading from the MBIDs sent in the JSON. Weird of them... I'll open a ticket tomorrow. I've double checked and the payload sent by Eavesdropfm is correct, so this can probably be merged without consequence, so that whenever it is fixed on LB side, it will works.

defvs commented 1 month ago

In any case - this won't really do anything on LB side until https://tickets.metabrainz.org/browse/LB-1330 is resolved.

defvs commented 1 month ago

I've started another branch, to resolve the track_mbid into release_mbid and recording_mbid because as I said earlier, LB does not yet use track_mbid for matching.

https://github.com/defvs/eavesdrop.fm/tree/track-mbid-resolving if you want to have a look...

defvs commented 1 month ago

Just tested everything now and I can see the track_mbid being properly sent to ListenBrainz (through the "inspect listen"). I can also confirm that it isn't currently taken into account when matching tracks. Yet.

Example (Both tracks are properly tagged with MBIDs and have a different track_mbid linking to two different releases):

Track 1: image image image

Track 2: image image image