480 lines
16 KiB
Groovy
Executable File
480 lines
16 KiB
Groovy
Executable File
//by @xeviff
|
|
/** RUTAS **/
|
|
def ubuntu_desktop=false
|
|
|
|
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
|
|
/*************/
|
|
|
|
/** 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", "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
|
|
def idiomaOrigin = audio2Print.Language_String
|
|
if (idiomaOrigin==null) {
|
|
idiomaOrigin = audio2Print.Title
|
|
if (idiomaOrigin =~ /(?i)\bcat\b/)
|
|
idioma = "Cat"
|
|
else if (idiomaOrigin =~ /(?i)\bcast\b|\bspa\b/)
|
|
idioma = "Es"
|
|
} else {
|
|
idioma = idiomaOrigin.replace("Catalan","Cat").replace("Espanol / Espanol", "Es").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 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
|
|
}
|
|
/***********/
|
|
|
|
try { //empieza el script
|
|
|
|
/** Tipo de archivo incorrecto **/
|
|
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) {
|
|
throw new Exception("[video_roto]")
|
|
}
|
|
try {
|
|
genres
|
|
} catch (err) {
|
|
throw new Exception("[genero_no_especificado]")
|
|
}
|
|
/********************************/
|
|
|
|
/** Codec Vídeo: en nombre fichero **/
|
|
def codecVideo = (any{vc}{0} =~ /HEVC|265|ATEME/ ) ? 'HEVC' :
|
|
(any{vc}{0} =~ /264/) ? 'AVC' : vc
|
|
/**************/
|
|
|
|
/******* Calidad ******/
|
|
def peso = bytes.toString().before(' ').toDouble()
|
|
def numericBps = (mbps.toString().before(' ').toDouble()*1000000).round()
|
|
def calidad =
|
|
['480p', '576p', '360p', '240p'].contains(vf) ? 'SD' //SD
|
|
: (vf == '2160p') ? //4K
|
|
(peso > 30 && numericBps >= 26000000)
|
|
? "4K-UHDRemux"
|
|
: (peso > 15)
|
|
? "4K-UHDRip"
|
|
: "4K-MicroUHD"
|
|
: (vf == '1080p') ? //1080
|
|
(peso > 15 && numericBps >= 18000000)
|
|
? "1080-BDRemux"
|
|
: (numericBps > 8000000)
|
|
? "1080-HD"
|
|
: "1080-MicroHD"
|
|
: vf //720
|
|
|
|
def calidadF = calidad=="4K-UHDRemux" ? "4K"
|
|
: calidad=="4K-UHDRip" ? "4K"
|
|
: calidad=="4K-MicroUHD" ? "micro4K"
|
|
: calidad=="1080-BDRemux" ? "HD"
|
|
: calidad=="1080-HD" ? "HD"
|
|
: calidad=="1080-MicroHD" ? "microHD"
|
|
: calidad=="SD" ? vf // Los SD vamos a poner su resolución
|
|
: calidad //tal cual
|
|
/***************************/
|
|
|
|
/** 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") //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 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 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
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_solo_ingles]")
|
|
} else if (!otherAudios.isEmpty()) { //tenemos español
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_marginal]")
|
|
} else {
|
|
if (!skipAudioCheck) throw new Exception("[idioma_audio_no_encontrado]")
|
|
}
|
|
if (bloqueAudio==null) bloqueAudio = "audio_no_def"
|
|
/***********/
|
|
|
|
/** Formato distribución **/
|
|
formato_distribucion =
|
|
fn=~/(?i)\bblu.?ray\b/ ? 'BDRip' :
|
|
fn=~/(?i)\bdrip\b/ ? 'BDRip' :
|
|
fn=~/(?i)\bDVD.?RIP\b/ ? 'DVDRip' :
|
|
fn=~/(?i)\bHDiTunes\b/ ? 'HDiTunes' :
|
|
fn=~/(?i)\bTV.?RIP\b/ ? 'TVRip' :
|
|
fn=~/(?i)\bWEB.?Screener\b/ ? 'WEB-SRC' :
|
|
'no_encontrado'
|
|
def plataforma
|
|
def esWEB_DL=false
|
|
if (formato_distribucion=='no_encontrado') {
|
|
esWEB_DL = fn=~/(?i)\bWEB.??(DL|RIP)\b/ //WEB-DL o WEB-RIP (todo junto o con punto/guión/etc)
|
|
|
|
if (esWEB_DL) {
|
|
def web_x = fn=~/(?i)\bWEB.?DL\b/ ? 'WEB-DL' : 'WEB-RIP' //guardar el que es
|
|
plataforma = fn.find( //coge el contenido que encaja
|
|
/(?i)\bAMZN?\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|\bRTVE\b|\bFLIXOL.\b|\bM\+\b/ )
|
|
if (plataforma!=null) plataforma = plataforma.replace("MVPLUS","MV+")
|
|
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
|
|
}
|
|
}
|
|
}
|
|
/**********/
|
|
|
|
/** Formato distribución 2ª ronda**/
|
|
//formato_distribucion = formato_distribucion=='no_encontrado'? '' : ' '+formato_distribucion
|
|
if (formato_distribucion=='no_encontrado') {
|
|
formato_distribucion =
|
|
calidad=="4K-UHDRemux" ? "UHDRemux" :
|
|
calidad=="4K-UHDRip" ? "UHDRip" :
|
|
calidad=="4K-MicroUHD" ? "UHDRip" :
|
|
calidad=="1080-BDRemux" ? "BDRemux" :
|
|
calidad=="1080-HD" ? "DBRip" :
|
|
calidad=="1080-MicroHD" ? "BDRip" :
|
|
'' //no_encontrado -> ''
|
|
} else {
|
|
if (calidad=~/(?i)\remux\b/) {
|
|
formato_distribucion =
|
|
calidad=="4K-UHDRemux" ? "UHDRemux" :
|
|
calidad=="1080-BDRemux" ? "BDRemux" :
|
|
'' //no_encontrado -> ''
|
|
}
|
|
|
|
}
|
|
if (formato_distribucion!='') formato_distribucion=' '+formato_distribucion
|
|
/**********************************/
|
|
|
|
/**** HDR ********/
|
|
def hdr_info=''
|
|
try{
|
|
def mHDRCol = ["BT.709" : "NO", "BT.2020" : "YES"]
|
|
def hdr_info_old = (bitdepth >= 10 && mHDRCol.get(self.video[0].colourprimaries) == "YES" ) ? ' HDR' : ''
|
|
|
|
def _HDRMap = [
|
|
"HDR10": "HDR10",
|
|
"SMPTE ST 2086": "HDR10",
|
|
"SMPTE ST 2094 App 4": "HDR10+",
|
|
"Dolby Vision / SMPTE ST 2086": "Dolby Vision",
|
|
"Dolby Vision / HDR10": "Dolby Vision",
|
|
]
|
|
def vid = video.first()
|
|
String _HDR
|
|
switch (bitdepth) {
|
|
case { it > 8 }:
|
|
_HDR = any
|
|
{ vid["HDR_Format_Commercial"] }
|
|
{ vid["HDR_Format"] }
|
|
{ hdr }
|
|
{ null }
|
|
break
|
|
default:
|
|
"$bitdepth-bit"
|
|
break
|
|
}
|
|
def hdr_info_ = _HDRMap.find { k, v ->
|
|
k =~ _HDR
|
|
}?.value
|
|
|
|
if (hdr_info_!=null) hdr_info=' '+hdr_info_
|
|
} catch (err) {}
|
|
/*****************/
|
|
|
|
/**** Profundidad de color */
|
|
def profundidadColor=''
|
|
try{profundidadColor = bitdepth+"bits" } catch(err){}
|
|
/**************************/
|
|
|
|
/**** Profundidad vídeo ****/
|
|
def myBitrate = 'noBRdef'
|
|
try{ myBitrate = mbps.replace(/.0/,'').replace(' ','') }catch(err){}
|
|
def myFps = ' FRvar'
|
|
try { myFps = ' '+fps.replace(/.0/,'').replace(' ','') }catch(err){}
|
|
/***************************/
|
|
|
|
/* RESULTADO MEDIAINFO */
|
|
def bloqueCalidadVideo = calidadF+formato_distribucion+hdr_info
|
|
def bloqueProfundidad = myBitrate+myFps
|
|
if (bloqueProfundidad!='' && profundidadColor!='') bloqueProfundidad=' '+bloqueProfundidad
|
|
|
|
def bloqueMediainfo = ' ['+codecVideo+' '+bloqueCalidadVideo+']['+profundidadColor+bloqueProfundidad+']'+' ['+bloqueAudio+']'
|
|
|
|
|
|
|
|
/**************************************/
|
|
/**** Carpeta / tipo contenido *******/
|
|
def tipoYaSeteado=false
|
|
|
|
//animacion (no concluyente)
|
|
def tieneAnimacion = genres.any{ it =~ /Anima.i.n/}
|
|
//familiar (no conclud)
|
|
def tieneFamiliar = genres.any{ it =~ /Familia|Family/}
|
|
//docu
|
|
def esDocu = genres.any{ it =~ /Documental|Documentary|Reality/} && !(title =~ /Jackass/)
|
|
//anime
|
|
def esAnime = false
|
|
def numPaises = info.ProductionCountries.size()
|
|
if (tieneAnimacion && info.ProductionCountries.contains("JP")) {
|
|
esAnime = numPaises==1 || anime /*|| country=="JP"*/
|
|
}
|
|
tipoYaSeteado = esDocu || esAnime
|
|
|
|
//*** española ***
|
|
def espanyola = false
|
|
if (!tipoYaSeteado && info.ProductionCountries.contains("ES")) {
|
|
espanyola=
|
|
(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|spa/ } 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 = 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
|
|
}
|
|
else if (tieneAnimacion) {
|
|
if (tieneCertificacion) {
|
|
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()) })
|
|
infantil = true
|
|
}
|
|
} else if (!esFamiliar) {
|
|
if (tieneCertificacion && (
|
|
info.Certifications.US=="G"
|
|
)) {
|
|
esFamiliar = true //posem a familiar pelis de nens que no son animacio
|
|
}
|
|
}
|
|
tipoYaSeteado = esFamiliar || infantil
|
|
}
|
|
|
|
//asiaticas
|
|
def asiatica = false
|
|
if (!tipoYaSeteado) {
|
|
//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)
|
|
asiatica = matchP.size() == numPaises
|
|
|| {try { languages.any{ languajAsia.contains(it.toString()) } } catch (err) {false} }()
|
|
//|| matchP.size()>0 && englishAudios.isEmpty() && audio.size()>1 /*en obseracion*/
|
|
|
|
}
|
|
}
|
|
|
|
//es animacion
|
|
def esAnimacion = tieneAnimacion && !esFamiliar
|
|
|
|
//tria
|
|
if (esDocu) ruta = ruta_docu
|
|
else if (esAnime) ruta = ruta_anime
|
|
else if (infantil) ruta = ruta_infantil
|
|
else if (esAnimacion) ruta = ruta_animacion
|
|
else if (espanyola) ruta = ruta_esp
|
|
else if (esFamiliar) ruta = ruta_familiar
|
|
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
|
|
/********************************************/
|
|
/**************************************/
|
|
|
|
|
|
/**** Nombre pelicula ****/
|
|
def nombrePelicula_formatoPlex = {try { primaryTitle!=localize.Catalan.n ? localize.Catalan.plex.name : localize.Spanish.plex.name } catch (err) {localize.Spanish.plex.name} }()
|
|
/*************************/
|
|
|
|
|
|
/*** RESULTADO FINAL ***/
|
|
def inicial = (ruta==rutaOK || ruta==ruta_retro) ? getInicial() : ''
|
|
def tmdb = " {tmdb-"+tmdbid+"}"
|
|
def carpetaPeli = localize.Spanish.plex.name + tmdb + '/'
|
|
def nomPrincipal = nombrePelicula_formatoPlex + bloqueMediainfo
|
|
def tracker = fn.find(/(?i)\bHDO(limpo)?\b/)
|
|
def extras = tracker != null ? ' ['+tracker.replace("HDOlimpo", "HDO")+']' : ''
|
|
|
|
return ruta + inicial + carpetaPeli + nomPrincipal + extras + tmdb
|
|
|
|
} catch (err) {
|
|
|
|
if (ubuntu_desktop) {
|
|
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 + '/' + localize.English.plex.name + '/' + fn
|
|
|
|
return resultado
|
|
} |