From 95cb29d2873b5e4f400b07c29b880f8854ed47e3 Mon Sep 17 00:00:00 2001 From: Xavier Fontanet Date: Tue, 9 May 2023 19:27:47 +0200 Subject: [PATCH] improves, clean up and reduce verticality --- MaNGranA_Pelis.groovy | 25 ++++-- MaNGranA_Pelis_Organizer.groovy | 154 +++++++++++--------------------- 2 files changed, 70 insertions(+), 109 deletions(-) diff --git a/MaNGranA_Pelis.groovy b/MaNGranA_Pelis.groovy index 29ce680..0538e05 100755 --- a/MaNGranA_Pelis.groovy +++ b/MaNGranA_Pelis.groovy @@ -21,6 +21,7 @@ def rutaKO = root+"error/" /* HARDCODED */ def skipAudioCheck = true +def relocation = true /*************/ /** Audio (definición) **/ @@ -95,6 +96,13 @@ def getInicial () { def inicial = iniClear.replaceAll(/[0-9]/,'#')+'/' 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 @@ -106,6 +114,8 @@ try { //empieza el script else if (ext!="mkv" && ext!="avi" && ext!="mp4") { 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 { video } catch (e) { @@ -334,10 +344,11 @@ try { //empieza el script //familiar (no conclud) def tieneFamiliar = genres.any{ it =~ /Familia|Family/} //docu - def esDocu = genres.any{ it =~ /Documental|Documentary|Reality/} && !(title =~ /Jackass/) + def esDocu = genres.any{ it =~ /Documental|Documentary|Reality/} && !(localize.English.n =~ /Jackass/) //anime def esAnime = false def numPaises = info.ProductionCountries.size() + def llengu=[] if (tieneAnimacion && info.ProductionCountries.contains("JP")) { esAnime = numPaises==1 || anime /*|| country=="JP"*/ } @@ -347,13 +358,13 @@ try { //empieza el script def espanyola = false if (!tipoYaSeteado && info.ProductionCountries.contains("ES")) { 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.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) - || { 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) - || { 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 } @@ -400,7 +411,9 @@ try { //empieza el script def languajAsia = ["zho", "kor", "thai", "vie", "jpn", "ind"] def matchP = paisesAsiaticos.intersect(info.ProductionCountries) 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*/ } diff --git a/MaNGranA_Pelis_Organizer.groovy b/MaNGranA_Pelis_Organizer.groovy index 9bc237e..5b15afe 100755 --- a/MaNGranA_Pelis_Organizer.groovy +++ b/MaNGranA_Pelis_Organizer.groovy @@ -1,6 +1,6 @@ //by @xeviff /** RUTAS **/ -def ubuntu_desktop=true +def ubuntu_desktop=false def root = ubuntu_desktop ? '/mnt/mangrana_pelis/' : '/pelis/' def rutaOK = root+"Pelis/plain/" @@ -21,6 +21,7 @@ def rutaKO = root+"error/" /* HARDCODED */ def skipAudioCheck = true +def show_error_line=true /* otras funciones */ /**/ @@ -33,14 +34,12 @@ def getInicial () { 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 +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() } //*****************************************************************************************/ //*****************************************************************************************/ @@ -48,8 +47,14 @@ def sanityCheck() { try { //empieza el script //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 { video } 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 *******/ def tipoYaSeteado=false + def llengu=[] //animacion (no concluyente) def tieneAnimacion = genres.any{ it =~ /Anima.i.n/} @@ -136,37 +88,38 @@ try { //empieza el script tipoYaSeteado = esDocu || esAnime //*** española *** - def espanyola = tipoYaSeteado - || info.ProductionCountries.contains("ES") && (numPaises==1 || (numPaises==2 && info.ProductionCountries.contains("PT"))) - || { 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 } }() - || (info.Certifications.size()==1 && info.Certifications.ES!=null) - || { try { languages.size()==1 && languages.get(0).toString()=="esp" } catch (e) { false } }() || (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 } }() - tipoYaSeteado = tipoYaSeteado || espanyola + def espanyola = false + if (!tipoYaSeteado && info.ProductionCountries.contains("ES")) { + espanyola= + (numPaises==1 || (numPaises==2 && info.ProductionCountries.any{ it=~/AR|PT/ })) + || { try { info.Network =~ /(?i)\bFLIXOL.\b|\b.?TVE\b/ } 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) + || { 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 **** def esFamiliar = tieneFamiliar def infantil = false + 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 + 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 + infantil = 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" } else { def titulosInfantiles = ['Bonnie bears', 'The Jungle Bunch'] 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 } } - tipoYaSeteado = tipoYaSeteado || infantil + tipoYaSeteado = esFamiliar || infantil } //asiaticas @@ -188,10 +141,12 @@ try { //empieza el script //asiaticas if (numPaises>0) { 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 allAsian = matchP.size()==numPaises - def probableAsian = matchP.size()>0 && englishAudios.isEmpty() && audio.size()>1 - if (allAsian || probableAsian/*en obseracion*/) asiatica=true + asiatica = matchP.size() == numPaises + || { llengu=normalLang(llengu); languajAsia.intersect(llengu).size() == languajAsia.size() }() + || { llengu.size()==1 && llengu[0]=~/esp|spa/}() + } } @@ -213,26 +168,19 @@ try { //empieza el script /**************************************/ /*** 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 - 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 + return ruta + inicial + carpetaPeli + fn } catch (err) { - String str= err.getStackTrace().toString() - def pattern = ( str =~ /groovy.(\d+)./ ) - return " Error at line number = " + pattern[0][1] + ". more: "+str + if (show_error_line) { + 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()