1
0
Fork 0
filebot-presets/old/Mangrana_Series_rename.groovy

360 lines
12 KiB
Groovy
Executable File

def server=true
def root = '/series/'
def rutaSeries = root+'NSeries/'
def ruta_docu = root+'Series_docu/'
def ruta_animacion = root+'Series_animacion/'
def ruta_anime = root+'Series_anime/'
def ruta_antiguas = root+'Series_antiguas/'
def ruta_esp = root+'Series_esp'
def ruta_teen = root+'Series_familiar'
def ruta_infantil = root+'Series_infantil'
def ruta_programastv = root+'programas_tv'
def rutaKO = root+'error/'
def ruta = rutaSeries
def ignorarAudioNoDef = true
/** Audio (definición) **/
def hayEAC3=false
def getAudiosFromListByFormat (format, listAudios) {
def result=[]
for (singleAudio in listAudios) {
if (singleAudio.Format==format) {
result.add(singleAudio)
if ("EAC3"==format) hayEAC3=true
}
}
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", "HE-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 = audio2Print.Language_String.replace("Catalan","Cat").replaceFirst(/(?i)(spanish|espa.ol)/,"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
}
/***********/
/* otras funciones */
def tieneGeneroAnimacion (generos) {
for (genero in generos) {
if (genero =~ /Anima[c|t]i\p{L}n/)
return true
}
return false
}
def tieneGeneroAnime (generos) {
for (genero in generos) {
if (genero =~ /Anime/)
return true
}
return false
}
def tieneGeneroFamilia (generos) {
for (genero in generos) {
if (genero =~ /Familia|Family/)
return true
}
return false
}
def tieneGeneroDocumental (generos) {
for (genero in generos) {
if (genero =~ /Documental|Documentary/)
return true
}
return false
}
def tieneGeneroReality (generos) {
for (genero in generos) {
if (genero =~ /Reality/)
return true
}
return false
}
def normalitzarText(txt) {
return txt.replaceAll(':','.').replaceAll('\\?','¿').replaceAll('\\"','-')
}
/**/
try { //empieza el script
try{
media
} catch (err) {throw new Exception("[no_media]")}
def theAudio
try{
theAudio = audio
} catch (err) {/*throw new Exception("[no_audio]")*/}
/** Audio (ejecución) **/
def catalanAudios=[]
def spanishAudios=[]
def englishAudios=[]
def otherAudios=[]
def audioDeclUndefined=false
def audiosFantasma=''
if (theAudio != null)
for (item in audio) {
def idioma
try {
idioma = item.Language_String
if (idioma==null) 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
audiosFantasma=' '+audiosFantasma+item.Title
} catch (ex) {throw new Exception("[idioma_audio_no_definido]")}
} else throw err
}
}
def audioNodef = false
if (!ignorarAudioNoDef) {
if (audioDeclUndefined || (catalanAudios.isEmpty() && spanishAudios.isEmpty() && englishAudios.isEmpty() && otherAudios.isEmpty()) ) {
audioNodef = false
throw new Exception("[idioma_audio_no_definido]")
}
}
if (!audioNodef) {
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
throw new Exception("[idioma_audio_solo_ingles]")
} else if (!otherAudios.isEmpty()) { //tenemos español
throw new Exception("[idioma_audio_marginal]")
} else if (!ignorarAudioNoDef) {
throw new Exception("[idioma_audio_no_encontrado]")
}
} else {
bloqueAudio = "NoDef"
}
/***********/
/** Codec Vídeo: en carpeta y en nombre fichero **/
def codecVideo = (vcf =~ /HEVC|265|ATEME/ ) ? 'HEVC' :
(vcf =~ /264/) ? 'AVC' : vcf
/**************/
/** Formato distribución **/
formato_distribucion =
fn=~/(?i)\bblu.?ray\b/ ? 'BDRip' :
fn=~/(?i)\bBDrip\b/ ? 'BDRip' :
fn=~/(?i)\bDVD.?RIP\b/ ? 'DVDRip' :
fn=~/(?i)\bHDiTunes\b/ ? 'HDiTunes' :
fn=~/(?i)\bTV.?RIP\b/ ? 'TVRip' :
fn=~/(?i)\bahdtv\b/ ? 'AHDTV' :
fn=~/(?i)\bWEB.?Screener\b/ ? 'WEB-SRC' :
'no_encontrado'
def esWEB_DL=false
if (formato_distribucion=='no_encontrado') {
esWEB_DL = fn=~/(?i)\bWEB.??(D.?|RIP)\b/ //WEB-DL o WEB-RIP (todo junto o con punto/guión/etc)
if (esWEB_DL) {
def web_x = fn=~/(?i)\bWEB.?D.?\b/ ? 'WEB-DL' : 'WEB-RIP' //guardar el que es
def plataforma = fn.find( //coge el contenido que encaja
/(?i)\bSATRIP\b|\bDVB\b|\bFLXL\b|\bAMZN?\b|\bAMNZ?\b|\bNF\b|\bHBO\b|\bHBO.?MAX\b|\bHMAX\b|\bHULU\b|\bA3P\b|\bDPLY\b|\bSTARZ\b|\bFILMIN\b|\bFLMN\b|\bNETFLIX\b|\bDSN.?\b|\bDSP\+?\b|\bDNSP\b|\bMVPLUS\b|\bM\+\b|\bAPTV\b|\bAMC\b/ )
if (plataforma!=null) plataforma = plataforma.replace("MVPLUS","MV+").replace("AMNZ", "AMZN").replace("DSNY", "DSN").replace("DSNP", "DSN")
formato_distribucion = web_x+(plataforma!=null?(' '+plataforma.toUpperCase()):'') //web-dl/rip + plataforma(si hay)
} else {
if (hayEAC3) //por el audio también se determina que es web-dl
formato_distribucion = 'WEB-DL'
else {
def otrosFD = fn.find( /(?i)\bMTL\b |\bMUBI\b/ )
if (otrosFD!= null && !otrosFD.isEmpty())
formato_distribucion = otrosFD.toUpperCase() //si son estos, se setea
}
}
}
if (formato_distribucion=='no_encontrado') formato_distribucion='';
if (formato_distribucion!='') formato_distribucion=' '+formato_distribucion
/*****************************/
/**** Profundidad de color */
def profundidadColor=''
try{profundidadColor = bitdepth+"bits " } catch(err){}
/**************************/
/**** Profundidad vídeo ****/
def myBitrate = 'noBRdef'
try{ myBitrate = (mbps).replace(/.0/,'') }catch(err){}
//if (bitrate >= 10000000) throw new Exception("[bitrate_demasiado_alto]")
def numericBR = mbps.toString().before(' ').toDouble()
def infoBitrate = numericBR < 11 ? myBitrate
: numericBR < 15 ? myBitrate+' (BITRATE_S)'
: numericBR < 20 ? myBitrate+' (BITRATE_M)'
: numericBR < 25 ? myBitrate+' (BITRATE_L)'
: myBitrate+' (BITRATE_XL)'
def myFps = ' FRvar'
try { myFps = ' '+fps.replace(/.0/,'') }catch(err){}
/************ ***************/
/**************************************/
/**** Carpeta / tipo contenido *******/
def generes
def errorNoGenero=false
try {generes=genres} catch (err) {errorNoGenero=true}
def certificacio
try {certificacio=certification} catch (err) {}
def esDocu = tieneGeneroDocumental(generes)
def esAnime = anime || tieneGeneroAnime(generes)
def esAnimacion = tieneGeneroAnimacion(generes)
def esTeen = tieneGeneroFamilia(generes) && (certificacio==null || certificacio =~ /TV-14|TV-P?G/)
//return certificacio + " - " + generes + " - so: " + esTeen
def esInfantil = esAnimacion && certificacio =~ /TV-Y|TV-Y7|TV-P?G/
def esReality = tieneGeneroReality(generes)
//esp?
def esEsp=false
def spanishNetwork
try{ spanishNetwork = info.Network.find(/(?i)\bTVE\b|\bmovistar\b|\bAtresmedia\b|\bcanal 9\b|\bPlayz\b|\bATRES\b|\bETB1\b|\bTV3\b|\btelecinco\b|\bcanal+\b|\bgalicia\b|\bfox españa\b|\blasexta\b|\bantena 3\b/ )} catch(e){}
if (spanishNetwork!=null) esEsp=true
//tria
/*if (tenimCat) ruta = ruta_cat
else */if (esDocu) ruta = ruta_docu
else if (esReality) ruta = ruta_programastv
else if (esAnime) ruta = ruta_anime
else if (esInfantil) ruta = ruta_infantil
else if (esAnimacion) ruta = ruta_animacion
else if (esEsp) ruta = ruta_esp
else if (y < 1990) ruta = ruta_antiguas
else if (esTeen) ruta = ruta_teen
/****************************************/
/****************************************/
/****************************/
/**** Nombre de fichero *******/
def cuaTvdb = " {tvdb-"+id+"}"
def pathNombreSerie = '/' + normalitzarText(localize.English.ny) + cuaTvdb + '/'
def temporada = episode.special ?
'Specials'+'/' :
'Temporada '+ s.pad(2) + '/'
def volemInicials = false
def nomIngles = localize.English.n
def titol=''
def ini0 = nomIngles[0].toUpperCase()
def ini1 = nomIngles[1].toUpperCase()
def iniClear = ini0.replaceAll(/[¡¿'#*\(]/,ini1)
def inicial = volemInicials ? ruta==rutaSeries ? iniClear.replaceAll(/[0-9]/,'0-9') + '/' : '' : ''
try {
def titolCapitol = normalitzarText(localize.Spanish.t)
titol = ' - ' + titolCapitol
} catch (err) { /*nada*/ }
def nombreSerie = normalitzarText(localize.Spanish.ny)
def nombreArchivo = nombreSerie + ' - ' + s00e00 + titol
def resolucion = ['480p', '576p', '360p', '240p'].contains(vf) ? 'SD' //SD
: (vf == '2160p') ? //4K
'4K'
: //1080 o 720
vf
def tracker = fn.find(/(?i)\bHDO(limpo)?\b|\bredbits\b/)
def cuaTracker = tracker != null ? ' ['+tracker.replace("HDOlimpo", "HDO")+']' : ''
/****************************/
/**** RUTA FINAL *******/
def resultado = ruta + inicial + pathNombreSerie + temporada + nombreArchivo + ' [' + codecVideo +' '+ resolucion + formato_distribucion+']['+profundidadColor+infoBitrate+myFps+']'+' ['+bloqueAudio+']' + cuaTracker
return resultado
} catch (err) {
//throw err
String str= err.getStackTrace().toString()
def pattern = ( str =~ /groovy.(\d+)./ )
return " Error at line number = " + pattern[0][1]
def rutaMotivoErr
def msgErr = err.getMessage()
if (msgErr=="[formato_fichero_noestarndar]" || msgErr=="[video_roto]" || msgErr=="[no_media]")
rutaMotivoErr="/fichero/"
else if (msgErr=="[genero_no_especificado]" || msgErr=="[certificado_edad_no_especificado]") {
rutaMotivoErr="/themoviedb/"
} else if (msgErr.startsWith("[idioma_audio")) {
rutaMotivoErr="/audio/"
} else if (msgErr.startsWith("[bitrate_demasiado_alto]")) {
rutaMotivoErr="/bitrate/"
} else {
def errSplitted = msgErr.split("\\-")
if (errSplitted==null) {
rutaMotivoErr="/error_desconocido/"
} else {
return msgErr
def errType = errSplitted[0]
if (errType=="[formato_audio_no_encontrado")
rutaMotivoErr="/audio/"
else if (errType.startsWith("[idioma_audio"))
rutaMotivoErr="/idioma/"
else {
rutaMotivoErr="/error_desconocido/"
msgErr = "[error_inesperado]"
}
}
}
def cuaTvdb = " {tvdb-"+id+"}"
def pathNombreSerieErr = '/' + normalitzarText(localize.English.ny) + cuaTvdb + '/'
def resultado = rutaKO + rutaMotivoErr + msgErr + '/' + pathNombreSerieErr + fn
return resultado
}