Using tagger script syntax highlighting in Discourse

discourse
howto
taggerscript
Tags: #<Tag:0x00007f2a0036aa70> #<Tag:0x00007f2a0036a7c8> #<Tag:0x00007f2a0036a5c0>

#1

Continuing the discussion from Some help with naming script?:

I think I misunderstood that part, I thought it was related to the formatting inside Picard :slight_smile:

Nevertheless, the syntax highlighting here for your script works just fine. What you need is first place

```taggerscript

in one line (those are three backticks). Then just paste your script below this in a new line

$noop(Variables for characters replacement and maximum filename length)
$set(_unixforbiddencharactersfullstop,.)
$set(_unixforbiddencharactersonedotleader,․)
...

And end this whole block with another three backticks:

```

The result should be this:

$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%

How are Deluxe/Legacy/Expanded Editions handled?
Help understanding Picard naming script system for noob
#2

I have noticed that these blocks, once in a quote, would not render as intended.
It would display code block, starting with showing text taggerscript, then code rows without colouring.

It is only when we quote the post with the Discourse buttons, not when we hand‐type the quotes > or [quote] do work when hand‐typed but try to Reply the first post here then click the Quote whole post (bubble) icon and look at the right‐hand side preview, there will be uninterpreted taggerscript.


#3

https://meta.discourse.org/t/code-type-hints-broken-in-quotes/26229


Help understanding Picard naming script system for noob
#4

@WovenTales, you asked about Picard tagger script syntax highlighting at some point. This is how. :slight_smile:


#5

This will definitely come in handy. Thanks for digging it back up!