Help with refining picard script as well as how to sort radio and dj sets

Hi there, I am working on refining my MusicBrainz picard naming script. Im not great at scripting or coding.

However I did get help before and this is the file naming script I have $swapprefix($if2(%albumartist%,%artist%),A,An,The,Le)/ $if(%_date%,\(%_date%\) )%album% [%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%)]$if(%catalognumber%, \(%catalognumber%\))/ $if(%_discfolder%,%_discfolder%/) $num(%tracknumber%,2) - %artist% - %title%

Along with a Script in the script’s settings as `$set(_date,$left($if2(%originalyear%,%date%),4))

$if($eq(%media%,Compact Disc),$set(_source,CD))
// …and etc transforms to taste: https://musicbrainz.org/doc/Release/Format

$if($gt(%totaldiscs%,1),$set(_discfolder, Disc %discnumber%))`

However, there are a few things extra I would like to do with the script.

  1. Any lossy files such as mp3, Ogg, m4a etc instead of having [bit-44khz] due to the script, just instead have [320kbps mp3] for mp3 tracks that are 320kbps for example and for tracks that are 128kbps m4a files. the folder name would have [128kbps m4a] in the folder name.
  2. Some tracks would have _ due to a character that is not compatible with windows. any way to replace whatever_ whatever with whatever, whatever with the exception being if its in the MusicBrainz database. so replace _ with, with space afterwards.
  3. The final hardest part is that I want to sort out DJ mixes and radio recordings as this is what they are currently like https://imgur.com/a/QYzKQua. so I was wondering if there’s a way depending on how DJ mixes are added into MusicBrainz to put DJ mixes in their own folder such as DJ mixes sorted by DJ mixer. then for radio shows, to be put into a radio folder (not sure how to sort but could be sorted by the main host or program name such as dead ringers. but then for radio one essential mixes do they go in the dj mixes folder or radio folder? Or do I put dj and radio mixes into 1 folder sorted by dj mixer and radio host as what is suggested here on reddit.
  4. the next and final part is to be able to sort audiobooks which are prittly well organised but again could be organised much better into something universal.
  5. So I guess in picards settings I would have to change the folder structure from music to 1 directory up so that picard can move music into the music folder. dj mixes into dj mixes and radio shows into radio shows folder (unless i put radio and dj mixes into a compilations folder instead).

Any help would be appreciated.

thank you

update below, this is my renaming script so far. lossless lossy extension is needed.

$noop( ======================================================================= )
$noop( ===    Coded by Goldmaster with help from r/musichoarder discord    === )
$noop( ======================================================================= )

$noop(Replace part is to replace ANY _ or: which don`t work in windows with a comma, space.)
$replace(
$replace(


$set(_Directory,)
$if($not(%_Directory%),$if($inmulti(%releasetype%,audiobook),$set(_Directory,Audiobooks)))
$if($not(%_Directory%),$if($inmulti(%secondaryreleasetype%,audiobook),$set(_Directory,Dj Mixes)))
$if($not(%_Directory%),$if($inmulti(%releasetype%,audiobook),$set(_Directory,Radio),$set(_Directory,Music)))


$noop(For any album artists such as The Chemical Brothers, change the folder name to say Chemical Brothers, The.)
$swapprefix($if2(%albumartist%,%artist%),A,An,The,Le)/

$noop(Add in the original date the album came out for example a remastered 2017 version of a 1995 copy would start the year as 1995 in brackets.)
$if(%_date%,\(%_date%\) )%album% 

$noop(Using the lossles addon, any lossless albums would read as [16-bit 44khz] for cd qulity tracks, while lossy albums would read as [320kbps] for 320kbps tracks and add the media to the end.)
[$if($is_lossless(),%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz %_extension%,$replace(%_bitrate%,.0,)kbps %_extension%) %media%]

$noop(Adds the catalog number, but if there are any releases that have [none] in the catalog field, then just ignore.)
$if($and(%catalognumber%,$ne(%catalognumber%,[none])), \(%catalognumber%\))/

$noop(For mutidisc albums add a subfolder such as Disc 1, Disc 2 ect.)
$if(%_discfolder%,%_discfolder%/)

$noop(This is for vinyl albums which makes sure tracks display as A1, A2 ect.)
$if($in(%media%,Vinyl),%_musicbrainz_tracknumber%,$num(%tracknumber%,2)) - %artist% - %title%


$noop(Final part which closes of the script, like at the start, this for replacing ANY: or _ with a comma)
,:,\, )
,_,\, )

just need to fix dj mixes, radio shows and audiobooks.

2 Likes

Maybe use something like:

[$if(%_bits_per_sample%,%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%),%_bitrate%kbps %_extension%)]

That will use %_bitrate%kbps %_extension% if there is not %_bits_per_sample%.

I personally use a small plugin that gives me a $is_lossy() and $is_lossless() function, see Categorizing lossless music - #2 by outsidecontext . I never submitted this to the plugins list as it is kind of a hack and not 100% reliable, but it totally works for my use cases.

The characters not being allowed in Windows file names and hence getting replaced are ["*:<>?|]. Not sure which of those you want to replace with a comma, but you could wrap your entire naming script with a replacement, such as:

$replace(your naming script here,:,\,)

That would replace colons with a comma.

Two special cases are slash / and backslash \. As those are used as directory separators they get replaced with underscores before they reach the naming script. If you want to deal with those you need to handle this before, e.g. with a script modifying the tags or variables. E.g. if you want to replace a / in the artists add a script like this:

$set(_artist_for_filenaming,$replace(%artist%, /,\,))

This will add a variable %_artist_for_filenaming% which has the / replaced with a comma. Then in your file naming script you replace you use of `%artist% with

$if2(%_artist_for_filenaming%,%artist%)

The if2 is used to get a fallback in case %_artist_for_filenaming% is not set in situations where your other script has not run (e.g. if you save untagged files).

Yes. You’ll need to find out how to distingiush those cases then, I think you can use releasetype for your cases. Something like

$if($in(%releasetype%,audiobook),audiobooks,$if($in(%releasetype%,dj-mix),dj-mixes,music))

Not sure how radio shows are handled.

2 Likes

ok thank you for your help this is what I have so far

    $replace(
$if($not(%_placed%),
	$if($inmulti(%releasetype%,audiobook),
		$set(_placed,1)
		Audiobooks/
	)
)


$if($not(%_placed%),
	$if($inmulti(%secondaryreleasetype%,dj-mix),
		$set(_placed,1)
		Dj Mixes/
	)
)


$if($not(%_placed%),
	$if($inmulti(%releasetype%,broadcast),
		$set(_placed,1)
		Radio/
	)
)

$swapprefix($if2(%albumartist%,%artist%),A,An,The,Le)/
$if(%_date%,\(%_date%\) )%album% [$if(%_bits_per_sample%,%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%),%_bitrate%kbps %_extension%)$if(%_source%, %_source%)]$if(%catalognumber%, \(%catalognumber%\))/
$if(%_discfolder%,%_discfolder%/)
$if($in(%media%,Vinyl),%_musicbrainz_tracknumber%,$num(%tracknumber%,2)) - %artist% - %title%

,_,\,)

However the bit about

you could wrap your entire naming script with a replacement, such as:

$replace(your naming script here,:,\,)

doesn’t seem to have made a difference as the examples below still have an underscore instead of a comma.

this part

Maybe use something like:

[$if(%_bits_per_sample%,%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%),%_bitrate%kbps %_extension%)]

That will use %_bitrate%kbps %_extension% if there is not %_bits_per_sample%.

I personally use a small plugin that gives me a $is_lossy() and $is_lossless() function, see Categorizing lossless music .

I have managed to install the python plugin bit so I guess its a case of replacing something with $is_lossy and $is_lossless() then it should work from there.

I never submitted this to the plugins list as it is kind of a hack and not 100% reliable, but it totally works for my use cases.

you should submit it. you haven’t got anything to lose.

Not sure how radio shows are handled.

could stick into a compilations folder as per u/roboyoshi suggestion I spotted.

thank you for your help

You are trying to replace the underscore, but that doesn’t work, as at the point the script runs there are still the actual characters (one of "*:<>?|) there. The replacement of the special characters happens later. So in your $replace call you need to use the actual characters, something like $replace(your naming script here,:,\,) to replace the colon. I actually assumed you would want to have only specific characters replaced by comma!? Maybe if you can give a specific example what you want to have replaced how.

Yes, replacing your existing [%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%)] with the following should work:

[$if($is_lossless(),%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%),%_bitrate%kbps %_extension%)]

I’ll eventually submit this plugin :slight_smile:

1 Like

It strange I get an unknown function for the $is_lossless part. I have the plugin part installed and working as its showing in picard pluggins.

this is what I have it like

$if(%_date%,\(%_date%\) )%album% [$is_lossless(),%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%),%_bitrate%kbps %_extension%)]$if(%catalognumber%, \(%catalognumber%\))/

Do you have the plugin enabled? It should show a green checkmark. If it shows a cross it’s disabled, click on the cross to enable it.

Also you need to close and re-open the Options after enabling a plugin in order for it to be available in scripting. That’s a known limitation of the plugins system right now.

1 Like

yes I have managed to get it added in. however I have [1411.2kbps aif] insted of [16bit 44.1khz] for a test aif file.

You’d need to add aif and aiff to the list of extensions in the plugin, see the line starting with LOSSLESS_EXTENSIONS .

2 Likes

awesome got it now to work, just need to figure out how to display the extension on the end as that’s not showing did try

[$if($is_lossless(),%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz %_extenstion% $if(%_source%, %_source%),%_bitrate%kbps %_extension%)]

as well as %extention% but with no difference.

thank you for helping me get this far.

Can’t wait to see the lossless/lossy plugin as a plugin, hope you have a GitLab link for it. I can help submit a pull request for aif and AIFF files and for any other lossless files I come across.

1 Like

Hi there, this is the file naming script I have $swapprefix($if2(%albumartist%,%artist%),A,An,The,Le)/ $if(%_date%,\(%_date%\) )%album% [%_bits_per_sample%-bit $div(%_sample_rate%,1000) kHz$if(%_source%, %_source%)]$if(%catalognumber%, \(%catalognumber%\))/ $if(%_discfolder%,%_discfolder%/) $num(%tracknumber%,2) - %artist% - %title%

Along with a Script in the script’s settings as `$set(_date,$left($if2(%originalyear%,%date%),4))

$if($eq(%media%,Compact Disc),$set(_source,CD))
// …and etc transforms to taste: https://musicbrainz.org/doc/Release/Format

$if($gt(%totaldiscs%,1),$set(_discfolder, Disc %discnumber%))`

However, there are a few things extra I would like to do with the script.

  1. Any lossy files such as mp3, Ogg, m4a etc instead of having [bit-44khz] due to the script, just instead have [320kbps mp3] for mp3 tracks that are 320kbps for example and for tracks that are 128kbps m4a files. the folder name would have [128kbps m4a] in there.
  2. Some tracks would have _ due to a character that is not compatible with windows. any way to replace whatever_ whatever with whatever, whatever with the exception being if its in the MusicBrainz database. so replace _ with, with space afterwards.
  3. The final hardest part is that I want to sort out DJ mixes and radio recordings as this is what they are currently like https://imgur.com/a/QYzKQua. so I was wondering if there’s a way depending on how DJ mixes are added into MusicBrainz to put DJ mixes in their own folder such as DJ mixes sorted by dj mixer. then for radio shows, to be put into a radio folder (not sure how to sort but could be sorted by the main host or program name such as dead ringers. but then for radio one essential mixes do they go in the dj mixes folder or radio folder? Or do I put dj and radio mixes into 1 folder sorted by dj mixer and radio host as what is suggested here on reddit.
  4. the next and final part is to be able to sort audiobooks which are prittly well organised but again could be organised much better into something universal.
  5. So I guess in picards settings I would have to change the folder structure from music to 1 directory up so that picard can move music into the music folder. dj mixes into dj mixes and radio shows into radio shows folder (unless i put radio and dj mixes into a compilations folder instead).

Any help would be appreciated.

thank you.

I have asked here Help with refining picard script as well as how to sort radio and dj sets but not sure weather to ask here or start a new thread as it’s quite simple to do, but is very hard to program. I did see a lossy and lossless python script thing which I could try. But this is turning more into frustration as coding is my kryptonite.

To sort out your DJ mixes, radio recordings or audiobooks, you can try the method I describe in this post:

1 Like

thank you I will give it a go later on once I have sorted out this issue here.

the question I have is how could I add tracks and albums tagged as various and various artists into the same folder. titled as various artists.

Not sure what everyone does with these?

thoughts?

I do just that in my own script. The tag %compilation% is true for Various Artist albums, so testing on that allows you to separate them out.

Here’s my script:

so I guess that means if album artist is various, then move the album into various artists folder?

Yes. Under my Tagged Music folder, I have alphabetic folders for Artists, then special folders for Soundtracks and Various, sorted alphabetically by album name.

Hi there, I have started working a bit more on the script. I have added audiobooks part, however, the script doesn’t want to work with audiobooks correctly.

for some reason, any audiobooks end up as say audio\books\(2003) A Game Of Thrones [192kbps mp3 CD]\Disc 28\15George R․ R․ Martin read by Roy Dotrice\(2003) A Game Of Thrones [192kbps mp3 CD] (RHCD 3217)\Disc 28\15 - George R․ R․ Martin Read By Roy Dotrice - [A Game Of Thrones,.ext

instead of

audio\books\(2003) A Game Of Thrones [192kbps mp3 CD]\Disc 28\15 [A Game of Thrones, Part 492].ext

this is the script in its current state.

it seems to get stuck around %_musicbrainz_tracknumber%,$num(%tracknumber%,2) - %title%), any idea, how to fix the script so that audiobooks are moved into the correct folder structure please?

1 Like

Hey there, because Music Brainz Picard Version 2.7 (beta) now supports more than one script i made use of it. I´m Tagging Collections seperately with Foobar2000 with the Tags Collection and Collectiontyp (just select all Files, go to properties, right click, add Tag. The good thing is the search engine in Foobar2000 to find anything for an collection) and than use these Tags in an second script with Music Brainz Picard.

I think that would work for Audio Books, DJ Mixes and the Like aswell because you use your personal Tags as base. :slight_smile:

Collection Script:

/Collections/

$get(collectiontyp)/
$get(collection)/


$get(_extension)/

$if($is_complete(),
,$if($lt($matchedtracks(),%_totalalbumtracks%),_Incomplete/,_Dupes/)
)

$if(%musicbrainz_artistid%,
%originalyear% - $left(%album%,60)/$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)-)$num(%tracknumber%,3) $left(%title%,60),
_Missing/%date% - $left(%album%,60)/$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)-)$num(%tracknumber%,3) $left(%title%,60)
)

My Normal Script looks like this and goes more into detail with Sorting, so feel free to combine them or so

Musik Brainz/

$get(_extension)/

$if($is_complete(),
,$if($lt($matchedtracks(),%_totalalbumtracks%),_Incomplete/,_Dupes/)
)



$if($eq(%musicbrainz_albumartistid%,89ad4ac3-39f7-470e-963a-56509c546377),
$left($if2(%albumartist%, %artist%),50)/$upper($firstalphachar($if2(%album%, %albumsort%),_Missing))/$left(%album%,50)/$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)-)$num(%tracknumber%,3) $left(%title%,40),
$upper($firstalphachar($if2(%albumartist%, %artist%),_Missing))/$left($if2(%albumartist%, %artist%),40)/$left(%album%,40)/$if($gt(%totaldiscs%,1),CD$num(%discnumber%,2)-)$num(%tracknumber%,3) $left(%title%,40)
)

As a little example: I am tagging the “collectiontyp” Tag with the Tags compilations, discography, recordlabel or various so adding something like Audiobooks or DJ Mixes as an collectiontyp would be possible
For the Tag “collection” i am using something like Harry Potter (that would be collectiontyp Soundtrack) or Das Modul (that would be the collectiontyp discography) and so on.

3 Likes

@Goldmaster , I don’t know if you’ve solved this yet, but I’d be willing to bet it’s a misplaced parenthesis or comma. It does the audiobooks part right up to tracknumber, then follows with what I assume is the album artist, and “starts over” from there.

You should try pulling it up in something like Notepad++ that highlights parenthesis and walk through the code making sure that the start and end are where you expect them to be.