From 4be30fca2e08d63eb4bfc21f7704fb95e5ef4d26 Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Sat, 20 Apr 2013 14:28:20 +0200 Subject: [PATCH 1/3] lastgenre: force real lookup during import only if no custom whitelist set. --- beetsplug/lastgenre/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 9b793defe..d3e0e7b5f 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -39,6 +39,7 @@ log = logging.getLogger('beets') LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY) C14N_TREE = os.path.join(os.path.dirname(__file__), 'genres-tree.yaml') +WHITELIST = os.path.join(os.path.dirname(__file__), 'genres.txt') PYLAST_EXCEPTIONS = ( pylast.WSError, @@ -198,7 +199,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): super(LastGenrePlugin, self).__init__() self.config.add({ - 'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'), + 'whitelist': WHITELIST, 'fallback': None, 'canonical': None, 'source': 'album', @@ -347,8 +348,8 @@ class LastGenrePlugin(plugins.BeetsPlugin): def imported(self, session, task): """Event hook called when an import task finishes.""" - # Always force a "real" lookup during import. - if not self.config['force']: + # Force a "real" lookup during import if no custom whitelist set + if self.config['whitelist'].get() == WHITELIST: self.config['force'] = True if task.is_album: From 6fdfabe4b77e0061c70b77a1996535cbf2050781 Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Sun, 21 Apr 2013 10:35:08 +0200 Subject: [PATCH 2/3] Revert "lastgenre: force real lookup during import only if no custom whitelist set." This reverts commit 4be30fca2e08d63eb4bfc21f7704fb95e5ef4d26. --- beetsplug/lastgenre/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index d3e0e7b5f..9b793defe 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -39,7 +39,6 @@ log = logging.getLogger('beets') LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY) C14N_TREE = os.path.join(os.path.dirname(__file__), 'genres-tree.yaml') -WHITELIST = os.path.join(os.path.dirname(__file__), 'genres.txt') PYLAST_EXCEPTIONS = ( pylast.WSError, @@ -199,7 +198,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): super(LastGenrePlugin, self).__init__() self.config.add({ - 'whitelist': WHITELIST, + 'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'), 'fallback': None, 'canonical': None, 'source': 'album', @@ -348,8 +347,8 @@ class LastGenrePlugin(plugins.BeetsPlugin): def imported(self, session, task): """Event hook called when an import task finishes.""" - # Force a "real" lookup during import if no custom whitelist set - if self.config['whitelist'].get() == WHITELIST: + # Always force a "real" lookup during import. + if not self.config['force']: self.config['force'] = True if task.is_album: From 0fb877a059ceecc567062e16d3cf015c3190841c Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Sun, 21 Apr 2013 23:34:20 +0200 Subject: [PATCH 3/3] lastgenre: invert 'force' option default value. --- beetsplug/lastgenre/__init__.py | 6 ++---- docs/plugins/lastgenre.rst | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 9b793defe..e54c32bab 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -202,7 +202,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): 'fallback': None, 'canonical': None, 'source': 'album', - 'force': False, + 'force': True, 'auto': True, }) @@ -315,6 +315,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): lastgenre_cmd = ui.Subcommand('lastgenre', help='fetch genres') lastgenre_cmd.parser.add_option('-f', '--force', dest='force', action='store_true', + default=False, help='re-download genre when already present') lastgenre_cmd.parser.add_option('-s', '--source', dest='source', type='string', @@ -347,9 +348,6 @@ class LastGenrePlugin(plugins.BeetsPlugin): def imported(self, session, task): """Event hook called when an import task finishes.""" - # Always force a "real" lookup during import. - if not self.config['force']: - self.config['force'] = True if task.is_album: album = session.lib.get_album(task.album_id) diff --git a/docs/plugins/lastgenre.rst b/docs/plugins/lastgenre.rst index 3a6b1b137..c08b90204 100644 --- a/docs/plugins/lastgenre.rst +++ b/docs/plugins/lastgenre.rst @@ -35,6 +35,9 @@ Wikipedia`_. .. _pylast: http://code.google.com/p/pylast/ .. _script that scrapes Wikipedia: https://gist.github.com/1241307 +Switch ``force`` flag to False to keep the original genre when member +of the whitelist. + If no genre is found, the file will be left unchanged. To instead specify a fallback genre, use the ``fallback`` configuration option. You can, of course, use the empty string as a fallback, like so::