Multiple tags with only 1 letter

I did an import of my collection and I noticed the RELEASETYPE tag showing multiple times.
When checking the tags using Mp3Tag. The filetypes are FLAC or MP3.

ep:
RELEASETYPE: e
RELEASETYPE: p

single:
RELEASETYPE: s
RELEASETYPE: i
RELEASETYPE: n
RELEASETYPE: l
RELEASETYPE: g
RELEASETYPE: e

album:
RELEASETYPE: a
RELEASETYPE: l
RELEASETYPE: b
RELEASETYPE: u
RELEASETYPE: m

Shorthands:
e\\p
a\\l\\b\\u\\m
s\\i\\n\\g\\l\\e

I even saw things like
[\\'\\s\\i\\n\\g\\l\\e\\'\\]

So I thought I try to write a beets plugin that sets the RELEASETYPE based on some conditions.

Singles are less than 30 minutes with 3 or fewer tracks. EPs are up to 30 minutes in length with no more than 6 songs. And albums contain 6 or more songs with a total length of over 30 minutes.

from beets.plugins import BeetsPlugin
from beets.ui import Subcommand
from beets.library import Item

command = Subcommand('releasetype', help='do something super')


class ReleaseTypePlugin(BeetsPlugin):
    def __init__(self):
        super(ReleaseTypePlugin, self).__init__()

        self.config.add({
            'album_length_threshold': 1800,  # 30 minutes in seconds
            'ep_length_threshold': 1800,     # 30 minutes in seconds
            'single_track_limit': 3,
            'ep_track_limit': 6
        })

    def commands(self):
        command = Subcommand(
            'releasetype', help='Assign release type to items')
        command.func = self.add_release_type
        command.parser.add_option(
            '-a', '--album', dest='album', help='Specify album name')
        return [command]

    def add_release_type(self, lib, opts, args):
        album_length_treshold = self.config['album_length_threshold'].get(int)
        ep_length_threshold = self.config['ep_length_threshold'].get(int)
        single_track_limit = self.config['single_track_limit'].get(int)
        ep_track_limit = self.config['ep_track_limit'].get(int)

        if opts.album:
            album_name = opts.album
            albums = lib.albums(album_name)
            if albums:
                album = albums[0]
                for item in album.items():
                    release_type = self.determine_release_type(
                        album, album_length_treshold, ep_length_threshold, single_track_limit, ep_track_limit)
                    self.set_release_type(item, release_type)
            else:
                print(f"No album found with name: {album_name}")
        else:
            for album in lib.albums():
                for item in album.items():
                    release_type = self.determine_release_type(
                        album, album_length_treshold, ep_length_threshold, single_track_limit, ep_track_limit)
                    self.set_release_type(item, release_type)

    def determine_release_type(self, album, album_length_treshold, ep_length_threshold, single_track_limit, ep_track_limit):
        # album_obj = album.get()
        total_tracks = len(album.items())
        total_length = sum(item.length for item in album.items())

        if total_tracks <= single_track_limit:
            release_type = 'single'
        elif total_tracks <= ep_track_limit and total_length <= ep_length_threshold:
            release_type = 'ep'
        elif total_tracks >= ep_track_limit and total_length > album_length_treshold:
            release_type = 'album'
        else:
            release_type = None

        return release_type

    def set_release_type(self, item: Item, release_type: str):
        if release_type:
            item['RELEASETYPE'] = release_type
            item.write()

            # Do I need to update the library?


release_type_plugin = ReleaseTypePlugin()

I then ran my command releasetype -a "Album name" on 1 album to test. The type is single and I got the result as shown above 6 RELEASETYPE tags containing only 1 letter.

This is my config.yaml

directory: /media/sdb/music
library: ~/data/library.db
original_date: true
ignore_hidden: yes
art_filename: cover
import:
  move: yes
  incremental_skip_later: yes
  log: ~/data/beetslog.txt
match:
  required: label
ui:
  color: yes
pluginpath: /home/bas/.config/beets/beetsplug
plugins: scrub discogs fetchart releasetype
scrub:
  auto: yes
discogs:
  index_tracks: no
fetchart:
  cautious: true
  cover_names: cover
  sources: filesystem *

Does anyone now why it doing this on import and with my plugin?

This looks like the issue #4528 (which affects beets v1.6.0), fixed in #4582. Although I think that was about update rather than import.

Does it still happen if you use the latest source version of beets?

(A new release including this fix is “in the works”)

1 Like