-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support writing ISRC to tracks in Spotify plugin #4996
Conversation
@JOJ0 can you test this out with an album that has ISRC? It seems Spotify returns ISRC at both the album and track levels. Right now, I am importing both. I have never used ISRC, so I'm not sure if that is the right approach. I will look for your guidance here. |
@arsaboo thanks for getting this started. In the meantime I quickfixed this for myself so I could move on with my personal project. Please just cherry-pick this commit into your PR branch: JOJ0@30e0fb1 It implements proper fetching of the full track details and then writing to the TrackInfo object. It's tested, I'm using it. Your current implementation won't work since, as I tried to explain here, we currently only fetch a, so called "SimplifiedTrackObject", which definitely does not contain the track's ISRC. To get it we need to fetch a full track object! Have a look at the example response of the Then have a look at the full track infromation when fetching via the track's endpoint (which my code implements): https://developer.spotify.com/documentation/web-api/reference/get-track |
Regarding album ISRC I don't have a finished commit at hand but I just read the docs again and can report that I would understand that the album-level ISRC is already included via the endpoint we fetch, which is again this one: https://developer.spotify.com/documentation/web-api/reference/get-an-album and the example response contains it already :-) So your current implementation will do! If it helps, I can test from your branch, once you implemented both track-level and album-level ISRC's :-) |
Good catch. Would it make sense to create a separate function to update ISRC for those who want to use it? Otherwise, we are significantly increasing the number of API calls. |
Yeah I'm also thinking about "too many requests errors" (where is our rate-limiting code actually? do we have one? :-)) On the other hand, beets fetches track ISRC per default when using MusicBrainz and Deezer. So making it configurable with Spotify plugin only would be odd or at least would be "non-streamlined" behaviour within beets. IMHO the way to go is trying to support similar things as good as possible throughout sources and try to have similar defaults, to get a streamlined user experience. (repeat: as good as possible) This is how Deezer plugin does it in the Lines 111 to 117 in 708a04d
|
I was curious, we have ISRC for tracks fetching in MusicBrainz since 2020: b6fda63 BTW the MusicBrainz API is smarter about "I now want more info that is not available by default" - you can just tell the API to "include more info" on the initial requests. I wish Spotify's API could do that with albums - it could simply make it configurable of what info to include for the items object. Off-topic but interestingFrom another personal project I played around a lot with the playlists endpoint. Here we have a This is pretty similar to what the MusicBrainz API offers for regular albums and recordings already! configurable API endpoints! Actually an awesome feature! |
We do have the Line 640 in 6cda741
|
The only place where this function is called is here: Lines 480 to 482 in 6cda741
Will it be called when doing a regular import? I'm having a hard time reading that code at the moment...... Lines 438 to 485 in 6cda741
|
It is not called during regular import. The user will have to call |
Well, then this is not the solution I was aiming for. I think this should be similar to other plugins and ISRC should definitely be fetched on initial import. Why make it different? I do not want a second step when importing my tracks via Spotify. I do not have to issue a second step when I use MusicBrainz or Deezer. |
The problem with that approach is that it will definitely cause API errors. Additional API calls for all the tracks for all the albums (even those that are not used) will cause excessive API usage (especially when importing a large number of albums). Even with the current implementation, I sometimes get API errors (partly fixed with #4943). I don't think we should add multiple calls for everyone (not sure how popular/useful the ISRC field is). Once we have the track_ids, we can limit the calls for only those ids. This will significantly economize the number of calls. Just run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi and thanks a lot for the detailed information about the why's and how's! I now understand that at this point just adding an additional fetch to the tracks endpoint will cause rate-limiting trouble. I also now see that you already put some effort into rate-limiting in #4943 and #4946. I'm wondering why this still is not enough, it's actually pretty much what the Spotify docs suggest (Develop a backoff-retry strategy) https://developer.spotify.com/documentation/web-api/concepts/rate-limits).
Should we open another issue, or de we have one already, to further discuss rate limiting ideas?
The problem is that Spotify often (or rather mostly) does not return the retry-after interval. The only option is to give up after a few tries, which is what I did in the previous PR. We can open another issue for a better retry logic, if required. I'll try to fix the other issues tomorrow (thanks for your detailed review). |
Co-authored-by: J0J0 Todos <[email protected]>
Co-authored-by: J0J0 Todos <[email protected]>
Co-authored-by: J0J0 Todos <[email protected]>
Yes please, if you find a minute, please open one. You already started in the very right direction with your retry logic. Going a little further there I'd like to tell you what we've learned when we implemented rate-limiting magic in python3-discogs-client a couple of years ago.
Welcome! Thanks for quickly implementing this! Awesome new feature! |
..., I sometimes get API errors (partly fixed with #4943). I don't think we should add multiple calls for everyone (not sure how popular/useful the ISRC field is). Regarding ratelimiting: As suggested, let's better open a new issue and let's collect ideas together :-) Regarding "how useful is ISRC / what can it be used for": As far as I understand it and use it, it is a unique ID throughout tagging sources and I think it currently is the best way to "link" Deezer, MusicBrainz and Spotify tagged items together My personal usecase is, generating offline-m3u-playlists as pools for my DJ use. I have most of the music I collect on Spotify in my offline-collection on my DJ computer as well. I'm building and ordering playlists on my mobile within the Spotify app, and then can generate m3u playlists by looking up ISRCs via the Spotify playlist API, as well as search in the local beets lib for them. I have fallback searches for artist/title search within my beets library, but actually ISRC is the most accurate way to find exact versions of tracks and the best way for my use-case to generate those playlists. And no sorry I can't make this program available online, it is a super-poluted-all-purpose-personal-super-opinionated-DJ-preparation-tool-with-a-lot-of-crappy-code-and-ten-different-subcommands...
Makes sense!
Oh, great idea using the hook plugin! Thanks! |
Discogs has even less, 60 per minute: https://www.discogs.com/developers#page:home,header:home-rate-limiting -> Let's discuss in new issue PS: Sorry I accidentially edited your original post, but I reverted it as it was before! 😅 |
Description
Fixes #4992
To Do
Tests.