Skip to content
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

Feat/sync artists albums #92

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

c0ball
Copy link
Contributor

@c0ball c0ball commented Nov 27, 2024

No description provided.

Copy link
Collaborator

@timrae timrae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this matching algorithm of just looking at the name would be too error prone to be used reliably. When matching strings like this you generally have to use multiple fields in order to avoid false positives and false negatives, as per the match() function. For albums you should also use the ipc code if it exists

@c0ball
Copy link
Contributor Author

c0ball commented Nov 29, 2024

I've improved the artist and album syncing. When syncing a users' album, the algorithm preferable uses the UPC code to retrieve it from the tidal API, if none is present it uses the search function with a query string and afterwards verifies the name, the artist and the number of tracks (I decided not to include the check for the release date as this reduced the syncing quality as for some reason some albums don't have the same release date as on Spotify...). The artist syncing matches artists by retrieving a few albums of the artist from the Spotify API. Afterwards it searches these albums on tidal and checks whether the artists are the correct one. I've also added a fallback to match an artist by their top tracks if none albums are available.

@c0ball
Copy link
Contributor Author

c0ball commented Nov 29, 2024

If that works for you, I can create a cleanup commit.

@timrae
Copy link
Collaborator

timrae commented Dec 3, 2024

Sure that's a reasonable starting point, I'd need to go through and do some testing to find the right balance between speed and accuracy though. In general the PR needs quite a lot of cleaning up so if you could do your best to clean up, simplify, refactor, and match the existing style that would be appreciated, then I can take over the PR.

try:
albums = spotify_session.artist_albums(artist_id, album_type="album,single", limit=5)['items']
return albums
except Exception as e:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it's very unlikely that you should need to catch a general Exception in a function like this. If there's a specific exception that needs to be handled here then please catch that specific exception. If not then just remove the try block.

Copy link
Collaborator

@timrae timrae Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a maximum of ONE instance of catching except Exception as e for the entire project

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that right. I should have thrown a more specific exception like spotipy.exceptions.SpotifyException. But I removed this function in my last commit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still 6 other instances of catching Exception though ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code to remove most of the try catch blocks. The one remaining in search_album_on_tidal is needed as the method get_albums_by_barcode is raising an ObjectNotFound exception when it cannot find an album with the given UPC.

@timrae
Copy link
Collaborator

timrae commented Dec 3, 2024

Btw have you tested this?

@c0ball
Copy link
Contributor Author

c0ball commented Dec 5, 2024

Yes, I have tested this and can confirm that both the artists and the album syncing do work. I've did some clean up, improved the artist syncing and reduced the number of methods.

Copy link

@julence julence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worked for me

@c0ball
Copy link
Contributor Author

c0ball commented Jan 2, 2025

@timrae does this look good to you now?

@c0ball
Copy link
Contributor Author

c0ball commented Feb 15, 2025

@jlindbergh can you look into this and merge the PR?

@jlindbergh
Copy link
Contributor

@jlindbergh can you look into this and merge the PR?

Hi! Unfortunately I don't have time to look deeper into this, nor have I the privileges to approve a merge. It does look pretty reasonable to me though (without having really tested it...). Not sure what happens with saved spotify sessions when the SPOTIFY_SCOPES changes though? Might cause unexpected issues if spotipy doesn't refresh the session?

@c0ball
Copy link
Contributor Author

c0ball commented Feb 28, 2025

Hi @jlindbergh,
that's unfortunate. Maybe I'll have to continue the project in my fork for now.
As far as I can remember, you had to accept the new permission in the browser, as with the initial setup.

@timrae
Copy link
Collaborator

timrae commented Feb 28, 2025

Sorry I haven't had capacity to look into this. Currently I'm the only maintainer, and am going to be pretty occupied with other projects for at least the next few months. I'd say continuing in your fork for now with the goal of merging back at a later point would be pragmatic for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants