Beets: replaygain: Check for R128 tags fails on opus files when values are missing

Created on 28 Jun 2017  路  12Comments  路  Source: beetbox/beets

Problem

I enabled the replaygain plugin and attempted to compute tags for an album.
Output:

% beet -vv replaygain -a 'Brandenburg Concerti'
user configuration: /home/gandalf3/.config/beets/config.yaml
data directory: /home/gandalf3/.config/beets
plugin paths: 
Sending event: pluginload
library database: /home/gandalf3/data/music.db
library directory: /home/gandalf3/music
Sending event: library_opened
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/beets/dbcore/db.py", line 336, in __getattr__
    return self[key]
  File "/usr/lib/python3.6/site-packages/beets/dbcore/db.py", line 243, in __getitem__
    raise KeyError(key)
KeyError: 'r128_item_gain'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets==1.4.5', 'console_scripts', 'beet')()
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1256, in main
    _raw_main(args)
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1243, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 1010, in func
    self.handle_album(album, write)
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 900, in handle_album
    if not self.album_requires_gain(album):
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 859, in album_requires_gain
    for item in album.items()]) or \
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 859, in <listcomp>
    for item in album.items()]) or \
  File "/usr/lib/python3.6/site-packages/beets/dbcore/db.py", line 338, in __getattr__
    raise AttributeError(u'no such field {0!r}'.format(key))
AttributeError: no such field 'r128_item_gain'

Setup

  • OS: Archlinux
  • Python version: 3.6.1
  • beets version: 1.4.5
  • Turning off plugins made problem go away (yes/no): well, yes, but the functionality in question also went away ;)

My configuration (output of beet config) is:

directory: ~/music
library: ~/data/music.db

plugins: mpdstats chroma edit smartplaylist info replaygain
smartplaylist:
    playlist_dir: ~/.config/mpd/playlists
    playlists: [{name: all.m3u, query: ''}, {name: baroque.m3u, query: 'genre:baroque'}]
    relative_to:
    auto: yes
replaygain:
    auto: no
    backend: bs1770gain
    overwrite: no
    targetlevel: 89
    r128: [Opus]
    chunk_at: 5000
    method: replaygain

import:
    copy: no
    write: no
chroma:
    auto: yes
mpd:
    music_directory: /home/gandalf3/music
    rating: yes
    rating_mix: 0.75
    host: localhost
    port: 6600
    password: REDACTED
edit:
    albumfields: album albumartist
    itemfields: track title artist album
    ignore_fields: id path
bug

Most helpful comment

Sure, I'll look at it next week.

All 12 comments

Thank you for the report! It looks like this was a regression introduced in #2560. @autrimpo, would you mind taking a look? We may need to turn item.r128_item_gain into item.get('r128_item_gain') to avoid crashing when the value is missing.

Sure, I'll look at it next week.

I couldn't reproduce the issue, could you post some more info about the files? I assume they were imported into the db before the 1.4.5 release. What format are they in?
I tried both Python 2 and 3 and the results were the same, however my distro has only Python 3.5. Maybe it's a 3.6 specific bug?

I've got the same issue on import. Running master on Arch with Python 3.6.1-1.

The files I tested are all .opus files. Sure enough, it seems to work if I analyze an album with only .ogg files.

I'm still unable to reproduce the issue.
Here's what I did:

  1. Checkout the 1.4.3 tag from the repo
  2. Import an album with Opus files (with replaygain set to auto: no)
  3. Check the file metadata if they contain any replaygain/R128 tags (they do not)
  4. beet -vv replaygain -a 'album:THEALBUM' with the 1.4.5 version of beets

I found an issue with the logic in the handle_album function, the condition on lines 906-907 is missing a not so it falsely throws exceptions, but with that fixed, the replaygain command runs fine.

I'm going to set up an Arch VM and try reproduce the bug there.

I also haven't been able to directly reproduce the crash, but I think I do see the problem: it should be r128_track_gain, not r128_item_gain, on that line. :smiley:

I've created a new branch r128-#2615 where I've pushed the possible fix, could you clone it and see if it works, since I can't reproduce the bug?

@autrimpo I can confirm this fixes it for me, thanks!

@gandalf3 Could you leave this issue open until it's fixed in the beetbox repository (that is, #2623 is merged)?

Getting this issue still on beets version 1.4.5
Python version 3.6.2
plugins: absubmit, acousticbrainz, chroma, edit, embedart, fetchart, info, lyrics, mbsync, missing, mpdstats, mpdupdate, replaygain

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/beets/dbcore/db.py", line 336, in __getattr__
    return self[key]
  File "/usr/lib/python3.6/site-packages/beets/dbcore/db.py", line 243, in __getitem__
    raise KeyError(key)
KeyError: 'r128_item_gain'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets==1.4.5', 'console_scripts', 'beet')()
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1256, in main
    _raw_main(args)
  File "/usr/lib/python3.6/site-packages/beets/ui/__init__.py", line 1243, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.6/site-packages/beets/ui/commands.py", line 934, in import_func
    import_files(lib, paths, query)
  File "/usr/lib/python3.6/site-packages/beets/ui/commands.py", line 911, 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 693, in reraise
    raise value
  File "/usr/lib/python3.6/site-packages/beets/util/pipeline.py", line 312, in run
    out = self.coro.send(msg)
  File "/usr/lib/python3.6/site-packages/beets/util/pipeline.py", line 194, in coro
    func(*(args + (task,)))
  File "/usr/lib/python3.6/site-packages/beets/importer.py", line 1435, in plugin_stage
    func(session, task)
  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/replaygain.py", line 998, in imported
    self.handle_album(task.album, False)
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 900, in handle_album
    if not self.album_requires_gain(album):
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 859, in album_requires_gain
    for item in album.items()]) or \
  File "/usr/lib/python3.6/site-packages/beetsplug/replaygain.py", line 859, in <listcomp>
    for item in album.items()]) or \
  File "/usr/lib/python3.6/site-packages/beets/dbcore/db.py", line 338, in __getattr__
    raise AttributeError(u'no such field {0!r}'.format(key))
AttributeError: no such field 'r128_item_gain'

AFAIK that's because 1.4.5 was released before the fix was merged. (Jun 20 vs Jul 7)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Freso picture Freso  路  4Comments

clounie picture clounie  路  3Comments

robot3498712 picture robot3498712  路  3Comments

lhupitr picture lhupitr  路  5Comments

nopoz picture nopoz  路  4Comments