How to get maximum samplerate for path - Different samplerate on single album

Hi there!

I have some loseless albums where some tracks have higher samplerate than others.
I want to display the samplerate in the folder name if the file is flac. But sometimes it creates a mess and I have 2 folders for 1 album.

I don’t know enough about python/inline plugin, how can I get the maximum or the most popular samplerate of a folder and use that instead? In the best world, if most tracks are 48khz then 48 would be the used value.

Is it possible? How can I do that?
Thanks

Hmm… I think the real problem to be solved here might be the fact that you’re ending up with two folders for a given album? It sounds like beets thinks there are two albums. If you could merge them together (the best way would be to import the whole album together again), then you could calculate sample rates for albums.

Inevitably, you will need to write some Python code to get a maximum or most popular value, though.

I’m not quite sure what you mean by reimporting the whole album together.

My config.yaml looks like this. It creates 2 folders because some tracks have higher samplerate.

image

item_fields:
    my_samplerate: str(round(samplerate / 1000))
    is_flac: 1 if format == "FLAC" else 0
    is_album: 1 if albumtype.upper() == "ALBUM" else 0
    multidisc: 1 if disctotal > 1 else 0
    compilation_display: '''Soundtracks'' if albumtype.upper() == ''SOUNDTRACK'' else ''Compilations'''
    #first_artist: albumartist.split(', ',1)[0:1][0]

album_fields:  
    fileformat: |
        formatList = []
        for item in items:
            formatList.append(item.format.upper())
        return formatList
    av_bitrate: |
        total = 0
        for item in items:
            total += item.bitrate
        return str(round(total / len(items) / 1000))

paths:
    default: '%the{$albumartist}/%if{$original_year,$original_year,0000} - $album%aunique{albumartist album year, albumtype label catalognum albumdisambig} [%ifdef{how,$how }%upper{$format}%if{$is_flac, $my_samplerate-$bitdepth, $av_bitrate}]/%if{$multidisc,$disc-}$track - $title'
    albumtype:single: '%the{$albumartist}/Singles/%if{$original_year,$original_year,0000} - $album%aunique{albumartist album year, albumtype label catalognum albumdisambig} [%ifdef{how,$how }%upper{$format}%if{$is_flac, $my_samplerate-$bitdepth, $av_bitrate}]/%if{$multidisc,$disc-}$track - $title'
    albumtype:ep: '%the{$albumartist}/EPs/%if{$original_year,$original_year,0000} - $album%aunique{albumartist album year, albumtype label catalognum albumdisambig} [%ifdef{how,$how }%upper{$format}%if{$is_flac, $my_samplerate-$bitdepth, $av_bitrate}]/%if{$multidisc,$disc-}$track - $title'
    albumtype:soundtrack: Soundtracks/%if{$year,$year - ,%if{$original_year,$original_year - }}$album%aunique{} [%ifdef{how,$how }%upper{$format}%if{$is_flac, $my_samplerate-$bitdepth, $av_bitrate}]/%if{$multidisc,$disc-}$track - $title
    comp: $compilation_display/%if{$year,$year - ,%if{$original_year,$original_year - }}$album%aunique{} [%ifdef{how,$how }%upper{$format}%if{$is_flac, $my_samplerate-$bitdepth, $av_bitrate}]/%if{$multidisc,$disc-}$track - $title

What would be the quickest fix for this? Can I tell beet to move files from one album in the other?

Ah, sorry, I misunderstood! I think you just want to make another album_fields entry that’s like av_bitrate but, like, for the sample rate. Then that will give you an “album-level” sample rate you can use to keep albums together. :+1:

1 Like

Oh, smart! It’s gonna be confusing at first but the average should give a clear indication of what’s inside.

Thanks!