Taggerscript: Reformat standardized JP release catalog number as a range

De facto Style for JP releases is to enter the release catalog number as a separate release label entry per medium, if the release catalog is formatted as a range. In most cases, this can be reversed so that multiple release labels can be represented as a simple string of text that is a range.

Supported:

  • Releases with more than one catalog number prefix
  • Catalog number values without left-padded zeros that do not sort correctly alphabetically

TODO:

  • Drop trailing value in parentheses for catalog numbers that are directly associated with an additional value

Not supported:

  • Any delimiter that is not the ASCII hyphen-minus
  • Catalog numbers where the first usage of the hyphen-minus does not separate the prefix from the number
  • Catalog numbers with avex-style letter suffixes that share a numeric base with another disc that are stored as separate release label entries
  • Typos that cause the catalog numbers to have illogical sorting
  • Releases that have both catalog numbers with hyphens and catalog numbers without hyphens
$if($and($gt($lenmulti(%catalognumber%),1),$eq(%releasecountry%,JP)),

$foreach($unique(%catalognumber%),
$set(_catnoHyphenIndex,$find(%_loop_value%,-))

$if(%_catnoHyphenIndex%,
$set(_catnoPrefix,$substr(%_loop_value%,0,%_catnoHyphenIndex%))
$copymerge(_catnoPrefixes,_catnoPrefix)

$set(_catnoSuffixForCurrentField,_catnoSuffixes_%_catnoPrefix%)
$set(_catnoSuffixForCurrentValue,$substr(%_loop_value%,$add(%_catnoHyphenIndex%,1)))
$copymerge(%_catnoSuffixForCurrentField%,_catnoSuffixForCurrentValue)

$unset(_catnoHyphenIndex)
$unset(_catnoPrefix)
$unset(_catnoSuffixForCurrentField)
$unset(_catnoSuffixForCurrentValue)
)
)

$foreach(%_catnoPrefixes%,
$set(_catalognumberReformatted,$if($gt($len(%_catalognumberReformatted%),0),%_catalognumberReformatted% / ,)%_loop_value%-)

$set(_catnoSuffixForCurrentField,_catnoSuffixes_%_loop_value%)

$noop(Find min and max values from alphabetical order [1, 10, ..., 19, 2, 20, ..., 57, 58, 6, 7, 8, 9].)
$set(_catnoPair_minValue,-1)
$set(_catnoPair_maxValue,-1)
$foreach($get(%_catnoSuffixForCurrentField%),
$if($eq(%_catnoPair_minValue%,-1),$set(_catnoPair_minValue,%_loop_value%),$if($lt(%_loop_value%,%_catnoPair_minValue%),$set(_catnoPair_minValue,%_loop_value%)))
$if($eq(%_catnoPair_maxValue%,-1),$set(_catnoPair_maxValue,%_loop_value%),$if($gt(%_loop_value%,%_catnoPair_maxValue%),$set(_catnoPair_maxValue,%_loop_value%)))
)

$set(_catalognumberReformatted,%_catalognumberReformatted%%_catnoPair_minValue%)
$if($gt($lenmulti($get(%_catnoSuffixForCurrentField%)),1),

$noop(Remove common left-leading digits)
$if($eq($len(%_catnoPair_minValue%),$len(%_catnoPair_maxValue%)),
$set(_catnoPairSharedDigitCount,$len(%_catnoPair_minValue%))
$set(_catnoPair_maxValue_SignificantDigitsValue,)
$while($and($gt(%_catnoPairSharedDigitCount%,0),$not(%_catnoPair_maxValue_SignificantDigitsValue%)),
$set(_catnoPairSharedDigitCount,$sub(%_catnoPairSharedDigitCount%,1))
$if($eq($substr(%_catnoPair_minValue%,0,%_catnoPairSharedDigitCount%),$substr(%_catnoPair_maxValue%,0,%_catnoPairSharedDigitCount%)),
$set(_catnoPair_maxValue_SignificantDigitsValue,$substr(%_catnoPair_maxValue%,%_catnoPairSharedDigitCount%))
)
)
)
$if(%_catnoPair_maxValue_SignificantDigitsValue%,$set(_catnoPair_maxValue,%_catnoPair_maxValue_SignificantDigitsValue%))

$set(_catalognumberReformatted,%_catalognumberReformatted%~%_catnoPair_maxValue%)
)

)

$if(%_catalognumberReformatted%,
$set(catalognumber,%_catalognumberReformatted%)
$unset(_catalognumberReformatted)
)
$unset(_catnoSuffixForCurrentField)
$unset(_catnoPair_minValue)
$unset(_catnoPair_maxValue)
$unset(_catnoPairSharedDigitCount)
$unset(_catnoPair_maxValue_SignificantDigitsValue)

)
5 Likes

Works great, thanks again for picking this up!

2 Likes