Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Don't use inconsistent albumId or artistId (#233)
Browse files Browse the repository at this point in the history
* Don't use `albumId` or `artistId` from Google, as it doesn't always exist

* Remove commented code

* Add pipe to separate sections of album ID

* Add logging for library refresh

* Hopefully fix indentations

* Ran `black .`
  • Loading branch information
jjok authored Mar 10, 2020
1 parent 3f378dd commit a4a7846
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions mopidy_gmusic/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ def sorter(track):
return sorted(tracks, key=sorter)

def refresh(self, uri=None):
logger.info("Refreshing library")

self.tracks = {}
self.albums = {}
self.artists = {}
Expand Down Expand Up @@ -407,6 +409,13 @@ def refresh(self, uri=None):
for artist in album.artists:
self.artists[artist.uri] = artist

logger.info(
"Loaded "
f"{len(self.artists)} artists, "
f"{len(self.albums)} albums, "
f"{len(self.tracks)} tracks from Google Play Music"
)

def search(self, query=None, uris=None, exact=False):
if exact:
return self._find_exact(query=query, uris=uris)
Expand Down Expand Up @@ -589,9 +598,7 @@ def _to_mopidy_album(self, song):
artist = self._to_mopidy_album_artist(song)
date = str(song.get("year", 0))

album_id = song.get("albumId")
if album_id is None:
album_id = create_id(artist.name + name + date)
album_id = create_id(f"{artist.name}|{name}|{date}")

uri = "gmusic:album:" + album_id
return Album(
Expand All @@ -605,11 +612,7 @@ def _to_mopidy_album(self, song):

def _to_mopidy_artist(self, song):
name = song.get("artist", "")
artist_id = song.get("artistId")
if artist_id is not None:
artist_id = artist_id[0]
else:
artist_id = create_id(name)
artist_id = create_id(name)
uri = "gmusic:artist:" + artist_id
return Artist(uri=uri, name=name)

Expand Down

4 comments on commit a4a7846

@tryinit6
Copy link

Choose a reason for hiding this comment

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

I've tried this, but some problems seems not to be resolved. Some albums are shown multiple times. I played a bit around with the line 601: album_id = create_id(f"{name}") this solves the issue showing albums multiple times, but the tracks are not merged in one album together, so that I only see some of them, any suggestions?

@jjok
Copy link
Contributor Author

@jjok jjok commented on a4a7846 Apr 26, 2020

Choose a reason for hiding this comment

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

It groups albums by artist, track and year. The only place I've seen issues is where the year isn't set the same on all tracks that I'm expecting to appear all on one album.

I've been able to fix anything that still looks wrong by fixing the metadata in Google Play Music itself.

@tryinit6
Copy link

Choose a reason for hiding this comment

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

Indeed, I can confirm, after correcting the Album-Year, the Album-Listing in Mopidy work as expected. Unfortunaley for Compilations you'll overwrite correct Year-Informations of the songs

@jjok
Copy link
Contributor Author

@jjok jjok commented on a4a7846 Apr 28, 2020

Choose a reason for hiding this comment

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

Yes, that's the only legitimate issue I've found. I think most of my compilations must have the year set for the whole album, so work fine. ie the tracks have the year of the album, rather than the year of the track. I've got a couple where each track has a different year though.

Please sign in to comment.