Different path formatting for FLAC and MP3|AAC with %if and inline plugin


#1

This question was buried in another thread so I wanted to post is as a single request hoping for a suggestion.

I want part of my Path to be different for MP3 and FLAC albums.
MP3 albums should have ($format $albumbitrate) in the path and
FLAC albums ($format $bitdepth-$samplerate)

The album format is determined by the following code via the inline plugin

# Inline plugin template
album_fields:  
  format: |
       formatList = []
       for item in items:
           formatList.append(item.format)
       return formatList

I’ve tried the following in my path (and many many other formattings) but didn’t get it to work.

%if{$format:"FLAC",($format $bitdepth-$samplerate),($format $bitrate)}

I probably miss something in what I can put in the various %if statement fields.
As you can see my reasoning was that if my conditional is something like “%if(format is FLAC then print information for FLAC otherwise print information for MP3 and AAC”. But to no avail.

Thanks for any suggestions,
Jan

Ps: @adrian by the way… I’ve succeeded in creating different paths via the format:FLAC before the path like you suggested, but ran in to trouble when trying to achieve the same differentiation for FLAC and MP3 compilations. Didn’t find a way to combine format:FLAC with comp:
It would also have given me many paths to manage. Putting an %if in one path to server FLAC and MP3 would be less administration.


#2

Hello! The %if{} function does not support any manner of complicated expressions like $format:"FLAC"; it really can only tell the difference between empty and nonempty strings (or zero/nonzero numbers).

Using the conditional path formats is the way, as you alluded to:

I’ve succeeded in creating different paths via the format:FLAC before the path like you suggested, but ran in to trouble when trying to achieve the same differentiation for FLAC and MP3 compilations. Didn’t find a way to combine format:FLAC with comp:
It would also have given me many paths to manage. Putting an %if in one path to server FLAC and MP3 would be less administration.

You can combine the compilation matching with the format matching using something like comp:true format:flac as the condition for the path. You’re right, of course, that this will yield lots of different path formats you’ll need to craft separately.

So one other alternative would be to define an inline field called, say, is_flac, that produces 1 or 0 depending on the format. That field would then work with %if{}. This is the same sprit as the %if{$multidisc,...} setup from the FAQ.


#3

Hi, ah yes, of course you can combine information, you can do that in the terminal too, didn’t think of that.
And thanks for clarifying how it would work with the inline plugin. I think that I get the point now.


#4

Wanted to report back after all the help I got from @adrian and @macleodmike to share the results for future forum visitors if they are looking for a similar solution.

My quest was to get an album folder name that contained disambiguation data and specific data for FLAC and MP3/AAC. Beets needed to parse different format related fields for each of them.
You might ask why you would want this info in your folder name (it could be consided as clutter) but I find it very useful to be visually able to determine which albums could use an upgrade from e.g. mp3 --> FLAC or from FLAC 16-44 to 24-96.

For FLAC I wanted to parse
(FLAC bitdepth-samplerate(without kHz))
and for MP3
(MP3 average bitrate(without kbps))

This would result in album names like:

Graceland (1986) (25th anniversary edition 2012) (FLAC 16-44)

and

Stranger to Stranger (2016) (deluxe edition 2016) (MP3 320)

I created (with help) the following inline plugin code with specific variables for

  • a rounded samplerate for use with FLAC
  • a rounded average bitrate for use with MP3/AAC
  • a ‘is_flac’ check to determine if format FLAC is true or false
  • a ‘format’ variable to determine the albums file format.

My inline plugin code looks like this:

  Inline plugin template
  item_fields:
    my_samplerate: round(samplerate / 1000)
    is_flac: 1 if format == "FLAC" else 0
    multidisc: 1 if disctotal > 1 else 0
  album_fields:  
    format: |
         formatList = []
         for item in items:
             formatList.append(item.format)
         return formatList
    av_bitrate: |
         total = 0
         for item in items:
             total += item.bitrate
         return round(total / len(items) / 1000)

This is my full path:

paths:
  default: 'Albums/%the{$albumartist}/$album (%if{$original_year,$original_year}) %aunique{albumartist album year, albumtype label catalognum albumdisambig}%if{$albumdisambig,($albumdisambig $year) }%if{$is_flac,($format $bitdepth-$my_samplerate),($format $av_bitrate)}/%if{$multidisc,$disc-}$track - $title'

And in my path you can see the following %if statement to achieve the differentiation for FLAC and MP3/AAC

%if{$is_flac,($format $bitdepth-$my_samplerate),($format $av_bitrate)}

I hope this helps. If you need clarification please post and I’ll try to clarify.

Thanks again for all the help,
Jan


#5

Thanks for the update, @janpeeters. Did you find a solution to duplicate checking that you’re happy with?


#6

No helas, I didn’t succeed in achieving that.
@adrian suggested to use the samplerate as disambiguation but I added that to my path but didn’t get it to work.

So in the end I asked myself why keep mp3’s when I have a higher resolution FLAC file? I decided that for duplicates the highest quality format stays and the rest gets omitted.

For on the road I have Spotify so I don’t really needed to keep MP3s too.