292 lines
9.5 KiB
Groovy
Executable File
292 lines
9.5 KiB
Groovy
Executable File
//by @xeviff
|
||
/** RUTAS **/
|
||
def ubuntu_desktop=true
|
||
|
||
def root = ubuntu_desktop ? '/mnt/mangrana_pelis/' : '/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_familiar = root+"Pelis_familiar/"
|
||
def ruta_esp = root+"Pelis_esp/plain/"
|
||
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/"
|
||
/**********/
|
||
|
||
/* HARDCODED */
|
||
def skipAudioCheck = true
|
||
def infantilHardCoded = false
|
||
|
||
/* 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 tieneGeneroReality (generos) {
|
||
for (genero in generos) {
|
||
if (genero =~ /Reality/)
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
def esDocumental (generos, title) {
|
||
def noJackass = !(title =~ /Jackass/)
|
||
return (tieneGeneroDocumental(generos) || tieneGeneroReality(generos)) && noJackass
|
||
}
|
||
def fromEspPlatform () {
|
||
return fn.find(/(?i)\bFLIXOL.\b|\bRTVE\b/) != null
|
||
}
|
||
/**/
|
||
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 iniClear = nomIngles.size()>1 ? ini0.replaceAll(/[¡¿'#*\(]/,nomIngles[1].toUpperCase()) : ini0
|
||
def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/'
|
||
return inicial
|
||
}
|
||
def sanityCheck() {
|
||
def clearCurrentName = fn.replaceAll(/\s|-|:|∶|\./,'')
|
||
def clearPlexName = plex.name.replaceAll(/\s|-|:|∶|\./,'')
|
||
if (clearCurrentName.substring(0, clearCurrentName.size()-6)!=clearPlexName.substring(0, clearPlexName.size()-6))
|
||
return false
|
||
def yearOldName = clearCurrentName.substring(clearCurrentName.size()-5, clearCurrentName.size()-1) as int
|
||
def yearNewName = clearPlexName.substring(clearPlexName.size()-5, clearPlexName.size()-1) as int
|
||
return Math.abs(yearOldName - yearNewName) < 2
|
||
}
|
||
//*****************************************************************************************/
|
||
//*****************************************************************************************/
|
||
//*****************************************************************************************/
|
||
try { //empieza el script
|
||
|
||
//sanity check
|
||
if (!sanityCheck()) return '@@@@@@ Names Sanity Check KO @@@@@@@ --> New name: '+plex.name
|
||
|
||
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) otherAudios.add("audio_no_def")
|
||
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 tenimEsp = !spanishAudios.isEmpty()
|
||
} else if (!spanishAudios.isEmpty()) { //tenemos español
|
||
|
||
} else if (!englishAudios.isEmpty()) {
|
||
if (!skipAudioCheck) throw new Exception("[idioma_audio_solo_ingles]")
|
||
} else if (!otherAudios.isEmpty()) {
|
||
if (!skipAudioCheck) throw new Exception("[idioma_audio_marginal]")
|
||
} else {
|
||
if (!skipAudioCheck) throw new Exception("[idioma_audio_no_encontrado]")
|
||
}
|
||
/***********/
|
||
|
||
|
||
/**************************************/
|
||
/**** Carpeta / tipo contenido *******/
|
||
def generes
|
||
def errorNoGenero=false
|
||
try {generes=genres} catch (err) {errorNoGenero=true}
|
||
|
||
def tieneAnimacion = tieneGeneroAnimacion(generes)
|
||
def tieneFamiliar = tieneGeneroFamilia(generes)
|
||
|
||
def esDocu = esDocumental(generes, localize.English.n)
|
||
def esAnime = false
|
||
if (tieneAnimacion && info.ProductionCountries.contains("JP")) {
|
||
esAnime = info.ProductionCountries.size()==1 || anime
|
||
}
|
||
|
||
//***** familiar vs infantil ****
|
||
def esFamiliar = tieneFamiliar
|
||
def infantil = false
|
||
|
||
def tipoYaSeteado=esDocu || esAnime
|
||
if (!tipoYaSeteado) {
|
||
|
||
def tieneCertificacion = info.Certifications!=null && info.Certifications.size()!=0
|
||
|
||
if (tieneFamiliar && tieneAnimacion) {
|
||
def noTanInfantil = info.Certifications.US ==~/PG-13/
|
||
if (!noTanInfantil)
|
||
infantil = true
|
||
}
|
||
else if (tieneAnimacion) {
|
||
if (tieneCertificacion) {
|
||
if ( info.Certifications.US=="G"
|
||
|| info.Certifications.ES==~/Ai|APTA/
|
||
|| info.Certifications.DE==~/0|6/
|
||
|| info.Certifications.IT=="T"
|
||
|| info.Certifications.LT=="V" || info.Certifications.RU ==~ /6.+/
|
||
|| info.Certifications.BR=="L"
|
||
)
|
||
infantil=true
|
||
} else {
|
||
def titulosInfantiles = ['Bonnie bears', 'The Jungle Bunch']
|
||
if (titulosInfantiles.any { localize.English.n.toLowerCase()contains(it.toLowerCase()) })
|
||
infantil = true
|
||
}
|
||
} else if (!esFamiliar) {
|
||
if (tieneCertificacion && (
|
||
info.Certifications.US=="G"
|
||
)) {
|
||
esFamiliar = true //posem a familiar pelis de nens que no son animacio
|
||
}
|
||
}
|
||
}
|
||
|
||
//espanyoles & asiaticas
|
||
def espanyola = false
|
||
def asiatica = false
|
||
tipoYaSeteado=esDocu || esAnime || esFamiliar || infantil
|
||
if (!tipoYaSeteado) {
|
||
|
||
def segurEsp = info.ProductionCountries.contains("ES") && info.ProductionCountries.size()==1
|
||
espanyola = fromEspPlatform() || segurEsp
|
||
|
||
//asiaticas
|
||
if (!espanyola && info.ProductionCountries.size()>0) {
|
||
def paisesAsiaticos = ["CN", "HK", "JP", "KP", "KR", "TH", "NP", "TW", "PH", "MO"]
|
||
def matchP = paisesAsiaticos.intersect(info.ProductionCountries)
|
||
def allAsian = matchP.size()==info.ProductionCountries.size()
|
||
def probableAsian = matchP.size()>0 && englishAudios.isEmpty() && audio.size()>1
|
||
if (allAsian || probableAsian/*en obseracion*/) asiatica=true
|
||
}
|
||
}
|
||
|
||
//tria
|
||
if (esDocu) ruta = ruta_docu
|
||
else if (esAnime) ruta = ruta_anime
|
||
else if (infantil) ruta = ruta_infantil
|
||
else if (esFamiliar) ruta = ruta_familiar
|
||
else if (tieneAnimacion) ruta = ruta_animacion
|
||
else if (asiatica) ruta = ruta_asiaticas
|
||
else if (espanyola) ruta = ruta_esp
|
||
else if (y<1980) ruta = ruta_classic
|
||
else if (y<2000) ruta = ruta_retro
|
||
if (ruta==rutaOK && y>=2021) ruta = ruta_estrenos
|
||
/********************************************/
|
||
/**************************************/
|
||
|
||
//if (errorNoGenero && 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
|
||
if (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
|
||
|
||
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
|
||
} |