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

Fetchart: Wikipedia source is not unicode-ready #1960

Closed
wisp3rwind opened this issue Apr 26, 2016 · 2 comments
Closed

Fetchart: Wikipedia source is not unicode-ready #1960

wisp3rwind opened this issue Apr 26, 2016 · 2 comments
Labels
bug bugs that are confirmed and actionable

Comments

@wisp3rwind
Copy link
Member

Fails when formatting artist and title into the basestring request. Beets was a few commits behind master, but I don't think there've been any changes to fetchart since.

The offending album was
http://musicbrainz.org/release/a2f9ef1e-dc73-4054-94f4-5b341660e73e

Traceback (most recent call last):
  File "/usr/bin/beet", line 9, in <module>
    load_entry_point('beets==1.3.18', 'console_scripts', 'beet')()
  File "/usr/lib/python2.7/site-packages/beets/ui/__init__.py", line 1247, in main
    _raw_main(args)
  File "/usr/lib/python2.7/site-packages/beets/ui/__init__.py", line 1237, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python2.7/site-packages/beets/ui/commands.py", line 965, in import_func
    import_files(lib, paths, query)
  File "/usr/lib/python2.7/site-packages/beets/ui/commands.py", line 942, in import_files
    session.run()
  File "/usr/lib/python2.7/site-packages/beets/importer.py", line 336, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/usr/lib/python2.7/site-packages/beets/util/pipeline.py", line 248, in run
    self._run()
  File "/usr/lib/python2.7/site-packages/beets/util/pipeline.py", line 346, in _run
    out = self.coro.send(msg)
  File "/usr/lib/python2.7/site-packages/beets/util/pipeline.py", line 191, in coro
    func(*(args + (task,)))
  File "/usr/lib/python2.7/site-packages/beets/importer.py", line 1389, in plugin_stage
    func(session, task)
  File "/usr/lib/python2.7/site-packages/beets/plugins.py", line 123, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/beetsplug/fetchart.py", line 755, in fetch_art
    candidate = self.art_for_album(task.album, task.paths, local)
  File "/usr/lib/python2.7/site-packages/beetsplug/fetchart.py", line 825, in art_for_album
    for candidate in source.get(album, extra):
  File "/usr/lib/python2.7/site-packages/beetsplug/fetchart.py", line 491, in get
    artist=album.albumartist.title(), album=album.album)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 5: ordinal not in range(128)
@wisp3rwind wisp3rwind added the bug bugs that are confirmed and actionable label Apr 26, 2016
@jackwilsdon
Copy link
Member

jackwilsdon commented Apr 26, 2016

After doing some tests, it seems that the root cause of this is that SPARQL_QUERY is an ASCII string where as either album.albumartist.title() or album.album is a Unicode string.

A simple fix would be to decode SPARQL_QUERY as Unicode, making it into a Unicode string:

--- fetchart.py
+++ fetchart.py
@@ -487,7 +487,7 @@
             params={
                 'format': 'application/sparql-results+json',
                 'timeout': 2500,
-                'query': self.SPARQL_QUERY.format(
+                'query': self.SPARQL_QUERY.decode('utf-8').format(
                     artist=album.albumartist.title(), album=album.album)
             },
             headers={'content-type': 'application/json'},

I'm not sure if this is a good way to fix this, as it may just move the error elsewhere. I'm sure @sampsyo has a better method for fixing this.

@sampsyo
Copy link
Member

sampsyo commented Apr 27, 2016

Thanks! This probably arose recently during the unicode_literals transition. Fixed by using a Unicode literal for the query.

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

No branches or pull requests

3 participants