beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.88k stars 1.82k forks source link

thumbnail plugin: "AttributeError: 'bytes' object has no attribute 'encode'" when importing an album #2466

Closed Armael closed 7 years ago

Armael commented 7 years ago

Problem

For most of the albums I tried lastly, when running beet import /my/album, the thumbnails plugin crashes with the following error:

Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets==1.4.4', 'console_scripts', 'beet')()
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1209, in main
    _raw_main(args)
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1196, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.6/site-packages/beets/ui/commands.py", line 930, in import_func
    import_files(lib, paths, query)
  File "/usr/lib/python3.6/site-packages/beets/ui/commands.py", line 907, in import_files
    session.run()
  File "/usr/lib/python3.6/site-packages/beets/importer.py", line 325, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/usr/lib/python3.6/site-packages/beets/util/pipeline.py", line 445, in run_parallel
    six.reraise(exc_info[0], exc_info[1], exc_info[2])
  File "/usr/lib/python3.6/site-packages/six.py", line 686, in reraise
    raise value
  File "/usr/lib/python3.6/site-packages/beets/util/pipeline.py", line 358, in run
    self.coro.send(msg)
  File "/usr/lib/python3.6/site-packages/beets/util/pipeline.py", line 171, in coro
    task = func(*(args + (task,)))
  File "/usr/lib/python3.6/site-packages/beets/importer.py", line 1422, in manipulate_files
    session=session,
  File "/usr/lib/python3.6/site-packages/beets/importer.py", line 692, in manipulate_files
    plugins.send('import_task_files', session=session, task=self)
  File "/usr/lib/python3.6/site-packages/beets/plugins.py", line 452, in send
    result = handler(**arguments)
  File "/usr/lib/python3.6/site-packages/beets/plugins.py", line 124, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/beetsplug/fetchart.py", line 814, in assign_art
    self._set_art(task.album, candidate, not self.src_removed)
  File "/usr/lib/python3.6/site-packages/beetsplug/fetchart.py", line 799, in _set_art
    album.set_art(candidate.path, delete)
  File "/usr/lib/python3.6/site-packages/beets/library.py", line 1133, in set_art
    plugins.send('art_set', album=self)
  File "/usr/lib/python3.6/site-packages/beets/plugins.py", line 452, in send
    result = handler(**arguments)
  File "/usr/lib/python3.6/site-packages/beets/plugins.py", line 124, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/beetsplug/thumbnails.py", line 132, in process_album
    wrote &= self.make_cover_thumbnail(album, 256, LARGE_DIR)
  File "/usr/lib/python3.6/site-packages/beetsplug/thumbnails.py", line 144, in make_cover_thumbnail
    target = os.path.join(target_dir, self.thumbnail_file_name(album.path))
  File "/usr/lib/python3.6/site-packages/beetsplug/thumbnails.py", line 166, in thumbnail_file_name
    hash = md5(uri.encode('utf-8')).hexdigest()
AttributeError: 'bytes' object has no attribute 'encode'

Setup

My configuration (output of beet config) is:

importfeeds:
    dir: !!binary |
        L3Bvb2wvbXVzaXF1ZQ==
    relative_to:
    formats: m3u
    m3u_name: imported.m3u
    absolute_path: no
directory: /pool/musique
library: /pool/musiclibrary.blb

plugins: fromfilename embedart fetchart lastgenre thumbnails importfeeds
embedart:
    ifempty: yes
    maxwidth: 0
    auto: yes
    compare_threshold: 0
    remove_art_file: no
fetchart:
    enforce_ratio: 5%
    auto: yes
    minwidth: 0
    maxwidth: 0
    cautious: no
    cover_names:
    - cover
    - front
    - art
    - album
    - folder
    sources:
    - filesystem
    - coverart
    - itunes
    - amazon
    - albumart
    google_key: REDACTED
    google_engine: 001442825323518660753:hrh5ch1gjzm
    fanarttv_key: REDACTED
    store_source: no
lastgenre:
    count: 5
    force: no
    whitelist: yes
    min_weight: 10
    fallback:
    canonical: no
    source: album
    auto: yes
    separator: ', '
    prefer_specific: no

import:
    incremental: yes
    log: /pool/beets_import.log
thumbnails:
    auto: yes
    force: no
    dolphin: no
sampsyo commented 7 years ago

Hi! Any chance you can get a verbose log leading up to this? There should be a line like this:

using (something) to compute URIs

which should help narrow down where the problem is coming from.

Armael commented 7 years ago

Looking at the verbose log, it looks like the corresponding line is thumbnails: using GIO to compute URIs. Should I paste the entire verbose log?

sampsyo commented 7 years ago

No, that will do; thanks! I just pushed a possible fix—could you give the new commit a try and see if that solves the problem?

Armael commented 7 years ago

It seems to have fixed the crash, thanks! I noticed however than the beet import now ends by printing configuration error: importfeeds.dir: must be a filename, not bytes. Is that normal?

sampsyo commented 7 years ago

Great!

That sounds like a separate issue, related to this part of your config:

importfeeds:
    dir: !!binary |
        L3Bvb2wvbXVzaXF1ZQ==

Any particular reason why you have a chunk of binary data in that config option?

Armael commented 7 years ago

Mmh, this only seems to appear in the output of beet config.

My ~/.config/beets/config.yaml is as follows:

directory: /pool/musique
library: /pool/musiclibrary.blb

plugins: fromfilename embedart fetchart lastgenre thumbnails importfeeds

embedart:
    ifempty: yes

fetchart:
    enforce_ratio: 5%

lastgenre:
    count: 5
    force: no

import:
    incremental: yes
    log: /pool/beets_import.log

importfeeds:
    formats: m3u
sampsyo commented 7 years ago

Very strange. That definitely looks wrong… I think I might see the problem, but would you mind opening another bug to track this?

Armael commented 7 years ago

Sure, see #2467