1
0
Fork 0

improves, clean up and reduce verticality

This commit is contained in:
Xavier Fontanet 2023-05-09 19:27:47 +02:00
parent 9d60356ee5
commit 95cb29d287
2 changed files with 70 additions and 109 deletions

View File

@ -21,6 +21,7 @@ def rutaKO = root+"error/"
/* HARDCODED */ /* HARDCODED */
def skipAudioCheck = true def skipAudioCheck = true
def relocation = true
/*************/ /*************/
/** Audio (definición) **/ /** Audio (definición) **/
@ -95,6 +96,13 @@ def getInicial () {
def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/' def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/'
return inicial return inicial
} }
def normalLang(langs) {
return !langs.isEmpty() ? {try { for (lan in languages) langs.add(lan.toString()) } catch(err) {langs}}() : langs
}
def sanityCheck(newId) {
def oldId = fn.find(/\{tmdb-\d+\}/).find(/\d+/)
return oldId == newId.toString()
}
/***********/ /***********/
try { //empieza el script try { //empieza el script
@ -106,6 +114,8 @@ try { //empieza el script
else if (ext!="mkv" && ext!="avi" && ext!="mp4") { else if (ext!="mkv" && ext!="avi" && ext!="mp4") {
throw new Exception("[formato_fichero_noestarndar]") throw new Exception("[formato_fichero_noestarndar]")
} }
/* otras validaciones */
if (relocation && !sanityCheck(tmdbid)) return '@@@@@@ Names Sanity Check KO @@@@@@@ --> New name: '+localize.Spanish.n+' with tmdb='+tmdbid
try { try {
video video
} catch (e) { } catch (e) {
@ -334,10 +344,11 @@ try { //empieza el script
//familiar (no conclud) //familiar (no conclud)
def tieneFamiliar = genres.any{ it =~ /Familia|Family/} def tieneFamiliar = genres.any{ it =~ /Familia|Family/}
//docu //docu
def esDocu = genres.any{ it =~ /Documental|Documentary|Reality/} && !(title =~ /Jackass/) def esDocu = genres.any{ it =~ /Documental|Documentary|Reality/} && !(localize.English.n =~ /Jackass/)
//anime //anime
def esAnime = false def esAnime = false
def numPaises = info.ProductionCountries.size() def numPaises = info.ProductionCountries.size()
def llengu=[]
if (tieneAnimacion && info.ProductionCountries.contains("JP")) { if (tieneAnimacion && info.ProductionCountries.contains("JP")) {
esAnime = numPaises==1 || anime /*|| country=="JP"*/ esAnime = numPaises==1 || anime /*|| country=="JP"*/
} }
@ -347,13 +358,13 @@ try { //empieza el script
def espanyola = false def espanyola = false
if (!tipoYaSeteado && info.ProductionCountries.contains("ES")) { if (!tipoYaSeteado && info.ProductionCountries.contains("ES")) {
espanyola= espanyola=
(numPaises==1 || (numPaises==2 && info.ProductionCountries.contains("PT"))) (numPaises==1 || (numPaises==2 && info.ProductionCountries.any{ it=~/AR|PT/ }))
|| { try { info.Network =~ /(?i)\bFLIXOL.\b|\b.?TVE\b/ } catch (e) { false } }() || { try { info.Network =~ /(?i)\bFLIXOL.\b|\b.?TVE\b/ } catch (e) { false } }()
|| { try { info.ProductionCompanies.any{ it =~ /.?TVE|ESDIP|Canal Sur|Canal\+ España/ } } catch (e) { false } }() || { try { info.ProductionCompanies.any{ it =~ /.?TVE|ESDIP|Canal Sur|Canal\+|Telecinco/ } } catch (e) { false } }()
|| (info.Certifications.size()==1 && info.Certifications.ES!=null) || (info.Certifications.size()==1 && info.Certifications.ES!=null)
|| { try { languages.size()==1 && languages.get(0).toString()=~/esp|spa/ } catch (e) { false } }() || { llengu=normalLang(llengu); llengu.size()==1 && llengu[0]=~/esp|spa/}()
|| (movie.alternativeTitles.size()==1 && movie.alternativeTitles.ES!=null) || (movie.alternativeTitles.size()==1 && movie.alternativeTitles.ES!=null)
|| { try { country=="ES" } catch (e){false} }() && { try { if(languages.size()==1) languages.get(0).toString()!="eng" } catch (e) { false } }() || (country=="ES" && (!llengu.isEmpty() ? llengu.size()==1 && llengu[0]!="eng" : true))
tipoYaSeteado = espanyola tipoYaSeteado = espanyola
} }
@ -400,7 +411,9 @@ try { //empieza el script
def languajAsia = ["zho", "kor", "thai", "vie", "jpn", "ind"] def languajAsia = ["zho", "kor", "thai", "vie", "jpn", "ind"]
def matchP = paisesAsiaticos.intersect(info.ProductionCountries) def matchP = paisesAsiaticos.intersect(info.ProductionCountries)
asiatica = matchP.size() == numPaises asiatica = matchP.size() == numPaises
|| {try { languages.any{ languajAsia.contains(it.toString()) } } catch (err) {false} }() //|| {try { languages.any{ languajAsia.contains(it.toString()) } } catch (err) {false} }()
|| { llengu=normalLang(llengu); languajAsia.intersect(llengu).size() == languajAsia.size() }()
|| { llengu.size()==1 && llengu[0]=~/esp|spa/}()
//|| matchP.size()>0 && englishAudios.isEmpty() && audio.size()>1 /*en obseracion*/ //|| matchP.size()>0 && englishAudios.isEmpty() && audio.size()>1 /*en obseracion*/
} }

View File

@ -1,6 +1,6 @@
//by @xeviff //by @xeviff
/** RUTAS **/ /** RUTAS **/
def ubuntu_desktop=true def ubuntu_desktop=false
def root = ubuntu_desktop ? '/mnt/mangrana_pelis/' : '/pelis/' def root = ubuntu_desktop ? '/mnt/mangrana_pelis/' : '/pelis/'
def rutaOK = root+"Pelis/plain/" def rutaOK = root+"Pelis/plain/"
@ -21,6 +21,7 @@ def rutaKO = root+"error/"
/* HARDCODED */ /* HARDCODED */
def skipAudioCheck = true def skipAudioCheck = true
def show_error_line=true
/* otras funciones */ /* otras funciones */
/**/ /**/
@ -33,14 +34,12 @@ def getInicial () {
def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/' def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/'
return inicial return inicial
} }
def sanityCheck() { def normalLang(langs) {
def clearCurrentName = fn.replaceAll(/\s|-|:||\./,'') return !langs.isEmpty() ? {try { for (lan in languages) langs.add(lan.toString()) } catch(err) {langs}}() : langs
def clearPlexName = plex.name.replaceAll(/\s|-|:||\./,'') }
if (clearCurrentName.substring(0, clearCurrentName.size()-6)!=clearPlexName.substring(0, clearPlexName.size()-6)) def sanityCheck(newId) {
return false def oldId = fn.find(/\{tmdb-\d+\}/).find(/\d+/)
def yearOldName = clearCurrentName.substring(clearCurrentName.size()-5, clearCurrentName.size()-1) as int return oldId == newId.toString()
def yearNewName = clearPlexName.substring(clearPlexName.size()-5, clearPlexName.size()-1) as int
return Math.abs(yearOldName - yearNewName) < 2
} }
//*****************************************************************************************/ //*****************************************************************************************/
//*****************************************************************************************/ //*****************************************************************************************/
@ -48,8 +47,14 @@ def sanityCheck() {
try { //empieza el script try { //empieza el script
//sanity check //sanity check
if (!sanityCheck()) return '@@@@@@ Names Sanity Check KO @@@@@@@ --> New name: '+plex.name if (!sanityCheck(tmdbid)) return '@@@@@@ Names Sanity Check KO @@@@@@@ --> New name: '+localize.Spanish.n+' with tmdb='+tmdbid
if (ext==~/jpg|nfo|png|url/) {
return fn
}
else if (ext!="mkv" && ext!="avi" && ext!="mp4") {
throw new Exception("[formato_fichero_noestarndar]")
}
try { try {
video video
} catch (e) { } catch (e) {
@ -62,64 +67,11 @@ try { //empieza el script
} }
/********************************/ /********************************/
/** 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 *******/ /**** Carpeta / tipo contenido *******/
def tipoYaSeteado=false def tipoYaSeteado=false
def llengu=[]
//animacion (no concluyente) //animacion (no concluyente)
def tieneAnimacion = genres.any{ it =~ /Anima.i.n/} def tieneAnimacion = genres.any{ it =~ /Anima.i.n/}
@ -136,37 +88,38 @@ try { //empieza el script
tipoYaSeteado = esDocu || esAnime tipoYaSeteado = esDocu || esAnime
//*** española *** //*** española ***
def espanyola = tipoYaSeteado def espanyola = false
|| info.ProductionCountries.contains("ES") && (numPaises==1 || (numPaises==2 && info.ProductionCountries.contains("PT"))) if (!tipoYaSeteado && info.ProductionCountries.contains("ES")) {
|| { try { info.Network =~ /(?i)\bFLIXOL.\b|\b.?TVE\b/ } catch (e) { false } }() espanyola=
|| { try { info.ProductionCompanies.any{ it =~ /.?TVE|ESDIP|Canal Sur|Canal\+ España/ } } catch (e) { false } }() (numPaises==1 || (numPaises==2 && info.ProductionCountries.any{ it=~/AR|PT/ }))
|| (info.Certifications.size()==1 && info.Certifications.ES!=null) || { try { info.Network =~ /(?i)\bFLIXOL.\b|\b.?TVE\b/ } catch (e) { false } }()
|| { try { languages.size()==1 && languages.get(0).toString()=="esp" } catch (e) { false } }() || (movie.alternativeTitles.size()==1 && movie.alternativeTitles.ES!=null) || { try { info.ProductionCompanies.any{ it =~ /.?TVE|ESDIP|Canal Sur|Canal\+|Telecinco/ } } catch (e) { false } }()
|| { try { country=="ES" } catch (e){false} }() && { try { if(languages.size()==1) languages.get(0).toString()!="eng" } catch (e) { false } }() || (info.Certifications.size()==1 && info.Certifications.ES!=null)
tipoYaSeteado = tipoYaSeteado || espanyola || { llengu=normalLang(llengu); llengu.size()==1 && llengu[0]=~/esp|spa/}()
|| (movie.alternativeTitles.size()==1 && movie.alternativeTitles.ES!=null)
|| (country=="ES" && (!llengu.isEmpty() ? llengu.size()==1 && llengu[0]!="eng" : true))
tipoYaSeteado = espanyola
}
//***** familiar vs infantil **** //***** familiar vs infantil ****
def esFamiliar = tieneFamiliar def esFamiliar = tieneFamiliar
def infantil = false def infantil = false
if (!tipoYaSeteado) { if (!tipoYaSeteado) {
def tieneCertificacion = info.Certifications!=null && info.Certifications.size()!=0 def tieneCertificacion = info.Certifications!=null && info.Certifications.size()!=0
if (tieneFamiliar && tieneAnimacion) { if (tieneFamiliar && tieneAnimacion) {
def noTanInfantil = info.Certifications.US ==~/PG-13/ def noTanInfantil = info.Certifications.US ==~/PG-13/
if (!noTanInfantil) if (!noTanInfantil) infantil = true
infantil = true
} }
else if (tieneAnimacion) { else if (tieneAnimacion) {
if (tieneCertificacion) { if (tieneCertificacion) {
if ( info.Certifications.US=="G" infantil = info.Certifications.US=="G"
|| info.Certifications.ES==~/Ai|APTA/ || info.Certifications.ES==~/Ai|APTA/
|| info.Certifications.DE==~/0|6/ || info.Certifications.DE==~/0|6/
|| info.Certifications.IT=="T" || info.Certifications.IT=="T"
|| info.Certifications.LT=="V" || info.Certifications.RU ==~ /6.+/ || info.Certifications.LT=="V" || info.Certifications.RU ==~ /6.+/
|| info.Certifications.BR=="L" || info.Certifications.BR=="L"
)
infantil=true
} else { } else {
def titulosInfantiles = ['Bonnie bears', 'The Jungle Bunch'] def titulosInfantiles = ['Bonnie bears', 'The Jungle Bunch']
if (titulosInfantiles.any { localize.English.n.toLowerCase()contains(it.toLowerCase()) }) if (titulosInfantiles.any { localize.English.n.toLowerCase()contains(it.toLowerCase()) })
@ -179,7 +132,7 @@ try { //empieza el script
esFamiliar = true //posem a familiar pelis de nens que no son animacio esFamiliar = true //posem a familiar pelis de nens que no son animacio
} }
} }
tipoYaSeteado = tipoYaSeteado || infantil tipoYaSeteado = esFamiliar || infantil
} }
//asiaticas //asiaticas
@ -188,10 +141,12 @@ try { //empieza el script
//asiaticas //asiaticas
if (numPaises>0) { if (numPaises>0) {
def paisesAsiaticos = ["CN", "HK", "JP", "KP", "KR", "TH", "NP", "TW", "PH", "MO"] def paisesAsiaticos = ["CN", "HK", "JP", "KP", "KR", "TH", "NP", "TW", "PH", "MO"]
def languajAsia = ["zho", "kor", "thai", "vie", "jpn", "ind"]
def matchP = paisesAsiaticos.intersect(info.ProductionCountries) def matchP = paisesAsiaticos.intersect(info.ProductionCountries)
def allAsian = matchP.size()==numPaises asiatica = matchP.size() == numPaises
def probableAsian = matchP.size()>0 && englishAudios.isEmpty() && audio.size()>1 || { llengu=normalLang(llengu); languajAsia.intersect(llengu).size() == languajAsia.size() }()
if (allAsian || probableAsian/*en obseracion*/) asiatica=true || { llengu.size()==1 && llengu[0]=~/esp|spa/}()
} }
} }
@ -213,26 +168,19 @@ try { //empieza el script
/**************************************/ /**************************************/
/*** RESULTADO FINAL ***/ /*** RESULTADO FINAL ***/
def inicial='' def inicial = (ruta==rutaOK || ruta==ruta_retro) ? getInicial() : ''
def tmdb = ""//" {tmdb-"+tmdbid+"}"
def carpetaPeli = localize.Spanish.plex.name + tmdb + '/'
def inicialsRequerides = ruta==rutaOK || ruta==ruta_retro return ruta + inicial + carpetaPeli + fn
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) { } catch (err) {
String str= err.getStackTrace().toString() if (show_error_line) {
def pattern = ( str =~ /groovy.(\d+)./ ) String str= err.getStackTrace().toString()
return " Error at line number = " + pattern[0][1] + ". more: "+str def pattern = ( str =~ /groovy.(\d+)./ )
return " Error at line number = " + pattern[0][1] + ". more: "+str
}
def rutaMotivoErr def rutaMotivoErr
def msgErr = err.getMessage() def msgErr = err.getMessage()