187 lines
6.2 KiB
Groovy
Executable File
187 lines
6.2 KiB
Groovy
Executable File
|
|
def getAudiosFromListByFormat (format, listAudios) {
|
|
def result=[]
|
|
for (singleAudio in listAudios) {
|
|
if (singleAudio.Format==format) {
|
|
result.add(singleAudio)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
def getBestChannelFromList (audiosFormatFound) {
|
|
def bestChanel
|
|
def currentValue=0
|
|
for (myAudio2 in audiosFormatFound) {
|
|
if (myAudio2.Channels>currentValue) {
|
|
currentValue = myAudio2.Channels
|
|
bestChanel = myAudio2
|
|
}
|
|
}
|
|
return bestChanel
|
|
}
|
|
def getMaxQuality (listOfLanguageAudio) {
|
|
def formatSet = ["PCM", "MLP FBA" ,"DTS", "FLAC", "AC-3", "E-AC-3", "EAC3", "AAC", "MPEG Audio", "MP3"]
|
|
for (cFormat in formatSet) {
|
|
def audiosFormatFound = getAudiosFromListByFormat(cFormat, listOfLanguageAudio);
|
|
if (!audiosFormatFound.isEmpty()) {
|
|
return getBestChannelFromList(audiosFormatFound)
|
|
}
|
|
}
|
|
//no debería llegar aquí, si lo hace hay que documentar el problema indicando el/los formato/s no encontrado/s
|
|
def formatosInvolucradosProblema='[formato_audio_no_encontrado-'
|
|
for (audioFormatNotFound in listOfLanguageAudio) {
|
|
formatosInvolucradosProblema = formatosInvolucradosProblema+' '+audioFormatNotFound.Format
|
|
}
|
|
formatosInvolucradosProblema=formatosInvolucradosProblema+']'
|
|
throw new Exception(formatosInvolucradosProblema)
|
|
}
|
|
|
|
def bloqueAudio
|
|
def printAudio (audio2Print) {
|
|
def idioma
|
|
def idiomaOrigin = audio2Print.Language_String
|
|
if (idiomaOrigin==null) {
|
|
idiomaOrigin = audio2Print.Title
|
|
if (idiomaOrigin =~ /(?i)\bcat\b/)
|
|
idioma = "Cat"
|
|
else if (idiomaOrigin =~ /(?i)\bcast\b|\bspa\b/)
|
|
idioma = "Es"
|
|
} else {
|
|
idioma = idiomaOrigin.replace("Catalan","Cat").replace("Espanol / Espanol", "Es").replaceFirst(/(?i)(spanish|espa.ol)/,"Es").replace("(ES)","")
|
|
}
|
|
def formato_audio = audio2Print.Format_Commercial.replace("Dolby Digital":"Dolby").replace(" Plus","+")
|
|
.replace("DTS-HD Master Audio","DTS-MA").replace("DTS-HD High Resolution Audio","DTS-HD-H")
|
|
.replace("MPEG Audio","MPEG").replace("HE-AAC","AAC+")
|
|
.replace(" with Dolby Atmos", "Atmos")
|
|
def canales = audio2Print.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1')
|
|
return idioma + ' ' + formato_audio + ' ' + canales
|
|
}
|
|
|
|
|
|
/** Audio (ejecución) **/
|
|
def catalanAudios=[]
|
|
def spanishAudios=[]
|
|
def englishAudios=[]
|
|
def otherAudios=[]
|
|
def audioDeclUndefined=false
|
|
for (item in audio) {
|
|
def idioma
|
|
try {
|
|
idioma = item.Language_String
|
|
if (idioma==null) otherAudios.add("audio_no_def") //throw new Exception("[idioma_audio_no_definido0]")
|
|
if ("Catalan"==idioma) catalanAudios.add(item)
|
|
else if (idioma=~/(?i)(Spanish|Espa.ol)/) spanishAudios.add(item)
|
|
else if ("English"==idioma) englishAudios.add(item)
|
|
else if ("Undefined"==idioma) audioDeclUndefined=true
|
|
else otherAudios.add(item)
|
|
} catch (err) {
|
|
if (idioma==null) {
|
|
try { //si tampoco tiene item.Title
|
|
def audioTitle=item.Title
|
|
if (audioTitle!=null) {
|
|
if (any{audioTitle}{0} =~ /(?i)\bcat\b/)
|
|
catalanAudios.add(item)
|
|
else if (any{audioTitle}{0} =~ /(?i)\bcast\b|\bspa\b/)
|
|
spanishAudios.add(item)
|
|
else if (any{audioTitle}{0} =~ /(?i)\bingl.es\b|\beng\b/)
|
|
englishAudios.add(item)
|
|
else otherAudios.add(item)
|
|
}
|
|
} catch (ex) {}
|
|
} else if (!skipAudioCheck) throw err
|
|
}
|
|
}
|
|
|
|
if (audioDeclUndefined || (catalanAudios.isEmpty() && spanishAudios.isEmpty() && englishAudios.isEmpty() && otherAudios.isEmpty()) ) {
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_no_definido]")
|
|
}
|
|
def tenimCat=false
|
|
if (!catalanAudios.isEmpty()) { //tenim català
|
|
tenimCat=true
|
|
def maxCat = getMaxQuality(catalanAudios)
|
|
def blocCat = printAudio(maxCat)
|
|
def tenimEsp = !spanishAudios.isEmpty()
|
|
def blocEsp=''
|
|
if (tenimEsp) {
|
|
def maxEsp = getMaxQuality(spanishAudios)
|
|
blocEsp = ', '+printAudio(maxEsp)
|
|
}
|
|
bloqueAudio = blocCat + blocEsp
|
|
} else if (!spanishAudios.isEmpty()) { //tenemos español
|
|
def maxEsp = getMaxQuality(spanishAudios)
|
|
bloqueAudio = printAudio(maxEsp)
|
|
} else if (!englishAudios.isEmpty()) { //tenemos español
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_solo_ingles]")
|
|
} else if (!otherAudios.isEmpty()) { //tenemos español
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_marginal]")
|
|
} else {
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_no_encontrado]")
|
|
}
|
|
if (bloqueAudio==null) bloqueAudio = "[audio_no_def]"
|
|
else bloqueAudio = ' ['+bloqueAudio+']'
|
|
/***********/
|
|
/*********************************************************/
|
|
|
|
|
|
def bloqueAudio2=''
|
|
def audiosMap = [:]
|
|
for (aud in audio) {
|
|
def shortDesc = aud.Language_String3
|
|
if (audiosMap.containsKey(shortDesc)) audiosMap[shortDesc].add(aud)
|
|
else audiosMap[shortDesc] = [aud]
|
|
}
|
|
|
|
for (audioElms in audiosMap) {
|
|
def k = audioElms.key
|
|
def v = audioElms.value
|
|
def s = v.size()
|
|
def mQ = getMaxQuality2(v)
|
|
if (s>1) k = k+'('+s+')'
|
|
bloqueAudio2 += k+' '+printAudio2(mQ)+', '
|
|
}
|
|
|
|
/***********/
|
|
def getMaxQuality2 (listOfLanguageAudio) {
|
|
def formatSet = ["PCM", "MLP FBA" ,"DTS", "FLAC", "AC-3", "E-AC-3", "EAC3", "AAC", "MPEG Audio", "MP3"]
|
|
for (cFormat in formatSet) {
|
|
def audiosFormatFound = getAudiosFromListByFormat2(cFormat, listOfLanguageAudio);
|
|
if (!audiosFormatFound.isEmpty()) {
|
|
return getBestChannelFromList2(audiosFormatFound)
|
|
}
|
|
}
|
|
}
|
|
|
|
def printAudio2 (audio2Print) {
|
|
def formato_audio = audio2Print.Format_Commercial.replace("Dolby Digital":"Dolby").replace(" Plus","+")
|
|
.replace("DTS-HD Master Audio","DTS-MA").replace("DTS-HD High Resolution Audio","DTS-HD-H")
|
|
.replace("MPEG Audio","MPEG").replace("HE-AAC","AAC+")
|
|
.replace(" with Dolby Atmos", "Atmos").replace("TrueHD", "HD")
|
|
def canales = audio2Print.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1')
|
|
return formato_audio + ' ' + canales
|
|
}
|
|
|
|
|
|
def getAudiosFromListByFormat2 (format, listAudios) {
|
|
def result=[]
|
|
for (singleAudio in listAudios) {
|
|
if (singleAudio.Format==format) {
|
|
result.add(singleAudio)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
def getBestChannelFromList2 (audiosFormatFound) {
|
|
def bestChanel
|
|
def currentValue=0
|
|
for (myAudio2 in audiosFormatFound) {
|
|
if (myAudio2.Channels>currentValue) {
|
|
currentValue = myAudio2.Channels
|
|
bestChanel = myAudio2
|
|
}
|
|
}
|
|
return bestChanel
|
|
}
|
|
|
|
|
|
|
|
return bloqueAudio + ' vs [' + bloqueAudio2.substring(0,bloqueAudio2.size()-2) + ']' |