Categorizing lossless music

Tags: #<Tag:0x00007f23c633dbc8>


Hi there.
I couldn’t find script for this query:

if file type in (*.FLAC, *, *.WAV) then categorize by this rule:


if file type in (*.MP3) then categorize by this rule:

Can someone help me?


Something like this:


I actually have a small plugin which provides me two functions $is_lossless() and $is_lossy(). The functions also try to detect whether a mp4 is lossy or lossless. Maybe I should publish it :slight_smile: if you want to try this place the following code in a file called e.g. inside the Picard plugin folder (click on “Open plugin folder” in Options > Plugins):

# -*- coding: utf-8 -*-
PLUGIN_NAME = 'Tagger script functions is_lossless() and is_lossy()'
PLUGIN_AUTHOR = 'Philipp Wolfer'
PLUGIN_DESCRIPTION = 'Tagger script functions to detect if a file is lossless or lossy'

from picard.script import register_script_function

LOSSLESS_EXTENSIONS = ['flac', 'oggflac', 'ape', 'ofr', 'tak', 'wv', 'tta', 'wav']

def is_lossless(parser):
    Returns true, if the file processed is a lossless audio format.
    Note: This depends mainly on the file extension and does not look inside the
    file to detect the codec.
    if parser.context['~extension'] in LOSSLESS_EXTENSIONS:
        return "1"
    elif parser.context['~extension'] == 'm4a':
        # Mutagen < 1.26 fails to detect the bitrate for Apple Lossless Audio Codec.
        if not parser.context['~bitrate'] or parser.context['~bitrate'] > 1000:
            return "1"
            return ""
        return ""

def is_lossy(parser):
    """Returns true, if the file processed is a lossy audio format."""
    if is_lossless(parser) == "1":
        return ""
        return "1"


Enable the plugin in Pcicard’s options, then you can use it like this:


Folder naming by Codec / File Format

Awesomenesss, wow :slight_smile:
Thanks for help!


Just realized that “wav” should also be in the lossless extension list. I updated the plugin code above. I initially did not add this as I don’t use WAV and Picard does not save tags to WAV anyway, so I think it should nearly always be better to use FLAC instead except you absolutely need it to be in WAV format for some reason :slight_smile: