# Multiple tags with only 1 letter

**URL:** <https://discourse.beets.io/t/multiple-tags-with-only-1-letter/2360>\
**Category:** Development\
**Created:** [June 1, 2023, 6:08pm UTC](https://discourse.beets.io/t/multiple-tags-with-only-1-letter/2360 "2023-06-01T18:08:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![may](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@may](https://discourse.beets.io/u/may)\
**Post date:** [June 1, 2023, 6:08pm UTC](https://discourse.beets.io/t/multiple-tags-with-only-1-letter/2360/1 "2023-06-01T18:08:01Z")

</div>

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\\'\\]`

 ![Scherm­afbeelding 2023-06-01 om 19.49.15](https://canada1.discourse-cdn.com/flex029/uploads/beets/original/1X/a45a10bb4c887b2d62f799b34cc53c3906b5bc52.jpeg)

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.

```auto
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`

```auto
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?

---

<div class="post-metadata">

**Author:** ![out-of-range](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/out-of-range/32/428_2.png) [@out-of-range](https://discourse.beets.io/u/out-of-range)\
**Post date:** [June 3, 2023, 6:55pm UTC](https://discourse.beets.io/t/multiple-tags-with-only-1-letter/2360/2 "2023-06-03T18:55:18Z")

</div>

This looks like the issue [#4528](https://github.com/beetbox/beets/issues/4528) (which affects beets v1.6.0), fixed in [#4582](https://github.com/beetbox/beets/pull/4582). Although I think that was about `update` rather than `import`.

Does it still happen if you use the [latest source version of beets](https://beets.readthedocs.io/en/latest/faq.html#run-the-latest-source-version-of-beets)?

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