From c4783e25f8b76e103da45d63ea5907bce2dcd522 Mon Sep 17 00:00:00 2001 From: kraymer Date: Tue, 8 May 2012 23:41:07 +0200 Subject: [PATCH 1/2] 'Issue 358:Options for when lastgenre fails to find a tag'. Added 'fallback_str' plugin parameter to specify a fallback string when no genre found. Declare the parameter without specifying a value (= empty string) to blank the genre field when no genre found. --- beetsplug/lastgenre/__init__.py | 17 +++++++++++++++-- docs/plugins/lastgenre.rst | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index ccfb7ec74..0ca4cb919 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -128,6 +128,8 @@ options = { } class LastGenrePlugin(plugins.BeetsPlugin): def configure(self, config): + global fallback_str + wl_filename = ui.config_val(config, 'lastgenre', 'whitelist', None) if not wl_filename: # No filename specified. Instead, use the whitelist that's included @@ -158,12 +160,19 @@ class LastGenrePlugin(plugins.BeetsPlugin): flatten_tree(genres_tree, [], branches) options['branches'] = branches options['c14n'] = True + + fallback_str = ui.config_val(config, 'lastgenre', 'fallback_str', None) + @LastGenrePlugin.listen('album_imported') def album_imported(lib, album, config): + global fallback_str tags = _tags_for(LASTFM.get_album(album.albumartist, album.album)) genre = _tags_to_genre(tags) - if genre: + if not genre and fallback_str != None : + genre = fallback_str + log.debug(u'no last.fm genre found: fallback to %s' % genre) + if genre is not None: log.debug(u'adding last.fm album genre: %s' % genre) album.genre = genre @@ -173,9 +182,13 @@ def album_imported(lib, album, config): @LastGenrePlugin.listen('item_imported') def item_imported(lib, item, config): + global fallback_str tags = _tags_for(LASTFM.get_track(item.artist, item.title)) genre = _tags_to_genre(tags) - if genre: + if not genre and fallback_str != None : + genre = fallback_str + log.debug(u'no last.fm genre found: fallback to %s' % genre) + if genre is not None: log.debug(u'adding last.fm item genre: %s' % genre) item.genre = genre lib.store(item) diff --git a/docs/plugins/lastgenre.rst b/docs/plugins/lastgenre.rst index 598ea630a..ff4e29606 100644 --- a/docs/plugins/lastgenre.rst +++ b/docs/plugins/lastgenre.rst @@ -38,6 +38,13 @@ Wikipedia`_. .. _pylast: http://code.google.com/p/pylast/ .. _script that scrapes Wikipedia: https://gist.github.com/1241307 +If no genre is found, you have the opportunity to specify a fixed string instead +(declare *fallback_str* with no value to blank the genre field):: + + [lastgenre] + faalback_str: + + Canonicalization ---------------- From f93dd6999b6915634056b5764303946f9357d4bb Mon Sep 17 00:00:00 2001 From: kraymer Date: Wed, 9 May 2012 09:08:55 +0200 Subject: [PATCH 2/2] correct typo --- docs/plugins/lastgenre.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/lastgenre.rst b/docs/plugins/lastgenre.rst index ff4e29606..accd7c819 100644 --- a/docs/plugins/lastgenre.rst +++ b/docs/plugins/lastgenre.rst @@ -42,7 +42,7 @@ If no genre is found, you have the opportunity to specify a fixed string instead (declare *fallback_str* with no value to blank the genre field):: [lastgenre] - faalback_str: + fallback_str: Canonicalization