mirror of
https://github.com/beetbox/beets.git
synced 2025-12-30 04:22:40 +01:00
Merged the ``multiple` and `max_genres` option into one `count`` option.
Updated debug output to waste less lines.
This commit is contained in:
parent
b2a23a58e2
commit
b1570beba9
2 changed files with 15 additions and 35 deletions
|
|
@ -64,31 +64,21 @@ def _tags_for(obj):
|
|||
return []
|
||||
|
||||
tags = []
|
||||
multiple = config['lastgenre']['multiple'].get(bool)
|
||||
if multiple:
|
||||
min_weight = config['lastgenre']['min_weight'].get(int)
|
||||
max_genres = config['lastgenre']['max_genres'].get(int)
|
||||
else:
|
||||
min_weight = -1
|
||||
max_genres = 1
|
||||
min_weight = config['lastgenre']['min_weight'].get(int)
|
||||
count = config['lastgenre']['count'].get(int)
|
||||
|
||||
dbg = []
|
||||
for el in res:
|
||||
# pylast 0.5.x does not use Album.getTopTags, so we don't have a
|
||||
# weight for album tags. However: Album.getInfo (they use that)
|
||||
# returns only ~5 tags, so we use maximum weight for them
|
||||
if isinstance(el, pylast.TopItem):
|
||||
weight = int(el.weight)
|
||||
tag = el.item.get_name().lower()
|
||||
else:
|
||||
weight = 100
|
||||
tag = el.get_name().lower()
|
||||
weight = int(el.weight)
|
||||
tag = el.item.get_name().lower()
|
||||
if _is_allowed(tag):
|
||||
if min_weight > -1 and min_weight > weight and len(tags) > 0:
|
||||
return tags
|
||||
log.debug(u'lastfm.tag (min. {}): {} [{}]'.format(min_weight, tag, weight))
|
||||
tags.append(tag)
|
||||
if len(tags) == max_genres:
|
||||
return tags
|
||||
dbg.append(u'{} [{}]'.format(tag, weight))
|
||||
if len(tags) == count:
|
||||
break
|
||||
log.debug(u'lastfm.tag (min. {}): {}'.format(min_weight, u', '.join(dbg)))
|
||||
return tags
|
||||
|
||||
def _is_allowed(genre):
|
||||
|
|
@ -114,10 +104,7 @@ def _strings_to_genre(tags):
|
|||
tags = find_parents(tags[0], options['branches'])
|
||||
|
||||
tags = [t.title() for t in tags]
|
||||
if config['lastgenre']['multiple']:
|
||||
return u', '.join(tags[:config['lastgenre']['max_genres'].get(int)])
|
||||
else:
|
||||
return tags[0]
|
||||
return u', '.join(tags[:config['lastgenre']['count'].get(int)])
|
||||
|
||||
def fetch_genre(lastfm_obj):
|
||||
"""Return the genre for a pylast entity or None if no suitable genre
|
||||
|
|
@ -213,9 +200,8 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
|
||||
self.config.add({
|
||||
'whitelist': os.path.join(os.path.dirname(__file__), 'genres.txt'),
|
||||
'multiple': False,
|
||||
'min_weight': 10,
|
||||
'max_genres': 3,
|
||||
'count': 1,
|
||||
'fallback': None,
|
||||
'canonical': None,
|
||||
'source': 'album',
|
||||
|
|
|
|||
|
|
@ -86,13 +86,13 @@ Multiple Genres
|
|||
---------------
|
||||
|
||||
By default, the plugin chooses the most popular tag on Last.fm as a genre. If
|
||||
you prefer to use a *list* of popular genre tags, turn on the ``multiple``
|
||||
config option::
|
||||
you prefer to use a *list* of popular genre tags, you can increase the number
|
||||
of the ``count`` config option::
|
||||
|
||||
lastgenre:
|
||||
multiple: true
|
||||
count: 3
|
||||
|
||||
Comma-separated lists of genres will then be used instead of single genres.
|
||||
Comma-separated lists of up to 3 genres will then be used instead of single genres.
|
||||
|
||||
`Last.fm`_ provides a popularity factor aka *weight* for each *tag* ranging
|
||||
from 100 for the most popular *tag* down to 0 for the least popular *tags*.
|
||||
|
|
@ -106,12 +106,6 @@ the ``min_weight`` config option::
|
|||
However, if no tag with a *weight* greater then ``min_weight`` is found, the
|
||||
plugin uses the next best popular *tag*.
|
||||
|
||||
By default, the pulgin uses a maxmimum of 3 genres. You can change this by
|
||||
setting the ``max_genres`` config option::
|
||||
|
||||
lastgenre:
|
||||
max_genres: 5
|
||||
|
||||
|
||||
Running Manually
|
||||
----------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue