Some help with naming script?

picard
taggerscript
Tags: #<Tag:0x00007f2a0037b758> #<Tag:0x00007f2a0037b5c8>

#1

Hola,

So, I don’t understand the script coding language too well, my knowledge basically consisted of %artist% and %album%. So I dug through the forums to find a script someone else wrote that would give me something close to what I want, and then tweaked it to my needs.

Well, I’ve reached the limit on what I know how to change. My problem with the current script is some of the character replacement - I actually don’t have a huge issue with forbidden and nonlatin characters and the like, and I prefer to have my filenames with proper Japanese characters, tags with the same, etc. Of course, I understand that certain things like colons simply will never be in file names, but they can still make it into tags and that’s fine with me. The trouble is, I can’t really figure out exactly how I need to tweak this beastly script to allow those conventions in filenames (and the others at least in metadata). If someone would kindly lend assistance, I’d be very grateful…here’s the script:

$noop(Variables for characters replacement and maximum filename length)
$set(_unixforbiddencharactersfullstop,.)
$set(_unixforbiddencharactersonedotleader,․)
$set(_unixforbiddencharactersellipsis,...)
$set(_unixforbiddencharactershorizontalellipsis,…)
$set(_windowsforbiddencharacters,\\/:*?"<>|    \\n)
$set(_musicbrainzreplacementforwindowsforbiddencharacters,)
$set(_charactersforspace,\\s)
$set(_maximumlength,85)
$set(_toolongmarker,[…])

$noop(Variables for flags you can write in the comments of the musical file)
$noop(Attention: Do not write parentheses in the Comment tag)
$set(_artistdelimiter,;)
$set(_commentdelimiter,|)
$set(_nonlatinartistinenglish,NonLatinArtistInEnglish=)
$set(_nonlatinartistinlatin,NonLatinArtistInLatin=)
$set(_artistcommentinenglish,ArtistCommentInEnglish=)
$set(_nonlatinalbuminenglish,NonLatinAlbumInEnglish=)
$set(_nonlatinalbuminlatin,NonLatinAlbumInLatin=)
$set(_albumcommentinenglish,AlbumCommentInEnglish=)
$set(_nonlatintitleinenglish,NonLatinTitleInEnglish=)
$set(_nonlatintitleinlatin,NonLatinTitleInLatin=)
$set(_titlecommentinenglish,TitleCommentInEnglish=)
$set(_firstpartofthename,FirstPartOfTheName=)
$set(_lastpartofthename,LastPartOfTheName=)
$set(_samemainartistforalltracks,SameMainArtistForAllTracks=)

$noop(Part 1: Define artist part)
$noop(1 - Extract form Comment tag the flags about non-latin artist in english, otherwise in latin)
$set(_nonlatinartist,$rsearch(%comment:%,%_nonlatinartistinenglish%[^\(\)]+))
$if($eq(%_nonlatinartist%,),$set(_nonlatinartist,$rsearch(%comment:%,%_nonlatinartistinlatin%[^\(\)]+)),)
$set(_nonlatinartist,$rsearch(%_nonlatinartist%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_nonlatinartist,$rreplace(%_nonlatinartist%,^%_nonlatinartistinenglish%{1},))
$set(_nonlatinartist,$rreplace(%_nonlatinartist%,^%_nonlatinartistinlatin%{1},))
$noop(2 - Delete the delimiter which separe the different comments)
$if($eq($right(%_nonlatinartist%,1),%_commentdelimiter%),$set(_nonlatinartist,$trim(%_nonlatinartist%,%_commentdelimiter%)),)
$if($eq($right(%_nonlatinartist%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_nonlatinartist,$trim(%_nonlatinartist%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)
$noop(3 - Exactly the same but with the comments on the artist)
$set(_artistcomment,$rsearch(%comment:%,%_artistcommentinenglish%[^\(\)]+))
$set(_artistcomment,$rsearch(%_artistcomment%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_artistcomment,$rreplace(%_artistcomment%,^%_artistcommentinenglish%{1},))
$if($eq($right(%_artistcomment%,1),%_commentdelimiter%),$set(_artistcomment,$trim(%_artistcomment%,%_commentdelimiter%)),)
$if($eq($right(%_artistcomment%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_artistcomment,$trim(%_artistcomment%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)

$noop(Part 2: Define album part, exactly the same)
$set(_nonlatinalbum,$rsearch(%comment:%,%_nonlatinalbuminenglish%[^\(\)]+))
$if($eq(%_nonlatinalbum%,),$set(_nonlatinalbum,$rsearch(%comment:%,%_nonlatinalbuminlatin%[^\(\)]+)),)
$set(_nonlatinalbum,$rsearch(%_nonlatinalbum%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_nonlatinalbum,$rreplace(%_nonlatinalbum%,^%_nonlatinalbuminenglish%{1},))
$set(_nonlatinalbum,$rreplace(%_nonlatinalbum%,^%_nonlatinalbuminlatin%{1},))
$if($eq($right(%_nonlatinalbum%,1),%_commentdelimiter%),$set(_nonlatinalbum,$trim(%_nonlatinalbum%,%_commentdelimiter%)),)
$if($eq($right(%_nonlatinalbum%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_nonlatinalbum,$trim(%_nonlatinalbum%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)
$set(_albumcomment,$rsearch(%comment:%,%_albumcommentinenglish%[^\(\)]+))
$set(_albumcomment,$rsearch(%_albumcomment%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_albumcomment,$rreplace(%_albumcomment%,^%_albumcommentinenglish%{1},))
$if($eq($right(%_albumcomment%,1),%_commentdelimiter%),$set(_albumcomment,$trim(%_albumcomment%,%_commentdelimiter%)),)
$if($eq($right(%_albumcomment%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_albumcomment,$trim(%_albumcomment%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)

$noop(Part 3: Define Title part, exactly the same)
$set(_nonlatintitle,$rsearch(%comment:%,%_nonlatintitleinenglish%[^\(\)]+))
$if($eq(%_nonlatintitle%,),$set(_nonlatintitle,$rsearch(%comment:%,%_nonlatintitleinlatin%[^\(\)]+)),)
$set(_nonlatintitle,$rsearch(%_nonlatintitle%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_nonlatintitle,$rreplace(%_nonlatintitle%,^%_nonlatintitleinenglish%{1},))
$set(_nonlatintitle,$rreplace(%_nonlatintitle%,^%_nonlatintitleinlatin%{1},))
$if($eq($right(%_nonlatintitle%,1),%_commentdelimiter%),$set(_nonlatintitle,$trim(%_nonlatintitle%,%_commentdelimiter%)),)
$if($eq($right(%_nonlatintitle%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_nonlatintitle,$trim(%_nonlatintitle%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)
$set(_titlecomment,$rsearch(%comment:%,%_titlecommentinenglish%[^\(\)]+))
$set(_titlecomment,$rsearch(%_titlecomment%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_titlecomment,$rreplace(%_titlecomment%,^%_titlecommentinenglish%{1},))
$if($eq($right(%_titlecomment%,1),%_commentdelimiter%),$set(_titlecomment,$trim(%_titlecomment%,%_commentdelimiter%)),)
$if($eq($right(%_titlecomment%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_titlecomment,$trim(%_titlecomment%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)

$noop(Part 4: Prefer %albumartist% on %artist%, but not if it is "various artists")
$noop(If there are many artist separated by ; we take just the first)
$set(_artist,$if($and($ne(%albumartist%,),$ne($lower(%albumartist%),various artists)),%albumartist%,%artist%))
$if($in(%_artist%,%_artistdelimiter%),$set(_morethanoneartist,1),$set(_morethanoneartist,0))
$if($eq(%_morethanoneartist%,1),$set(_artist,$rsearch(%_artist%,[^%_artistdelimiter%]+%_artistdelimiter%)),)
$if($eq(%_morethanoneartist%,1),$if($eq($right(%_artist%,1),%_artistdelimiter%),$set(_artist,$trim(%_artist%,%_artistdelimiter%)),),)
$noop(We add the parts about non latin artist and comments)
$set(_artist,%_artist%$if($ne(%_nonlatinartist%,), \(%_nonlatinartist%\),)$if($ne(%_artistcomment%,), \(%_artistcomment%\),))

$noop(Part 5: Define the date, if incomplete, we take just the year, otherwise the complete date)
$set(_date,$if2(%originaldate%,%date%))
$if($eq($len(%_date%),10),$set(_date,$left(%_date%,4)))

$noop(Part 6: If more than one disc, we write in the name the disc number and the subtitle of the disc)
$set(_album,%album%$if($gt(%totaldiscs%,1), \(Disc %discnumber%$if($ne(%discsubtitle%,), - %discsubtitle%\),\)$if($ne(%_nonlatinalbum%,), \(%_nonlatinalbum%\),)$if($ne(%_albumcomment%,), \(%_albumcomment%\),)),$if($ne(%_nonlatinalbum%,), \(%_nonlatinalbum%\),)$if($ne(%_albumcomment%,), \(%_albumcomment%\),)))

$noop(Part 7: If this is not a track, we write 0)
$set(_notrack,$if($if2($eq(%album%,[non-album tracks]),$eq(%tracknumber%,0),$eq(%tracknumber%,)),1,0))
$set(_tracknumber,$if($eq(%_notrack%,0),$num(%tracknumber%,1),0))

$noop(Part 8: Setting title)
$set(_title,%title%$if($ne(%_nonlatintitle%,), \(%_nonlatintitle%\),)$if($ne(%_titlecomment%,), \(%_titlecomment%\),))

$noop(Part 9: Exactly the same of the first paragraphs of this script: extract from the comments the part to write at the start or the end of the filename)
$set(_filenameprefix,$rsearch(%comment:%,%_firstpartofthename%[^\(\)]+))
$set(_filenameprefix,$rsearch(%_filenameprefix%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_filenameprefix,$rreplace(%_filenameprefix%,^%_firstpartofthename%{1},))
$if($eq($right(%_filenameprefix%,1),%_commentdelimiter%),$set(_filenameprefix,$trim(%_filenameprefix%,%_commentdelimiter%)),)
$if($eq($right(%_filenameprefix%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_filenameprefix,$trim(%_filenameprefix%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)
$set(_filenamesuffix,$rsearch(%comment:%,%_lastpartofthename%[^\(\)]+))
$set(_filenamesuffix,$rsearch(%_filenamesuffix%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_filenamesuffix,$rreplace(%_filenamesuffix%,^%_lastpartofthename%{1},))
$if($eq($right(%_filenamesuffix%,1),%_commentdelimiter%),$set(_filenamesuffix,$trim(%_filenamesuffix%,%_commentdelimiter%)),)
$if($eq($right(%_filenamesuffix%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_filenamesuffix,$trim(%_filenamesuffix%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)

$noop(Part 10: Control the size of the different parts to be sure that the filename won't be too long, otherwise, trunk the name correctly)
$if($gte($len(%_artist%),%_maximumlength%),$set(_artist,$firstwords(%_artist%,%_maximumlength%)%_toolongmarker%),)
$if($gte($len(%_album%),%_maximumlength%),$set(_album,$firstwords(%_album%,%_maximumlength%)%_toolongmarker%),)
$if($gte($len(%_title%),%_maximumlength%),$set(_title,$firstwords(%_title%,%_maximumlength%)%_toolongmarker%),)

$noop(Part 11: Center of the script, define the order of the parts)
$noop(If normal: Artist - Date - Album - Track - Title, If various artists: Album - Date - Track - artist - Title)
$noop(Possibility to force the order you wish with the flag SameMainArtistForAllTracks=1 or 2)
$if($eq(%compilation%,1),$set(_sameartistinthealbum,0),$set(_sameartistinthealbum,1))
$set(_forcesameartist,$rsearch(%comment:%,%_samemainartistforalltracks%[^\(\)]+))
$set(_forcesameartist,$rsearch(%_forcesameartist%,[^%_commentdelimiter%]+%_commentdelimiter%))
$set(_forcesameartist,$rreplace(%_forcesameartist%,^%_samemainartistforalltracks%{1},))
$if($eq($right(%_forcesameartist%,1),%_commentdelimiter%),$set(_forcesameartist,$trim(%_forcesameartist%,%_commentdelimiter%)),)
$if($eq($right(%_forcesameartist%,1),%_musicbrainzreplacementforwindowsforbiddencharacters%),$set(_forcesameartist,$trim(%_forcesameartist%,%_musicbrainzreplacementforwindowsforbiddencharacters%)),)
$if($eq(%_forcesameartist%,1),$set(_sameartistinthealbum,1),)
$if($eq(%_forcesameartist%,2),$set(_sameartistinthealbum,0),)
$set(_trackname,$if($ne(%_filenameprefix%,),%_filenameprefix% - ,)$if($eq(%_sameartistinthealbum%,1),%_artist%/%_album%/ %_artist% - %_album% - %_date% - %_tracknumber% - %_title%,%_artist%/%_album%/%_artist% -%_album% - %_date% - %_tracknumber% - %_title%)$if($ne(%_filenamesuffix%,), - %_filenamesuffix%,))

%_trackname%

I had to wrap it in code tags because the instructions in the sticky about formatting taggerscipt are…less than helpful. It formatted the first line of the script correctly, at least… I’m assuming the graves are a placeholder for spaces, which is what I did, but only 1 line gets formatted, probably due to how my script is formatted on its own.

Anyways, thanks in advance!

Kyle


#2

Just a quick note: You can actually enable syntax highlighting for tagger script in your posts, that makes the script much more readable :slight_smile:

Can you tell which replacements cause issues for you. From what I can see without looking too closely this script defines mostly replacements for characters not allowed in Windows file names, and I am not sure why it does that since Picard will handle this by itself. And there are replacements for a leading dot (also causing issues on all kinds of operating system) and ellipsis. This all should not affect Japanese characters.

On the other hand Picard itself has some options that affects non latin characters. Check your settings in Options -> Metadata, especially “Translate artists names to this locale where possible”, “Use standardized artist names” and “Convert Unicode punctuation characters to ASCII”.

What I wrote here pretty much applies to this as well.


#3

Thanks for the quick reply. You may have missed it, but I actually addressed the lack of syntax highlighting in my post - I suppose it’s due to the formatting of the script itself interfering with the forum coding. If you have any ideas, I’m all ears, I’d love to make it more readable.

I actually read that same post re: script complexity before I posted mine, so I understand your reply. The relevant portions should all feasibly be in the early sections that deal with character replacement and nonlatin artists and such, but as you pointed out, maybe it’s a Picard thing, so thanks for the tip. I’ll dig through more when I’m at my computer again (the mobile interface for this forum is killer btw).

Also re: script complexity: well, the trouble is, I like 90% of how this script handles my data (well, 80%, I changed the other 15% manually and there’s a good 30% that I simply don’t understand), and my alternative is to learn the scripting language. I don’t have the luxury of that kind of time right now, which is the reason I found one that someone else made already that was close to what I wanted, and tweaked it to my needs based on my current limited knowledge, rather than making my own from scratch (reinventing the wheel, poorly). If I can’t get it perfect, so be it. It’s miles better than what I had of my own accord and preferable to all the other options I managed to scrape from forums previously :stuck_out_tongue:


Using tagger script syntax highlighting in Discourse
#4

They aren’t. The graves are placeholders for graves. I edited your post to enable the syntax highlighting. You should see an orange/red-ish pencil icon by your post indicating there’s been a change. If you click it and choose the “raw” comparison, you can see what I changed.


#5

Really weird, that’s the first thing I tried - it didn’t work when I did it. Three graves simply turned into one, it displayed the text “`taggerscript” with the single grave appended and everything, and my code was a mess. Well, thanks for formatting it for me.This thread is officially derailed :wink:

So, I do not have “translate artists names” (or both the other options) enabled; the issue actually makes “光田康典” come out as “____” and I haven’t tried many of my other albums simply because I don’t want to have to fix everything later. The tags are still retained, but the filenames and folder structures become hosed. I will use translated names if I have to but I’d prefer not.

I’m actually not 100% sure if the script is causing the issue or not, but it seemed the most likely culprit to me which is why I brought it up in the first place.


#6

Ok, that’s strange. You should not need to use translated artist names. Japanese or other scripts should work fine in general. If I find some time this evening I will test it here with your script, let’s see if I can reproduce it.


#7

Note that the you have to do the three graves twice: once to start the code block, and once again to end it. If you only do one ```, it will indeed appear as a single `.


#8

Thank you, I thought I definitely closed it with three, but it’s really the only likely explanation I can think of.

Thank you :slight_smile: