Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lastgenre plugin crashes with canonical_tree: yes and prefer_specific: yes #2459

Closed
dropofwill opened this issue Feb 27, 2017 · 3 comments · Fixed by #2583
Closed

Lastgenre plugin crashes with canonical_tree: yes and prefer_specific: yes #2459

dropofwill opened this issue Feb 27, 2017 · 3 comments · Fixed by #2583
Labels
bug bugs that are confirmed and actionable

Comments

@dropofwill
Copy link

Problem

When using the default canonical tree whenever a genre is unmatched _get_depth(genre) will return None, which when combined with prefer_specific will try to sort this None against a bunch of ints. For example Tycho will return this list (note (None, chillout)):

[(0, 'electronic'), (1, 'ambient'), (2, 'post-rock'), (1, 'alternative rock'), (0, 'rock'), (1, 'downtempo'), (None, 'chillout'), (2, 'shoegaze'), (2, 'idm'), (1, 'electronica')]
Traceback (most recent call last):
  File "/Users/wpaul/.asdf/installs/python/3.6.0/bin/beet", line 11, in <module>
    load_entry_point('beets==1.4.3', 'console_scripts', 'beet')()
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beets/ui/__init__.py", line 1209, in main
    _raw_main(args)
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beets/ui/__init__.py", line 1196, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 380, in lastgenre_func
    album.genre, src = self._get_genre(album)
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 322, in _get_genre
    result = self.fetch_album_genre(obj)
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 273, in fetch_album_genre
    u'album', LASTFM.get_album, obj.albumartist, obj.album
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 265, in _last_lookup
    genre = self.fetch_genre(method(*args_replaced))
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 228, in fetch_genre
    return self._resolve_genres(self._tags_for(lastfm_obj, min_weight))
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 213, in _resolve_genres
    tags = self._sort_by_depth(tags)
  File "/Users/wpaul/.asdf/installs/python/3.6.0/lib/python3.6/site-packages/beetsplug/lastgenre/__init__.py", line 178, in _sort_by_depth
    depth_tag_pairs.sort(reverse=True)
TypeError: '<' not supported between instances of 'NoneType' and 'int'

My quick fix was to call _get_depth in a guard:

depth_tag_pairs = [(self._get_depth(t), t) for t in tags if self._get_depth(t) != None]

Obviously we shouldn't be calling this twice without memoizing.

Setup

  • OS: macOS Sierra
  • Python version: 3.6.0
  • beets version: 1.4.3

My configuration (output of beet config) is:

lastgenre:
  canonical: yes
  count: 3
  prefer_specific: yes
@sampsyo sampsyo added the bug bugs that are confirmed and actionable label Feb 27, 2017
@sampsyo
Copy link
Member

sampsyo commented Feb 27, 2017

Thanks for the report and the diagnosis! I agree with your assessment of where the crash comes from.

Since you already have a good handle here on what's going wrong, is there any chance I can convince you to open a pull request? One simple fix, for example, would be to compute that list of pairs as-is and then add a second line that uses a second list comprehension to drop the Nones.

@ghost
Copy link

ghost commented Feb 27, 2017

what would a 0 mean in this context?

@dropofwill
Copy link
Author

I believe a 0 means top-level or in other words least specific genre in the the tree. None occurs whenever a genre doesn't exist in the tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs that are confirmed and actionable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants