beets icon indicating copy to clipboard operation
beets copied to clipboard

merging albums with --set fields overwrites whole album

Open niacdoial opened this issue 1 year ago • 3 comments

Problem

when importing a track with:

  • for instance --set=title=whatever
  • then making so we hit the "this album is already in the library" dialog and choosing merge

the --set=title=whatever flag ends up affecting all existing tracks in the album as well.

fairly long, self-contained MWE:

#!/usr/bin/env bash
set -eux
basedir=$(mktemp -d)

# create a standalone config
cat > $basedir/conf.yaml <<EOF
plugins: edit
library: $basedir/library.beets-db
directory: $basedir/
import:
  duplicate_keys:
    album: "albumartist album"
edit:
  itemfields: "track title artist album albumartist"
EOF

# minimal wav file, exact contents unimportant
python3 -c 'import sys; sys.stdout.buffer.write(b"RIFF%\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00)#\x00\x00)#\x00\x00\x01\x00\x08\x00data\x01\x00\x00\x00\x00")' > $basedir/src.wav

# set the "file editor" to a script that sets the "album" and "albumartist" fields
export EDITOR="sed -E -i 's/album:.*\$/album: album/;s/albumartist:.*\$/albumartist: artist/'"

# import 'full album'
# eDit, Accept
beet -c $basedir/conf.yaml imp --set=title=title1 $basedir/src.wav  <<EOF
d
a
EOF

# import the new file
# eDit, Accept, Merge albums, Use album as-is
beet -c $basedir/conf.yaml imp --set=title=title2 $basedir/src.wav <<EOF
d
a
m
u
EOF

beet -c $basedir/conf.yaml ls

#this yelds two tracks with "title2" as their title

Setup

  • OS: Nixos 23.11
  • Python version: 3.11.6
  • beets version: 1.6.0
  • Turning off plugins made problem go away (yes/no): untested, the MWE uses only the edit plugin

niacdoial avatar Jan 11 '24 22:01 niacdoial

Isn't that the expected behavior? When you merge, the new tracks and the old tracks are combined into one album and the set title will affect all the tracks in the new album object.

arsaboo avatar Jan 11 '24 23:01 arsaboo

If that's the intended behavior, it's really surprising. I thought it would make more sense for "beet imp --set=field=value" to only affect the tracks that are actually imported to the library.

niacdoial avatar Jan 11 '24 23:01 niacdoial

Yes, that would work if you were not merging albums. When you merge, the merged album is used to the set operation.

arsaboo avatar Jan 12 '24 14:01 arsaboo