How to use pre-defined functions in {languages}

All about user-defined episode / movie / file name format expressions
Post Reply
Saaam
Posts: 1
Joined: 30 Nov 2019, 15:15

How to use pre-defined functions in {languages}

Post by Saaam »

Hi!

I have just installed FileBot for the first time. I usually rename the multi audio movies as [Eng 5.1 - Hin 5.1 - Fre 2.0] where 5.1 and 2.0 are audio channels.
I could only find {languages} which formats like [eng, hin, fre] and {channels}.
However in the https://www.filebot.net/naming.html I could not find ways to capitalize the first letter of the languages
and to add the audio channel inside the brackets [] and also to replace comma (,) with a hyphen (-).

Please guide me considering as a newbie.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to use pre-defined functions in {languages}

Post by rednoah »

:!: {languages} will give you the TheMovieDB Spoken Languages metadata field, and not audio stream languages.

:!: {channels} is just for the first audio stream, and can't be used to access all channels values for all audio streams.


e.g. Here's what you want:

Code: Select all

{
	[audio.collect{[
		it.LanguageString3.capitalize(), 
		it.ChannelPositionsString2.tokenize('/').take(2).join('.')
	]}*.join(' ').join(' - ')]
}

Code: Select all

[Eng 2.0 - Jpn 2.0]
:idea: viewtopic.php?t=4285
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: How to use pre-defined functions in {languages}

Post by kim »

This will fail and give output like this:
[Eng 3.2 - Eng 3.2 - Fra 3.2 - Ita 3.2 - Spa 3.2 - Dut 3.2]
so try this:

Code: Select all

{
	def codecList =
	[
	'MP3' : 'MP3',
	'PCM' : 'PCM',
	'AAC LC' : 'AAC',
	'AAC LC SBR' : 'AAC',
	'AC 3' : 'AC3',
	'AC 3 Dep' : 'EAC3',
	'E AC 3' : 'EAC3',
	'E AC 3 JOC' : 'EAC3 Atmos',
	'DTS' : 'DTS',
	'DTS 96 24' : 'DTS 96-24',
	'DTS ES' : 'DTS-ES',
	'DTS ES XXCH' : 'DTS-ES',
	'DTS XBR' : 'DTS-HD HRA',
	'DTS ES XBR' : 'DTS-HD HRA',
	'DTS ES XXCH XBR' : 'DTS-HD HRA',
	'DTS XLL' : 'DTS-HD MA',
	'DTS ES XLL' : 'DTS-HD MA',
	'DTS ES XXCH XLL' : 'DTS-HD MA',
	'DTS XLL X' : 'DTS X',
	'MLP FBA' : 'TrueHD',
	'MLP FBA 16 ch' : 'TrueHD Atmos'
	]
	def filter = { [it.lang, it.ch] }

	def audioStreams = []
	def audioClean = { it.replaceAll(/[\p{Pd}\p{Space}]/, ' ').replaceAll(/\p{Space}{2,}/, ' ').slash(' ') }
	def channelClean = { it.replaceAll(/Debug.+|Object\sBased\s?\/?|(\d+)?\sobjects\s\/\s|0.(?=\d.\d)|20/).replaceAll(/6.0/,'5.1').replaceAll(/8.0/,'7.1')}
	def oneStream = { it.collect{ filter(it) }*.minus(null).unique().flatten().join(' ') }
	def dString = { it.toDouble().toString() }
	def toInt = { it.toInteger() }

	audio.collect{ au ->
		def codec = audioClean(any{ au['CodecID/Hint'] }{ au['Format'] })
		def format_profile = any{ audioClean(au['Format_AdditionalFeatures'])}{}
		def String ch = any{ channelClean(au.ChannelPositionsString2).tokenize('\\/')*.toDouble().toString().sum() }
			{ channelClean(dString(au.ChannelsOriginal)) } { channelClean(dString(au.Channels)) }

		def chFilter =	(( ( (ac == 'AAC'||ac == 'MP3') && ch != '2.0') || ( (ac == 'AC3'||ac == 'EAC3'||ac == 'DTS'||ac == 'TrueHD'||ac == 'MLPFBA') && ch != '5.1' ) ) ? ch : null)

		def combined = allOf{codec}{format_profile}.join(' ')
		audioStreams << ['index' : codecList.findIndexOf {it.key == combined}, 'default' : au['default'][0].toBoolean(),
		'codec' : codecList.get(combined, 'UNKNOWN_FORMAT'), 'combined' : combined, 'ch' : ch, 
		'bitrate' : any{toInt(au.BitRate)}{toInt(au.BitRate_Maximum)}{au.FrameRate.toDouble()}{null},
		'objects' : any{'[' + au['NumberOfDynamicObjects'] + ' Objs]'}{null}, 'lang' : any{au.'LanguageString3'.upperInitial()}{null} ]
		return audioStreams
	}

	def allStreams = audioStreams.collect{ filter(it) }*.minus(null).unique()*.join(' ')
	allStreams.join(' - ')
}
viewtopic.php?f=5&t=5285
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: How to use pre-defined functions in {languages}

Post by rednoah »

Presumably, this is what the OP is asking for, capitalized 3-letter language code plus channel positions, for each audio stream, separated by dash, enclosed in brackets:

Code: Select all

[Eng 5.1 - Hin 5.1 - Fre 2.0]

Code: Select all

[Eng 2.0 - Jpn 2.0]

Code: Select all

[Eng 3.2 - Eng 3.2 - Fra 3.2 - Ita 3.2 - Spa 3.2 - Dut 3.2]
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: How to use pre-defined functions in {languages}

Post by kim »

The only thing you may want to change is:

Code: Select all

allStreams.join(' - ')
to

Code: Select all

allStreams.size() > 1 ? '[' + allStreams.join(' - ') + ']' : allStreams.join(' - ')
so only use brackets if 2+ audio streams
Post Reply