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

replaygain: Sets R128 fields to zero when R128 values are not calculated #2757

Closed
breversa opened this issue Dec 10, 2017 · 29 comments
Closed
Labels
bug bugs that are confirmed and actionable

Comments

@breversa
Copy link

Problem

The Replaygain plugins calculate either replaygain_* OR r128 tags, but when using "beet write", both series of tags are written, one being equal to zero.

My music player (Vanilla Music, on Android) applies r128_* gain if the tags are present, before trying the replaygain_* ones.

Is there any way NOT to write the r128 tags with the "beet write" command ? And to delete the existing r128 tags in my now messed-up library (I'm not blaming anyone ; just looking for a solution :) ) ?

Setup

  • OS: Linux
  • Python version: 2.7.12
  • beets version: 1.4.5

My configuration (output of beet config) is:

$ beet config

paths:
    default: $artist/$album%aunique{}/$artist - $title
    singleton: $artist/$album%aunique{}/$artist - $title
    comp: $artist/$album%aunique{}/$artist - $title
threaded: yes
scrub:
    auto: no
chroma:
    auto: yes
library: ~/.config/beets/musiclibrary.db
replaygain:
    backend: bs1770gain
    method: ebu
    auto: yes
    overwrite: yes
    targetlevel: 89
    r128: [Opus]
    chunk_at: 5000

ui:
    color: yes

plugins: replaygain chroma duplicates fetchart web info
directory: ~/Musique

import:
    copy: no
    autotag: no
    resume: ask
    group_albums: yes
    bell: yes
duplicates:
    count: no
    full: no
    format: ''
    keys: []
    move: ''
    tag: ''
    path: no
    copy: ''
    tiebreak: {}
    album: no
    strict: no
    checksum: ''
    merge: no
    delete: no
fetchart:
    auto: yes
    minwidth: 0
    sources:
    - filesystem
    - coverart
    - itunes
    - amazon
    - albumart
    google_engine: 001442825323518660753:hrh5ch1gjzm
    enforce_ratio: no
    cautious: no
    maxwidth: 0
    store_source: no
    google_key: REDACTED
    fanarttv_key: REDACTED
    cover_names:
    - cover
    - front
    - art
    - album
    - folder
web:
    host: 127.0.0.1
    include_paths: no
    port: 8337
    reverse_proxy: no
    cors: ''
@sampsyo sampsyo added the needinfo We need more details or follow-up from the filer before this can be tagged "bug" or "feature." label Dec 12, 2017
@sampsyo
Copy link
Member

sampsyo commented Dec 12, 2017

Hi! Hmm, I'm a little confused so far… as of 1.4.5, we're supposed to be keeping R128 and ReplayGain tags separate. The new r128 configuration option switches from RG to R128 for specific formats (Opus only by default) and only writes R128 tags.

Any chance this dual-tag problem came from older versions of beets? If so, maybe all you need is to use beet modify r128_album_gain=, etc., to clear out those tags and then to run beet replaygain again.

@breversa
Copy link
Author

breversa commented Dec 12, 2017

As I'm fairly new to Beets (I discovered it two weeks ago), I'm pretty sure it's not a matter of previous version.
Also, beet modify r128_album_gain= does NOT remove the tags ; it merely sets them to zero.

Actually, Beets seems to set up r128 tags regardless of the ReplayGain plugin config ; or maybe even without that plugin enabled, and beet write writes them to the file, with a value of 0 (which causes my problem).

@sampsyo
Copy link
Member

sampsyo commented Dec 13, 2017

I see! So is the problem here that the R128 tags are zero (always zero) when they should be missing? Or do they sometimes have nonzero values?

@breversa
Copy link
Author

breversa commented Dec 13, 2017

Yes, that's the problem : there shouldn't be any r128 tags except for files specifically configured in the ReplayGain plugin config.

@breversa
Copy link
Author

breversa commented Dec 13, 2017

Here's a proof, with a new track :

$ beet info album:The Final Station
Oleg Sergeev, Andrey Rumak/The Final Station soundtrack/Oleg Sergeev, Andrey Rumak - Porth Wen.mp3
     album: The Final Station soundtrack
       art: True
    artist: Oleg Sergeev, Andrey Rumak
  bitdepth: 0
   bitrate: 320000
  channels: 2
      comp: False
      date: 2016-01-01
    format: MP3
     genre: Videogame
    genres: Videogame
    length: 78.2692916667
samplerate: 48000
     title: Porth Wen
     track: 1
      year: 2016

I then calculated the gain (for the full album, but only displayed the relevant info for one track, to avoid clutter) :

$ beet replaygain -a album:The Final Station

And here's the result :

$ beet info album:The Final Station         
Oleg Sergeev, Andrey Rumak/The Final Station soundtrack/Oleg Sergeev, Andrey Rumak - Porth Wen.mp3
          album: The Final Station soundtrack
    albumartist: Oleg Sergeev, Andrey Rumak
       arranger: 
            art: True
         artist: Oleg Sergeev, Andrey Rumak
       bitdepth: 0
        bitrate: 320000
            bpm: 0
       channels: 2
           comp: False
           date: 2016-01-01
           disc: 0
      disctotal: 0
         format: MP3
          genre: Videogame
         genres: Videogame
         length: 78.2692916667
         lyrics: 
     mb_trackid: 
  original_year: 0
r128_album_gain: 0
r128_track_gain: 0
  rg_album_gain: -6.18
  rg_album_peak: 1.005274
  rg_track_gain: -2.7
  rg_track_peak: 0.988433
     samplerate: 48000
          title: Porth Wen
          track: 1
     tracktotal: 0
           year: 2016

If I check the file's tags with VLC :
snapshot3

@sampsyo sampsyo changed the title "beet write" should write either replaygain_* OR r128_* tags, not both replaygain: Sets R128 fields to zero when R128 values are not calculated Dec 13, 2017
@sampsyo sampsyo added bug bugs that are confirmed and actionable and removed needinfo We need more details or follow-up from the filer before this can be tagged "bug" or "feature." labels Dec 13, 2017
@sampsyo
Copy link
Member

sampsyo commented Dec 13, 2017

Got it; thanks! That really does clarify the issue. It sounds like the plugin is somehow writing zeroes for the R128 fields even when it's only calculating the RG values.

I don't immediately see the root cause of the problem. Doing a little more digging into where, in the plugin's workflow, the tags are being set to zero would help nail it down.

@breversa
Copy link
Author

Any way I can help ?

@sampsyo
Copy link
Member

sampsyo commented Dec 13, 2017

Good question! If you know a teensy bit of Python, you could try throwing in bunch of print(item.r128_track_gain) statements here and there to see when the value goes from None (i.e., missing) to 0.

@breversa
Copy link
Author

Sadly, I don't know Python. But bash, if that helps…

@sampsyo
Copy link
Member

sampsyo commented Dec 13, 2017

Maybe this is the perfect time to learn! 😃 🐍

@autrimpo
Copy link
Contributor

I'm the author of the R128 implementation so I've done some quick debugging today.

The replaygain plugin only sets the tags values by calling ReplayGainPlugin.store_track_r128_gain() and ReplayGainPlugin.store_album_r128_gain() methods respectively. I've tried importing a flac album with a similar config to the one posted by @breversa (at least as far as the replaygain plugin is concerned), and as described, R128_ tags appear with 0 values however the methods do not get called. This leads me to believe the bug is not related to the plugin but maybe to the database part?

An easy way to test it is to change the debug messages for the r128 methods to be different from the "standard" ones at lines 880 and 894 in replaygain.py (since right now they are identical) and run beets with -v -v. It only shows the original messages for me. I've even tried commenting out the blocks that call the r128 methods but the tags still appeared. I'm thinking that this might actually be worth to submit as a PR, so that we get some more information in the debugging messages.

A bit of a wild guess but I have a feeling it also might be related to this. (That at least explains why beet modify r128_album_gain= does not actually delete the tags, unless something has changed with regard to that). @sampsyo?

I'll look at this a bit more if I have the time but if anybody else decides to pick this up hopefully this information will be of some use.

@sampsyo
Copy link
Member

sampsyo commented Dec 20, 2017

Hmm, yes, it could indeed be that the Item abstraction never actually deletes these flags on the underlying MediaFile... but somehow I thought we had addressed that, so that these fields wouldn’t keep reappearing when there’s no RG analysis done. I’ll look into it too.

@breversa
Copy link
Author

Glad know the experts are on the case. ;-)
Is there any progress ? :-)

@autrimpo
Copy link
Contributor

autrimpo commented Feb 18, 2018

I've managed to track down the issue: the tags don't have a value of None but 0, that's why they don't get deleted.

I'll submit a fix as a PR.

@autrimpo
Copy link
Contributor

@breversa can you maybe pull the branch with the fix and see if it works for you as well? It should but extra testing never hurts.

@breversa
Copy link
Author

Okay… just how does it work ?

@autrimpo
Copy link
Contributor

https://github.com/autrimpo/beets/tree/issue2757 download the code from here and run ./beet just as you would normally run beet.

autrimpo added a commit to autrimpo/beets that referenced this issue Feb 19, 2018
@breversa
Copy link
Author

So, here goes…
Before replaygain calculation (only showing the first track) :

$ ./beet info album:The Final Station
/home/breversa/Musique/Oleg Sergeev, Andrey Rumak/The Final Station soundtrack/Oleg Sergeev, Andrey Rumak - Porth Wen.mp3
        album: The Final Station soundtrack
  albumartist: Oleg Sergeev, Andrey Rumak
     arranger: 
          art: True
       artist: Oleg Sergeev, Andrey Rumak
     bitdepth: 0
      bitrate: 320000
          bpm: 0
     channels: 2
         comp: False
         date: 2016-01-01
         disc: 0
    disctotal: 0
       format: MP3
        genre: Videogame
       genres: Videogame
       length: 78.2692916667
   mb_trackid: 
rg_album_gain: -6.18
rg_album_peak: 1.005274
rg_track_gain: -2.7
rg_track_peak: 0.988433
   samplerate: 48000
        title: Porth Wen
        track: 1
   tracktotal: 0
         year: 2016

Replaygain calculation :

$ ./beet replaygain -a album:The Final Station
replaygain: analyzing Oleg Sergeev, Andrey Rumak - The Final Station soundtrack

Checking the results (only showing the first track) :

$ ./beet info album:The Final Station
/home/breversa/Musique/Oleg Sergeev, Andrey Rumak/The Final Station soundtrack/Oleg Sergeev, Andrey Rumak - Porth Wen.mp3
          album: The Final Station soundtrack
    albumartist: Oleg Sergeev, Andrey Rumak
       arranger: 
            art: True
         artist: Oleg Sergeev, Andrey Rumak
       bitdepth: 0
        bitrate: 320000
            bpm: 0
       channels: 2
           comp: False
           date: 2016-01-01
           disc: 0
      disctotal: 0
         format: MP3
          genre: Videogame
         genres: Videogame
         length: 78.2692916667
         lyrics: 
     mb_trackid: 
  original_year: 0
r128_album_gain: 0
r128_track_gain: 0
  rg_album_gain: -6.75
  rg_album_peak: 1.005274
  rg_track_gain: -8.91
  rg_track_peak: 0.998319
     samplerate: 48000
          title: Porth Wen
          track: 1
     tracktotal: 0
           year: 2016

Those r128_*_gain tags are still there. :-(
(Also, just for the record : my locale is fr_FR@UTF-8, where floating-point numbers use commas instead of points)

@autrimpo
Copy link
Contributor

Try ./beets modify [query] 'r128_track_gain=None' 'r128_album_gain=None' instead.

@breversa
Copy link
Author

First I thought I was out of luck :

$ ./beet modify "The Final Station" 'r128_track_gain=None' 'r128_album_gain=None'
Modifying 10 items.
Oleg Sergeev, Andrey Rumak - The Final Station soundtrack - Porth Wen
  r128_album_gain: 000000 -> 000000
  r128_track_gain: 000000 -> 000000
…

but then :

$ ./beet info "The Final Station"
/home/breversa/Musique/Oleg Sergeev, Andrey Rumak/The Final Station soundtrack/Oleg Sergeev, Andrey Rumak - Porth Wen.mp3
        album: The Final Station soundtrack
  albumartist: Oleg Sergeev, Andrey Rumak
     arranger: 
          art: True
       artist: Oleg Sergeev, Andrey Rumak
     bitdepth: 0
      bitrate: 320000
          bpm: 0
     channels: 2
         comp: False
         date: 2016-01-01
         disc: 0
    disctotal: 0
       format: MP3
        genre: Videogame
       genres: Videogame
       length: 78.2692916667
       lyrics: 
   mb_trackid: 
original_year: 0
rg_album_gain: -6.18
rg_album_peak: 1.005274
rg_track_gain: -2.7
rg_track_peak: 0.988433
   samplerate: 48000
        title: Porth Wen
        track: 1
   tracktotal: 0
         year: 2016

No more R128 tags ! :D

@hdante
Copy link

hdante commented May 20, 2018

Hello, is this issue fixed ? I'm using beet version 1.4.6 and even with the replaygain plugin disabled the files are being tagged with R128_*_GAIN = 0.

@sampsyo
Copy link
Member

sampsyo commented May 20, 2018

@hdante, can you please try the latest source? (The FAQ has instructions.)

@breversa
Copy link
Author

From what I can read here : https://github.com/autrimpo/beets/blob/96a421df83d1dcbc85f3ab6870f508dc3f62f8ff/docs/changelog.rst, it has been fixed as of v1.4.7 (not released yet).

@hdante
Copy link

hdante commented May 31, 2018

Hello, I've just tested with beet 1.4.7 and the issue was not fixed. Here follows the steps to reproduce, starting with an empty library.

[hdante@dragonmount beets]$ cat config.yaml 
directory: ~/.local/share/beets/music
library: ~/.local/share/beets/library.db
[hdante@dragonmount beets]$ beet import ~/Música/AC_DC-If_You_Want_Blood_Youve_Got_It/

/home/hdante/Música/AC_DC-If_You_Want_Blood_Youve_Got_It (10 items)
Tagging:
    AC/DC - If You Want Blood You've Got It
URL:
    https://musicbrainz.org/release/d3240b40-8d3c-4c1e-aea8-251ac479e573
(Similarity: 100.0%) (CD, 2007, JP, Sony Music Japan International Inc.)
 * Hell Ain't A Bad Place To Be -> Hell Ain't a Bad Place to Be
 * Rock'N'Roll Damnation        -> Rock 'n' Roll Damnation
[hdante@dragonmount beets]$ mediainfo ~/Música/AC_DC-If_You_Want_Blood_Youve_Got_It/01.Riff_Raff.mp3 | grep R128
[hdante@dragonmount beets]$ mediainfo ~/.local/share/beets/music/AC_DC/If\ You\ Want\ Blood\ You\'ve\ Got\ It/01\ Riff\ Raff.mp3 | grep R128
R128_ALBUM_GAIN                          : 0
R128_TRACK_GAIN                          : 0
[hdante@dragonmount beets]$ beet --version
beets version 1.4.7
Python version 3.6.5
no plugins loaded

@autrimpo
Copy link
Contributor

It was fixed, it just didn't get merged (and thus released with 1.4.7), see #2813.
@sampsyo would it be possible to make a small bugfix release to include this?

@sampsyo
Copy link
Member

sampsyo commented May 31, 2018

Argh; how did I forget to merge this? My fault; sorry. Yes, we should release this ASAP.

@breversa
Copy link
Author

breversa commented Jun 7, 2018

How about a release, then ? :-)

@WatermelonDriveway
Copy link

WatermelonDriveway commented Mar 5, 2019

Running 1.4.7, this happens to me randomly for some albums.

~ bu
Jordon Alexander - More Than I Ever Thought I Could b/w The Heart Is A Lonely Hunter - More Than I Ever Thought I Could
r128_album_gain: 000000 -> 000000
Jordon Alexander - More Than I Ever Thought I Could b/w The Heart Is A Lonely Hunter - The Heart Is A Lonely Hunter
r128_album_gain: 000000 -> 000000

beet modify [query] 'r128_track_gain=None' 'r128_album_gain=None'

will fix the album in question, but still a pretty big annoyance.

@jackwilsdon
Copy link
Member

I think that's #3049 that you're seeing there @WatermelonDriveway (which I see you've already commented on), as this issue seems to be going from None -> 000000 instead of 000000 -> 000000.

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

6 participants