From eafceaa0ed870a154572f9b7d79d6dd3073181c2 Mon Sep 17 00:00:00 2001 From: Peter Schnebel Date: Mon, 14 Oct 2013 12:36:39 +0200 Subject: [PATCH] Added min_weight option to lastgenre, to provide for filtering out unpopulare genres. --- beetsplug/lastgenre/__init__.py | 10 ++++++++++ docs/plugins/lastgenre.rst | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 33fad7628..17f89b041 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -61,11 +61,20 @@ def _tags_for(obj): return [] tags = [] + discarded_tags = [] + min_weight = config['lastgenre']['min_weight'].get(int) for el in res: if isinstance(el, pylast.TopItem): + if min_weight > -1: + if len(tags) > 0 and min_weight > int(el.weight): + discarded_tags.append(el.item.get_name()) + continue el = el.item tags.append(el.get_name()) log.debug(u'last.fm tags: %s' % unicode(tags)) + if min_weight > -1: + log.debug(u'last.fm tags (weight < {0}): {1}'.format( + min_weight, unicode(discarded_tags))) return tags def _is_allowed(genre): @@ -205,6 +214,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): self.config.add({ 'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'), 'multiple': False, + 'min_weight': -1, 'fallback': None, 'canonical': None, 'source': 'album', diff --git a/docs/plugins/lastgenre.rst b/docs/plugins/lastgenre.rst index 37497fa40..51e47aacd 100644 --- a/docs/plugins/lastgenre.rst +++ b/docs/plugins/lastgenre.rst @@ -94,6 +94,15 @@ you prefer to use a list of *all available* genre tags, turn on the Comma-separated lists of genres will then be used instead of single genres. +If you want to filter out less popular tags, you can set the ``min_weight`` +config option:: + + lastgenre: + min_weight: 50 + +Only tags with a weight greater then ``min_weight`` will be used. The weight +ranges from 0 (unpopular) to 100 (most popular). + Running Manually ----------------