1
0
Fork 0
filebot-presets/docker/MaNGranA_Pelis_Organizer.gr...

277 lines
8.8 KiB
Groovy
Executable File

//by @xeviff
/** RUTAS **/
def inicialsActivades=true
def root = '/pelis/'
def rutaOK = root+"Pelis/plain/"
def ruta = rutaOK
def ruta_docu = root+"Documentales/plain/"
def ruta_anime = root+"Pelis_anime/plain/"
def ruta_animacion = root+"Pelis_animacion/"
def ruta_infantil = root+"Pelis_infantiles/"
def ruta_esp = root+"Pelis_esp/plain/"
def ruta_semiesp = root+"Pelis_esp/posible_esp/"
def ruta_retro = root+"Pelis_retro/plain/"
def ruta_estrenos = root+"Pelis_estrenos/plain/"
def ruta_classic = root+"Pelis_classic/"
def ruta_asiaticas = root+"Pelis_asiaticas/"
def rutaKO = root+"error/"
/**********/
/* otras funciones */
def tieneGeneroAnimacion (generos) {
for (genero in generos) {
if (genero =~ /Anima[c|t]i\p{L}n/)
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 esDocumental (generos, title) {
def noJackass = !(title =~ /Jackass/)
return tieneGeneroDocumental(generos) && noJackass
}
/**/
def getInicial () {
def nomIngles = localize.English.n
if (nomIngles.startsWith("The ") || nomIngles.startsWith("A "))
nomIngles = nomIngles.replaceFirst("The ",'').replaceFirst("A ",'')
def ini0 = nomIngles[0].toUpperCase()
def ini1 = nomIngles[1].toUpperCase()
def iniClear = ini0.replaceAll(/[¡¿'#*\(]/,ini1)
def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/'
return inicial
}
try { //empieza el script
if (ext!="mkv" && ext!="avi" && ext!="mp4") {
throw new Exception("[formato_fichero_noestarndar]")
}
try {
video
} catch (e) {
throw new Exception("[video_roto]")
}
/********************************/
/** 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) 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 throw err
}
}
if (audioDeclUndefined || (catalanAudios.isEmpty() && spanishAudios.isEmpty() && englishAudios.isEmpty() && otherAudios.isEmpty()) ) {
throw new Exception("[idioma_audio_no_definido]")
}
def tenimCat=false
if (!catalanAudios.isEmpty()) { //tenim català
tenimCat=true
def tenimEsp = !spanishAudios.isEmpty()
} else if (!spanishAudios.isEmpty()) { //tenemos español
} else if (!englishAudios.isEmpty()) {
throw new Exception("[idioma_audio_solo_ingles]")
} else if (!otherAudios.isEmpty()) {
throw new Exception("[idioma_audio_marginal]")
} else {
throw new Exception("[idioma_audio_no_encontrado]")
}
/***********/
/**************************************/
/**** Carpeta / tipo contenido *******/
def generes
def errorNoGenero=false
try {generes=genres} catch (err) {errorNoGenero=true}
def esDocu = esDocumental(generes, localize.English.n)
def esAnime = anime || (tieneGeneroAnimacion(generes) && info.ProductionCountries.contains("JP"))
if (esAnime) {
def noAnimeListEx = [351460]
if (noAnimeListEx.contains(tmdbid)) esAnime=false
}
def esAnimacion = tieneGeneroAnimacion(generes)
if (esAnimacion) {
def noAnimacionListEx = [554377, 708962, 35114]
if (noAnimacionListEx.contains(tmdbid)) esAnimacion=false
}
//infantil
def infantil=false
def famyListEx = [575100]
def noFamyListEx = [10637, 6639, 336121, 248688]
if (famyListEx.contains(tmdbid)) infantil=true
else if (noFamyListEx.contains(tmdbid)) infantil=false
else {
if (tieneGeneroFamilia(generes)) {
infantil=true
if (y<1980 && !esAnimacion) infantil=false
} else {
def certificacio
try {certificacio=certification} catch (err) {
certificacio = info.certifications.ES
if (certificacio==null)
certificacio = info.certifications.DE
}
if (certificacio!=null) {
def familyCert = ['A', 'PG.7', 'G', 'APTA', 'TP']
if (familyCert.contains(certificacio))
infantil=true
}
def certsMap = info.certifications
if (certsMap.size()>0) {
def noNens=false
certsMap.each { key, val ->
def num = val.findAll( /\d+/ )*.toInteger()
if (num!=null && num[0]!=null) {
try{
if (num[0]<8 && num[0]>1) {
infantil=true
} else if (num[0]>8) {
noNens=true
}
}catch (err) {}
}
}
if (infantil && noNens) infantil=false
}
}
}
//excepcions espanyoles
def semiEsp
def probablEsp = info.ProductionCountries.contains("ES")
if (probablEsp && info.ProductionCountries.contains("US")) probablEsp=false
def espanyola = probablEsp && info.ProductionCountries.size()==1
if (probablEsp && info.ProductionCountries.size()>1) semiEsp = true
def espListEx = [401545, 584427, 589203, 655187, 441614, 517327, 516856, 351097, 267579, 573150, 437036, 56812, 11429, 127864, 510318, 209251, 443585, 33273, 8881, 351809, 499547, 351145, 684471]
def noEspListEx = [290859, 1562, 530915, 329718, 248842, 353979, 34186, 2395, 735129, 421792, 335984, 591789, 429, 26388, 18898, 266396, 85872, 352161, 43020, 339967, 446696, 38031]
if (noEspListEx.contains(tmdbid)) {
semiEsp=false
espanyola=false
} else if (espListEx.contains(tmdbid)) espanyola=true
//asiaticas
def asiatica = false
if (info.ProductionCountries.size()>0) {
def paisesAsiaticos = ["CN", "HK", "JP", "KP", "KR", "TH", "NP", "TW", "PH"]
def matchP = paisesAsiaticos.intersect(info.ProductionCountries)
if (matchP.size()==info.ProductionCountries.size()) asiatica=true
}
//tria
if (esDocu) ruta = ruta_docu
else if (espanyola) ruta = ruta_esp
else if (semiEsp) ruta = ruta_semiesp
else if (esAnime) ruta = ruta_anime
else if (infantil) ruta = ruta_infantil
else if (esAnimacion) ruta = ruta_animacion
else if (asiatica) ruta = ruta_asiaticas
else if (y<1980) ruta = ruta_classic
else if (y<2000) ruta = ruta_retro
if (ruta==rutaOK && y>=2021) ruta = ruta_estrenos
/********************************************/
/**************************************/
if (errorNoGenero && !tenimCat && ruta!=ruta_classic && ruta!=ruta_retro && !espanyola && !semiEsp && !infantil && ruta!=ruta_esp_retro && ruta!=ruta_esp_classic && ruta!=ruta_estrenos )
throw new Exception("[genero_no_especificado]")
/*** RESULTADO FINAL ***/
def inicial=''
def inicialsRequerides = ruta==rutaOK || ruta==ruta_retro || ruta==ruta_infantil
if (inicialsActivades && inicialsRequerides) {
inicial = getInicial()
}
def tracker = fn.find(/(?i)\bHDO(limpo)?\b/)
def extras = tracker != null ? ' ['+tracker.replace("HDOlimpo", "HDO")+']' : ''
def resultado = ruta + //directorios
//nombre fichero
inicial +
localize.English.plex.name + '/' + fn
return resultado
} catch (err) {
/*
String str= err.getStackTrace().toString()
def pattern = ( str =~ /groovy.(\d+)./ )
return " Error at line number = " + pattern[0][1] + ". more: "+str
*/
def rutaMotivoErr
def msgErr = err.getMessage()
if (msgErr=="[formato_fichero_noestarndar]" || msgErr=="[video_roto]")
rutaMotivoErr="/fichero/"
else if (msgErr=="[genero_no_especificado]" || msgErr=="[certificado_edad_no_especificado]") {
rutaMotivoErr="/themoviedb/"
} else if (msgErr.startsWith("[idioma_audio")) {
rutaMotivoErr="/audio/"
} else {
def errSplitted = msgErr.split("\\-")
return msgErr
if (errSplitted==null) {
rutaMotivoErr="/error_desconocido/"
} else {
def errType = errSplitted[0]
if (errType=="[formato_audio_no_encontrado")
rutaMotivoErr="/audio/"
else if (errType.startsWith("[idioma_audio"))
rutaMotivoErr="/idioma/"
else {
String str2= err.getStackTrace().toString()
def pattern2 = ( str2 =~ /groovy.(\d+)./ )
return " Error at line number = " + pattern2[0][1]
}
}
}
def resultado = rutaKO + rutaMotivoErr + msgErr + '/' + fn
return resultado
}