From 429193229893e4755ec8208591f19a4fe6ac1e8e Mon Sep 17 00:00:00 2001 From: Ross Ashley Date: Thu, 26 Sep 2013 10:39:32 -0400 Subject: [PATCH] Added ability to store comma delimited lists of genres using lastfm and the local genre.txt file in the usual way. Using this, a song might now have a genre of 'House, IDM, Dance', instead of just 'House'. --- beetsplug/lastgenre/__init__.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 4e5f7bc2d..2c19786bb 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -49,6 +49,10 @@ PYLAST_EXCEPTIONS = ( # Core genre identification routine. +def _split_genre_string(genre): + genres = genre.split(',') + return genres + def _tags_for(obj): """Given a pylast entity (album or track), returns a list of tag names for that entity. Returns an empty list if the entity is @@ -82,10 +86,25 @@ def _find_allowed(genres): """Return the first string in the sequence `genres` that is present in the genre whitelist or None if no genre is suitable. """ + allowed_genres = [] + allowed_genres_copy = [] for genre in list(genres): if _is_allowed(genre): - return genre.title() # Title case. - return None + allowed_genres.append(genre.title()) + +# pdb.set_trace() + + for genre in allowed_genres[:-1]: + genre = genre + ', ' + allowed_genres_copy.append(genre) + else: + if allowed_genres: + allowed_genres_copy.append(allowed_genres[-1]) + + genre_str = '' + return genre_str.join(allowed_genres_copy) +# return genre.title() # Title case. +# return None def _strings_to_genre(tags): """Given a list of strings, return a genre. Returns the first string @@ -107,7 +126,7 @@ def _strings_to_genre(tags): def fetch_genre(lastfm_obj): """Return the genre for a pylast entity or None if no suitable genre - can be found. + can be found. Ex. 'Electronic, House, Dance' """ return _strings_to_genre(_tags_for(lastfm_obj))