Scripting help for a noob please

Hi there, everyone. I really don’t know much about scripts, but I want to set up a script so I can get on with fixing my library (about 3.3 TB so far).

I tried to employ AI to help me create a script and the ‘oh so cocky and confident’ AI reckoned it could help do this easily. Fast forward a few hours now and I’ve given up trying to help it get the script right so it is valid and performs all desired functions.

I wanted a script that could differentiate between normal albums and compilations and move and format the folder and file structure accordingly. I also wanted it to deal with multi-disc albums, including albums with disc ‘subtitles’. I wanted it to deal with illegal characters such as ? | \ / : ; # and emojis, etc. for | and : I wanted to replace them with ‘-’ and '- ’ respectively. In a more graphical and easy-to-understand format I wanted:

:white_check_mark: Compilations → Stored in /Compilations/Album Name (Year)/Track - Title - Artist

:white_check_mark: Artists → Stored in /Artists/Artist Name/Album Name (Year)/Track - Title

:white_check_mark: Multi-Disc Handling → Adds ‘CD x’ as a subfolder under the album folder, if applicable

:white_check_mark: Disc Subtitle Support → Includes disc subtitles, if present, to the multi-disc subfolder; ‘CD x - Subtitle’

:white_check_mark: Strict Confidence Check → Only processes files with a match confidence of 95% or higher

:white_check_mark: Illegal Character Cleanup → Replaces : with -

I just couldn’t get the script to create the compilations or artist’s subfolders though. However, because I never got that far I never tested the script out anyway so there may be (and probably is) a lot of other errors in it.

Someone who actually knows and understands Picard’s scripting will probably laugh at this script (which is only one of many iterations). I would really appreciate it if someone or some people could help me craft a script that meets all or as many of these needs as possible (instead of telling me to go off and learn all of this stuff myself and then make it myself - as you can see I’ve been a member since 2013 and obviously have never gotten around to it).

So, is there anyone up to the challenge to help me out here, please?

ok, so i tried copy and pasting a few bits of code that AI had written and got this far:

%albumartist%/
%album% ($left(%date%,4))/
$if($gt(%totaldiscs%,1),CD %discnumber%) $if($gt(%discsubtitle%,1),- %discsubtitle%)/
%tracknumber% - %title%

this seems to create most of the file and folder structure I want but doesn’t do the complicated stuff such as dealing with illegal characters and emoji’s or differentiating between artist albums or compilations and putting them into the correct subfolders. I also couldn’t seem to get $year to work so had to use some AI jiggery-pokery with the whole ‘first 4 digits of the date’ method.

I’d still also like to drop chunks of my unsorted library into a watch folder and get Picard to process the files automatically BUT ONLY processing files with a confidence score of 95+.

You’ll have to wait for better scripters to help out with the rest, but just thought I’d drop in this script nippet to differentiate between “normal albums and compilations”: Repository for neat file name string patterns and tagger script snippets - #277 by aerozol

Have you checked the excellent Picard documentation site which has a good page on renaming scripts?

thanks. trying to use that snippet i tried creating the following (with AI help) but it doesn’t seem to work on the example songs in the script editor:

$noop(★ Remove Illegal Characters in Multiple Stages ★)

$set(_clean_albumartist,$replace(%albumartist%,:, -))

$set(_clean_albumartist,$replace(%_clean_albumartist%,/,-))

$set(_clean_albumartist,$replace(%_clean_albumartist%,?,))

$set(_clean_albumartist,$replace(%_clean_albumartist%,*,))

$set(_clean_albumartist,$replace(%_clean_albumartist%,",‘’))

$set(_clean_albumartist,$replace(%_clean_albumartist%,<,))

$set(_clean_albumartist,$replace(%_clean_albumartist%,>,))

$set(_clean_albumartist,$replace(%_clean_albumartist%,|,-))

$set(_clean_album,$replace(%album%,:, -))

$set(_clean_album,$replace(%_clean_album%,/,-))

$set(_clean_album,$replace(%_clean_album%,?,))

$set(_clean_album,$replace(%_clean_album%,*,))

$set(_clean_album,$replace(%_clean_album%,",‘’))

$set(_clean_album,$replace(%_clean_album%,<,))

$set(_clean_album,$replace(%_clean_album%,>,))

$set(_clean_album,$replace(%_clean_album%,|,-))

$set(_clean_title,$replace(%title%,:, -))

$set(_clean_title,$replace(%_clean_title%,/,-))

$set(_clean_title,$replace(%_clean_title%,?,))

$set(_clean_title,$replace(%_clean_title%,*,))

$set(_clean_title,$replace(%_clean_title%,",‘’))

$set(_clean_title,$replace(%_clean_title%,<,))

$set(_clean_title,$replace(%_clean_title%,>,))

$set(_clean_title,$replace(%_clean_title%,|,-))

$noop(★ Extract Year from Date ★)

$set(_year,$left(%date%,4))

$noop(★ Detect Various Artists / Compilations ★)

$if($eq(%albumartist%,Various Artists),

$set(_isVarious,1)

)

$noop(★ File Structure for Confident Matches Only ★)

$if($gte(%_recording_match%,95),

$noop(★ Compilation Albums ★)

$if($or($eq(%_isVarious%,1),$eq(%compilation%,1)),

Compilations/%_clean_album% (%_year%)/$if($gt(%totaldiscs%,1),CD %discnumber%)$if(%discsubtitle%, - %discsubtitle%)/%tracknumber% - %_clean_title% - %artist%,

$noop(★ Artist Albums ★)

Artists/%_clean_albumartist%/%_clean_album% (%_year%)/$if($gt(%totaldiscs%,1),CD %discnumber%)$if(%discsubtitle%, - %discsubtitle%)/%tracknumber% - %_clean_title%

)

)

Hi Sophist. Yes i found it useful (what I managed to read of it). i find guides that are loaded with text overwhelming to be honest but I managed to get through a few pages and it helped but I find it hard to understand how I connect bits of scripting together and the rules to which they have to lie within. I still could do with help to create a more advanced script though.

If I understand you correctly, you want to have your file renaming script use different file naming templates / structures depending on certain criteria. I do that in my file naming script, which you might be able to use as an example or starting point. It is available in my GitHub repo, and is heavily commented to help explain how it works and what is being done in each section. The only time I need to specify which format to use is for Classical music albums, and that’s only because I haven’t taken the time to develop a way to automatically identify them from the available metadata.

As mentioned earlier, the Scripting, Tags & Variables and Scripting Functions sections of the Picard User Guide are a valuable reference when writing scripts. There is also a simple tutorial on Writing a File Naming Script that might help with the overall process.

When developing a script like you’re wanting, I find it useful to break the work up into smaller chunks (modules) such as: data cleaning; selecting the format scheme; formatting scheme 1; formatting scheme 2; etc. The formatting schemes sections typically turn out to be the most straightforward and simplest to code.

Your overall script would start with the common code, which would likely be cleaning the data and creating the parts (strings) that you will use in the formatting sections. Then you would have the code that will select which format to use based on your selected criteria. Finally, you would apply the selected format.

Another benefit of developing the various sections separately is that, once you have things working you can (more) easily make additions or modifications (or optimizations) to a section without impacting the rest of your code.

I haven’t looked at the code you posted in any detail, but there are a few potential optimizations that could be made in the “Remove Illegal Characters” code, utilizing a multi-value variable with a loop (or a regular expression). Again, this could be done later – after you have the script working the way you want it.

It is entirely up to you, but I also advise against using AI to try to develop the script. I never use AI for development work because too many times I’ve seen others rely on it, and fail to get the desired results. If I develop something myself, I have a better understanding of how it works which makes modifying (or fixing) something so much simpler. YMMV.

2 Likes

AI simply a little more advanced version of a chat-bot from the 1980s - they simply regurgitate what they have been fed without having even a glimmer of intelligence (or ironically for computers, logic) that they can use to weigh up what they are told and discriminate between wildly unscientific and illogical and unsupported false theories and evidence-supported, scientifically and logically consistent actual facts.

When my lawyer brother-in-law (who I never rated as a lawyer) started telling me he was basing his informal advice on what ChatGPT told him, my opinion was validated in Trumps.

If you don’t have the skills to at least check the validity of AI results, you shouldn’t be using it.

P.S. You have Bob @rdswift to thank for the excellent documentation.

2 Likes

Thanks for your advice and guidance. I’m concerned the advanced scripting is going to take more time than I have available to figure out, indeed I looked at your script and (no offence) but it is that advanced that it is just jibberish to me lol). Its the kind of thing that seems like it needs to be a labour of love to get reasonably right and I don’t have the time to go that deep (nor did I hope or expect to have to to get files tagged and named how I would like to be honest). It will probably end up that I will either have to steal someone else’s script (if I find someone who wants their files configured like I do) or I’ll just have to keep it more basic and just get on with all the other things in life that I have/want to do as well to be honest.