Need to make an exception when there are 2 or more spanish audio tracks

All about user-defined episode / movie / file name format expressions
Post Reply
carloscape
Posts: 9
Joined: 03 Jul 2020, 06:28

Need to make an exception when there are 2 or more spanish audio tracks

Post by carloscape »

This works quite well for simple cases:

Code: Select all

{def x = audio.language.findResults{ it.toLocale() }.unique().join(' '); x.replaceAll('es', 'es-419');  if (x) "audio $x"}
It will basically show a language once, and presents the Spanish audio (when available) as es-419 (stands for Spanish Latin america).

However, I would like for an exception to be made in case 2 or more Spanish audio tracks exist, so that it would add es-es (stands for Spanish Spain) along with es-419
so the sample output would be something like: es-419 es-es en (not necessarily in that order).

I was considering the creation of a variable that could detect that case, so that it could serve as a condition to use x.replaceAll('es', 'es-419') or x.replaceAll('es', 'es-419 es-es');
That's where I'm stuck. I welcome any suggestions.
User avatar
rednoah
The Source
Posts: 22899
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need to make an exception when there are 2 or more spanish audio tracks

Post by rednoah »

e.g. if there's one "es" then we replace that with "es-419", and if there's two or more "es" then we replace only the first one with "es-419"

Code: Select all

{ 
	audioLanguages.ISO2.join(' ').replaceFirst('es', 'es-419')
}

Test Case:

Code: Select all

// es-419 es
{ 
	['es', 'es'].join(' ').replaceFirst('es', 'es-419')
}
:idea: Please read the FAQ and How to Request Help.
carloscape
Posts: 9
Joined: 03 Jul 2020, 06:28

Re: Need to make an exception when there are 2 or more spanish audio tracks

Post by carloscape »

That wouldn't work, because I wouldn't be able to use unique. So I could get results like en en en en en en es-419 es es es. Also, I would like the second es to become es-es. Is there a replaceSecond? Would it work if I added unique?
User avatar
rednoah
The Source
Posts: 22899
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need to make an exception when there are 2 or more spanish audio tracks

Post by rednoah »

e.g.

Code: Select all

{
	// en es-419 es-es
	def a = ['en', 'en', 'en', 'es', 'es', 'es']
	a.join(' ').replaceFirst(/es/, 'es-419').replaceAll(/es(?![-])/, 'es-es').tokenize(' ').unique().join(' ')
}
/es(?![-])/ ... regex for "es not followed by -"
:idea: Please read the FAQ and How to Request Help.
carloscape
Posts: 9
Joined: 03 Jul 2020, 06:28

Re: Need to make an exception when there are 2 or more spanish audio tracks

Post by carloscape »

Not sure how to apply that solution, to an existing movie file. I added that line to replace the one I had (with replace changing a to x) and it didn't seem to work.

Code: Select all

{n}{def x = audio.language.findResults{ it.toLocale() }.join(' '); x.join(' ').replaceFirst(/es/, 'es-419').replaceAll(/es(?![-])/, 'es-es').tokenize(' ').unique().join(' '); if (x) "audio $x"}
Thank you for your help.
User avatar
rednoah
The Source
Posts: 22899
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need to make an exception when there are 2 or more spanish audio tracks

Post by rednoah »

Append this at the end of your custom format:

Code: Select all

{
	// en es-419 es-es
	def a = audio.language
	a.join(' ').replaceFirst(/es/, 'es-419').replaceAll(/es(?![-])/, 'es-es').tokenize(' ').unique().join(' ')
}


:idea: Set a to sample values for testing:

Code: Select all

def a = ['en', 'en', 'en', 'es', 'es', 'es']
:idea: Set a to real values via MediaInfo Bindings from the file at hand:

Code: Select all

def a = audio.language
:idea: Please read the FAQ and How to Request Help.
carloscape
Posts: 9
Joined: 03 Jul 2020, 06:28

Re: Need to make an exception when there are 2 or more spanish audio tracks

Post by carloscape »

That worked, thanks.
Post Reply