Page 1 of 1
Need to make an exception when there are 2 or more spanish audio tracks
Posted: 18 Jul 2022, 23:52
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.
Re: Need to make an exception when there are 2 or more spanish audio tracks
Posted: 19 Jul 2022, 10:06
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')
}
Re: Need to make an exception when there are 2 or more spanish audio tracks
Posted: 20 Jul 2022, 15:18
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?
Re: Need to make an exception when there are 2 or more spanish audio tracks
Posted: 20 Jul 2022, 15:32
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 -"
Re: Need to make an exception when there are 2 or more spanish audio tracks
Posted: 20 Jul 2022, 20:22
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.
Re: Need to make an exception when there are 2 or more spanish audio tracks
Posted: 21 Jul 2022, 11:03
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(' ')
}

Set
a to sample values for testing:
Code: Select all
def a = ['en', 'en', 'en', 'es', 'es', 'es']

Set
a to real values via
MediaInfo Bindings from the file at hand:
Re: Need to make an exception when there are 2 or more spanish audio tracks
Posted: 21 Jul 2022, 19:32
by carloscape
That worked, thanks.