[SNIPPET] Collecting audio tracks by format, handles commentary tracks seperately

All about user-defined episode / movie / file name format expressions
Post Reply
Franky
Posts: 9
Joined: 31 Mar 2021, 16:38

[SNIPPET] Collecting audio tracks by format, handles commentary tracks seperately

Post by Franky »

Example:
The Fellowship of the Ring
Track 1: 6ch E-AC3 Atmos English
Track 2: 6ch E-AC3 Atmos German
Track 3-6: Commentary tracks

Result: [5.1 AC3+ Atmos (eng deu)][Commentary x4]

Groovy: Select all

{	
	import java.math.RoundingMode
	import net.filebot.Language

	audio.findAll{
		it.Title =~ /^(?i:(?!comment|isolated).)*$/ 
	}.groupBy{	
		def channels_string = channels
		if (it.'ChannelPositions/String2'!=null) {
		channels_string = it.'ChannelPositions/String2'
			.replaceAll(/Object\sBased\s\/|0.(?=\d.\d)|\.\?/, '')
			.tokenize('\\/')
			.take(3)
			*.toDouble()
			.inject(0, { a, b -> a + b })
			.findAll { it > 0 }
			.max()
			.toBigDecimal()
			.setScale(1, RoundingMode.HALF_UP)
			.toString()
		}
		[channels_string, it.FormatCommercial, it.Format_Profile
		]
	}.collect{ group, it ->
		[*group, '('+it.'Language/String3'.unique().join(' ').lower().replaceAll(/zxx/,/silent/).removeAll(/-..$/)+')']
	}.join(' ').replaceAll('Layer 3','MP3').replaceAll('Layer 2','MP2').replaceAll('Dolby Digital','AC3').replaceAll(' Plus','+')
.replaceAll('Master Audio','MA').replaceAll('Atmos',' Atmos').replaceAll('High Resolution Audio','HD').removeAll(/,| null|Dolby | with | Discrete| Matrix| \+ DTS|MPEG Audio/)
.replace(
    '<' : '﹤',
    '>' : '﹥',
    ':' : 'ː',
    '"' : '“',
    '/' : '⁄',
    '|' : '⼁',
    '?' : '﹖',
    '*' : '﹡',
    '\\': '∖'
)
}
{	
	audio.findAll{
		it.Title =~ /(?i:(comment))/ 
	}.groupBy{	
		['Commentary']
	}.collect{ group, it ->
	def comment_count = audio.findAll{it.Title =~ /(?i:(comment))/}.size
	if (comment_count<2){comment_count=null}else{comment_count='x'+comment_count}
		[*group,comment_count]
	}.join(' ').removeAll(/,| null/)
	
}
Post Reply