miraclx / freyr-js

A tool for downloading songs from music streaming services like Spotify and Apple Music.
https://git.io/freyr-js
Apache License 2.0
1.36k stars 89 forks source link

Add MBID tag to downloaded musics #81

Open Maxmystere opened 2 years ago

Maxmystere commented 2 years ago

It would be really great if it was possible to add MBID tags as some self host music servers (for example LMS) can use it for Scrobbling to services like Listenbrainz

miraclx commented 2 years ago

Interesting... we could certainly integrate this. Problem is matching the right tracks to the proper MBIDs. Currently, all three services freyr supports, provide ISRC information. And a quick search shows we can make lookups on Musicbrains with ISRC and it returns an MBID-like ID.. I'm just not sure if this is an actual MBID.

For example: Billie Eilish's - all the good girls go to hell Freyr identifies it's ISRC as USUM71900766

$ curl "https://musicbrainz.org/ws/2/isrc/USUM71900766?inc=releases&fmt=json" | jq

{
  "isrc": "USUM71900766",
  "recordings": [
    {
      "disambiguation": "",
      "title": "all the good girls go to hell",
      "first-release-date": "2019-03-29",
      "length": 168840,
      "id": "1c3683c9-9008-4777-866b-5aacea6187dc", // <-- this the right ID?
      "video": false
    }
  ]
}
Maxmystere commented 2 years ago

Yup you found a solution in a lot less time than me (I didn't know about that ISRC information) And seems like that id is exactly what's needed for the track https://musicbrainz.org/recording/1c3683c9-9008-4777-866b-5aacea6187dc

Seeing the curl response it might be needed to handle multiple recordings as an answer but the first one should be the best one

miraclx commented 2 years ago

I see. Well, that makes sense. Btw, is this something you'd be interested in working on?

Maxmystere commented 2 years ago

I tried searching on it before adding that ticket but i'm really not enough into JS to handle it well 😄 and as well as you

miraclx commented 2 years ago

Oh, yeah.. Just looked through your repos 🙌🏽. Then again, I don't have that much free time on my hands either. But I'll go ahead and leave this ticket open, perhaps sometime in the future I'd dive in or someone else in the community might take up the initiative.

Maxmystere commented 2 years ago

Do you have leads on where is the best place to add the curl code and variables so that it can be added to the result file ?

I've been trying to read the code but all those async functions make it really hard to debug... And my lack of knowledge in NodeJS is not helping

miraclx commented 2 years ago

You can begin by introducing an async function that takes an ISRC and returns an optional MBID. then thereafter conditionally embedding the value.

On lookup:

Call and await your new function inside the cli:trackBroker async queue. Once you have your MBID, add it to the meta object like the others here.

https://github.com/miraclx/freyr-js/blob/14cd19ab3badf5fae54eb07dfd03fb29aff68412/cli.js#L1038

On embedding:

There's a section for handling metadata embedding, you can add a line here like with ISRC

https://github.com/miraclx/freyr-js/blob/14cd19ab3badf5fae54eb07dfd03fb29aff68412/cli.js#L842-L844