1. Adrian Sampson
  2. beets

Commits

Adrian Sampson  committed 00e279f Merge

Merge pull request #96 from pscn/master

Addition to pull request #92 (lastgenre) regarding track level genres and Various Artists compilations

  • Participants
  • Parent commits 234cd08, 7dd8945
  • Branches default

Comments (0)

Files changed (2)

File beets/util/confit.py

View file
         if value not in choices:
             raise ConfigValueError(
                 '{0} must be one of {1}, not {2}'.format(
-                    self.name, repr(value), repr(list(choices))
+                    self.name, repr(list(choices)), repr(value)
                 )
             )
 

File beetsplug/lastgenre/__init__.py

View file
                 result = fetch_artist_genre(obj)
             elif obj.albumartist != 'Various Artists':
                 result = fetch_album_artist_genre(obj)
+            else:
+                # For 'Various Artists' pick the most used common tag as
+                # album_tag
+                artist_genres = {}
+                for item in obj.items():
+                    tmp_genre = None
+                    if 'track' in self.sources:
+                        tmp_genre = fetch_track_genre(item)
+                    if not tmp_genre:
+                        tmp_genre = fetch_artist_genre(item)
+                    if tmp_genre:
+                        artist_genres[tmp_genre] = \
+                            artist_genres.get(tmp_genre, 0) + 1
+                if len(artist_genres) > 0:
+                    result = filter(lambda k:artist_genres[k] ==
+                        max(artist_genres.values()), artist_genres)[0]
 
             if result:
                 return result, 'artist'
                 ))
 
                 for item in album.items():
-                    item.genre, src = self._get_genre(item)
-                    lib.store(item)
-                    log.info(u'genre for track {0} - {1} ({2}): {3}'.format(
-                        item.artist, item.title, src, item.genre
-                    ))
+                    if 'track' in self.sources:
+                        # Fetch track genre only if source is 'track'
+                        item.genre, src = self._get_genre(item)
+                        lib.store(item)
+                        log.info(u'genre for track {0} - {1} ({2}): {3}'.format(
+                            item.artist, item.title, src, item.genre
+                        ))
                     if write:
                         item.write()
 
             log.debug(u'added last.fm album genre ({0}): {1}'.format(
                   src, album.genre))
             for item in album.items():
-                item.genre, src = self._get_genre(item)
-                log.debug(u'added last.fm item genre ({0}): {1}'.format(
-                      src, item.genre))
-                session.lib.store(item)
+                if 'track' in self.sources:
+                    item.genre, src = self._get_genre(item)
+                    log.debug(u'added last.fm item genre ({0}): {1}'.format(
+                          src, item.genre))
+                    session.lib.store(item)
 
         else:
             item = task.item