snejus / beetcamp

Bandcamp autotagger source for beets (https://beets.io)
GNU General Public License v2.0
68 stars 12 forks source link

`write: no` is being ignored (source files are being mutated) #16

Closed brianredbeard closed 3 years ago

brianredbeard commented 3 years ago

While troubleshooting the incorrect population of musicbrainz metadata, I discovered that beets-bandcamp (neé "bandcamp") is ignoring global configurations and mutating source material.

In my workflow I start from "vanilla" files that then go through a number of processing steps before ending up in a curated location.

Related to this, I have a beets configuration solely for handling content from Bandcamp, thus allowing me to rule out conflicts with plugins, misconfigurations, etc.

This is the rendered config.yaml:

$ beet config
library: /media/guacamole/music/bandcamp/.beets/library.db
directory: /media/guacamole/music/bandcamp

import:
    write: no
    copy: yes
    log: .beetslog.txt
    bell: yes

clutter:
- Thumbs.DB
- .DS_Store
- '@eaDir'
- '*@SynoResource'
ignore:
- .*
- '*~'
- System Volume Information
- lost+found
ignore_hidden: yes

replace:
    '[\\/]': _
    ^\.: _
    '[\x00-\x1f]': _
    '[<>:"\?\*\|]': _
    \.$: _
    \s+$: ''
    ^\s+: ''
    ^-: _
path_sep_replace: _
asciify_paths: no
art_filename: cover
max_filename_length: 255

aunique:
    keys: albumartist album
    disambiguators: albumtype year label catalognum albumdisambig releasegroupdisambig
    bracket: '[]'

overwrite_null:
    album: []
    track: []

plugins: [bandcamp, fetchart]
threaded: yes
timeout: 5.0
per_disc_numbering: no
id3v23: no
va_name: Various Artists

ui:
    color: yes
    colors:
        text_success: green
        text_warning: yellow
        text_error: red
        text_highlight: red
        text_highlight_minor: lightgray
        action_default: turquoise
        action: blue

format_item: $artist - $album - $title
format_album: $albumartist - $album
time_format: '%Y-%m-%d %H:%M:%S'
format_raw_length: no

sort_album: albumartist+ album+
sort_item: artist+ album+ disc+ track+
sort_case_insensitive: yes

paths:
    default: $albumartist - $album ($year) [$format]/$track - $title
    singleton: Non-Album/$artist/$title
    comp: Compilations/$album%aunique{}/$track $title

statefile: .state.pickle
chroma:
    auto: no
fetchart:
    auto: no
    cautious: yes
    minwidth: 0
    maxwidth: 0
    quality: 0
    max_filesize: 0
    enforce_ratio: no
    cover_names:
    - cover
    - front
    - art
    - album
    - folder
    sources:
    - filesystem
    - coverart
    - itunes
    - amazon
    - albumart
    google_key: REDACTED
    google_engine: 001442825323518660753:hrh5ch1gjzm
    fanarttv_key: REDACTED
    lastfm_key: REDACTED
    store_source: no
    high_resolution: no
bandcamp:
    source_weight: 0
    preferred_media: Digital
    include_digital_only_tracks: yes
    search_max: 5
    art: yes
    exclude_extra_fields: [lyrics, comments]

To demonstrate, I'm going to use a recent release: (Tales From The Ultra Tribe by Steve Roach / Byron Metcalf)

The original metadata in the FLAC files appears as follows:

$ metaflac --list --block-number=2  ~/bandcamp/Steve\ Roach\ -\ Byron\ Metcalf\ -\ Tales\ From\ The\ Ultra\ Tribe/Steve\ Roach\ -\ Byron\ Metcalf\ -\ Tales\ From\ The\ Ultra\ Tribe\ -\ 01\ Setting\ Forth.flac  
METADATA block #2
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 259
  vendor string: reference libFLAC 1.3.2 20170101
  comments: 7
    comment[0]: TITLE=Setting Forth
    comment[1]: ARTIST=Steve Roach / Byron Metcalf
    comment[2]: DATE=2021
    comment[3]: COMMENT=Visit https://steveroach.bandcamp.com
    comment[4]: ALBUM=Tales From The Ultra Tribe
    comment[5]: TRACKNUMBER=1
    comment[6]: ALBUMARTIST=Steve Roach / Byron Metcalf

After running beet import with the configuration above but the bandcamp plugin disabled, the metadata on the new file remains the same:

$ metaflac --list --block-number=2  /media/guacamole/music/bandcamp/Steve\ Roach\ \&\ Byron\ Metcalf\ -\ Tales\ From\ the\ Ultra\ Tribe\ \(2021\)\ \[FLAC\]/01\ -\ Setting\ Forth.flac 
METADATA block #2
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 259
  vendor string: reference libFLAC 1.3.2 20170101
  comments: 7
    comment[0]: TITLE=Setting Forth
    comment[1]: ARTIST=Steve Roach / Byron Metcalf
    comment[2]: DATE=2021
    comment[3]: COMMENT=Visit https://steveroach.bandcamp.com
    comment[4]: ALBUM=Tales From The Ultra Tribe
    comment[5]: TRACKNUMBER=1
    comment[6]: ALBUMARTIST=Steve Roach / Byron Metcalf

However, enabling the bandcamp plugin and running beet import the metadata is modified on the original file:

$ beet config | grep pluginplugins: [bandcamp, fetchart]
$ beet  import bandcamp/Steve\ Roach\ -\ Byron\ Metcalf\ -\ Tales\ From\ The\ Ultra\ Tribe
/home/bharrington/bandcamp/Steve Roach - Byron Metcalf - Tales From The Ultra Tribe (8 items)
Tagging:
    Steve Roach / Byron Metcalf - Tales From The Ultra Tribe
URL:
    https://steveroach.bandcamp.com/album/tales-from-the-ultra-tribe
(Similarity: 100.0%) (bandcamp, Digital Media, 2021, US, Steve Roach)
$ metaflac --list --block-number=2  ~/bandcamp/Steve\ Roach\ -\ Byron\ Metcalf\ -\ Tales\ From\ The\ Ultra\ Tribe/Steve\ Roach\ -\ Byron\ Metcalf\ -\ Tales\ From\ The\ Ultra\ Tribe\ -\ 01\ Setting\ Forth.flac  
METADATA block #2
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 1445
  vendor string: reference libFLAC 1.3.2 20170101
  comments: 58
    comment[0]: ACOUSTID_FINGERPRINT=
    comment[1]: ACOUSTID_ID=
    comment[2]: ALBUM=Tales From The Ultra Tribe
    comment[3]: ALBUM ARTIST=Steve Roach / Byron Metcalf
    comment[4]: ALBUMARTIST=Steve Roach / Byron Metcalf
    comment[5]: ALBUMARTIST_CREDIT=
    comment[6]: ALBUMARTISTSORT=
    comment[7]: MUSICBRAINZ_ALBUMCOMMENT=
    comment[8]: RELEASESTATUS=Official
    comment[9]: MUSICBRAINZ_ALBUMSTATUS=Official
    comment[10]: RELEASETYPE=album
    comment[11]: MUSICBRAINZ_ALBUMTYPE=album
    comment[12]: ARRANGER=
    comment[13]: ARTIST=Steve Roach / Byron Metcalf
    comment[14]: ARTIST_CREDIT=
    comment[15]: ARTISTSORT=
    comment[16]: ASIN=
    comment[17]: BPM=0
    comment[18]: CATALOGNUMBER=
    comment[19]: DESCRIPTION=Visit https://steveroach.bandcamp.com
    comment[20]: COMMENT=Visit https://steveroach.bandcamp.com
    comment[21]: COMPILATION=0
    comment[22]: COMPOSER=
    comment[23]: COMPOSERSORT=
    comment[24]: RELEASECOUNTRY=US
    comment[25]: DATE=2021-06-23
    comment[26]: YEAR=2021
    comment[27]: DISC=1
    comment[28]: DISCNUMBER=1
    comment[29]: DISCSUBTITLE=
    comment[30]: DISCTOTAL=1
    comment[31]: DISCC=1
    comment[32]: TOTALDISCS=1
    comment[33]: ENCODEDBY=
    comment[34]: ENCODER=
    comment[35]: GENRE=
    comment[36]: GROUPING=
    comment[37]: LABEL=Steve Roach
    comment[38]: PUBLISHER=Steve Roach
    comment[39]: LANGUAGE=
    comment[40]: LYRICIST=
    comment[41]: LYRICS=
    comment[42]: MUSICBRAINZ_ALBUMARTISTID=https://steveroach.bandcamp.com
    comment[43]: MUSICBRAINZ_ALBUMID=https://steveroach.bandcamp.com/album/tales-from-the-ultra-tribe
    comment[44]: MUSICBRAINZ_ARTISTID=https://steveroach.bandcamp.com
    comment[45]: MUSICBRAINZ_RELEASEGROUPID=
    comment[46]: MUSICBRAINZ_RELEASETRACKID=
    comment[47]: MUSICBRAINZ_TRACKID=https://steveroach.bandcamp.com/track/setting-forth
    comment[48]: MUSICBRAINZ_WORKID=
    comment[49]: MEDIA=Digital Media
    comment[50]: ORIGINALDATE=0000
    comment[51]: SCRIPT=
    comment[52]: TITLE=Setting Forth
    comment[53]: TRACK=1
    comment[54]: TRACKNUMBER=1
    comment[55]: TRACKTOTAL=8
    comment[56]: TRACKC=8
    comment[57]: TOTALTRACKS=8

as well as populating it on the new file:

$ metaflac --list --block-number=2  /media/guacamole/music/bandcamp/Steve\ Roach\ _\ Byron\ Metcalf\ -\ Tales\ From\ The\ Ultra\ Tribe\ \(2021\)\ \[FLAC\]/01\ -\ Setting\ Forth.flac 
METADATA block #2
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 1445
  vendor string: reference libFLAC 1.3.2 20170101
  comments: 58
    comment[0]: ACOUSTID_FINGERPRINT=
    comment[1]: ACOUSTID_ID=
    comment[2]: ALBUM=Tales From The Ultra Tribe
    comment[3]: ALBUM ARTIST=Steve Roach / Byron Metcalf
    comment[4]: ALBUMARTIST=Steve Roach / Byron Metcalf
    comment[5]: ALBUMARTIST_CREDIT=
    comment[6]: ALBUMARTISTSORT=
    comment[7]: MUSICBRAINZ_ALBUMCOMMENT=
    comment[8]: RELEASESTATUS=Official
    comment[9]: MUSICBRAINZ_ALBUMSTATUS=Official
    comment[10]: RELEASETYPE=album
    comment[11]: MUSICBRAINZ_ALBUMTYPE=album
    comment[12]: ARRANGER=
    comment[13]: ARTIST=Steve Roach / Byron Metcalf
    comment[14]: ARTIST_CREDIT=
    comment[15]: ARTISTSORT=
    comment[16]: ASIN=
    comment[17]: BPM=0
    comment[18]: CATALOGNUMBER=
    comment[19]: DESCRIPTION=Visit https://steveroach.bandcamp.com
    comment[20]: COMMENT=Visit https://steveroach.bandcamp.com
    comment[21]: COMPILATION=0
    comment[22]: COMPOSER=
    comment[23]: COMPOSERSORT=
    comment[24]: RELEASECOUNTRY=US
    comment[25]: DATE=2021-06-23
    comment[26]: YEAR=2021
    comment[27]: DISC=1
    comment[28]: DISCNUMBER=1
    comment[29]: DISCSUBTITLE=
    comment[30]: DISCTOTAL=1
    comment[31]: DISCC=1
    comment[32]: TOTALDISCS=1
    comment[33]: ENCODEDBY=
    comment[34]: ENCODER=
    comment[35]: GENRE=
    comment[36]: GROUPING=
    comment[37]: LABEL=Steve Roach
    comment[38]: PUBLISHER=Steve Roach
    comment[39]: LANGUAGE=
    comment[40]: LYRICIST=
    comment[41]: LYRICS=
    comment[42]: MUSICBRAINZ_ALBUMARTISTID=https://steveroach.bandcamp.com
    comment[43]: MUSICBRAINZ_ALBUMID=https://steveroach.bandcamp.com/album/tales-from-the-ultra-tribe
    comment[44]: MUSICBRAINZ_ARTISTID=https://steveroach.bandcamp.com
    comment[45]: MUSICBRAINZ_RELEASEGROUPID=
    comment[46]: MUSICBRAINZ_RELEASETRACKID=
    comment[47]: MUSICBRAINZ_TRACKID=https://steveroach.bandcamp.com/track/setting-forth
    comment[48]: MUSICBRAINZ_WORKID=
    comment[49]: MEDIA=Digital Media
    comment[50]: ORIGINALDATE=0000
    comment[51]: SCRIPT=
    comment[52]: TITLE=Setting Forth
    comment[53]: TRACK=1
    comment[54]: TRACKNUMBER=1
    comment[55]: TRACKTOTAL=8
    comment[56]: TRACKC=8
    comment[57]: TOTALTRACKS=8
snejus commented 3 years ago

Thanks for an amazing issue report!

This is interesting - also something that I wouldn't have caught myself, since I only use beets with write: on. Just had a brief look at the code and I think I see the culprit

self.add_additional_data(item, write=True)

this line hardcodes write to True which is obviously incorrect. That function also currently writes regardless of whether the additional fields are excluded.

I will try to address both of these over the next couple of days.

snejus commented 3 years ago

This should now be fixed with 0.9.2.