438 lines
16 KiB
Groovy
Executable File
438 lines
16 KiB
Groovy
Executable File
//by @xeviff
|
|
/* HARDCODED */
|
|
def skipAudioCheck = true
|
|
def relocation = true
|
|
/*************/
|
|
/** 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/"
|
|
/**********/
|
|
|
|
/** Audio (definición) **/
|
|
def hayEAC3=false
|
|
|
|
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]")
|
|
}
|
|
//*** Relocate Remux and UHD to Transcode input folder
|
|
def peso = bytes.toString().before(' ').toDouble()
|
|
def numericBps = (mbps.toString().before(' ').toDouble()*1000000).round()
|
|
def es1080 = vf ==~ '1080.'
|
|
def es1080Remux = peso > 15 && numericBps >= 18000000
|
|
if (!relocation && (vf ==~ '2160.' || (es1080 && es1080Remux))) return root+"/to Transcode/"+fn
|
|
|
|
/* otras validaciones */
|
|
if (relocation && !sanityCheck(tmdbid)) return '@@@@@@ Names Sanity Check KO @@@@@@@ --> New name: '+localize.Spanish.n+' with tmdb='+tmdbid
|
|
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 calidad =
|
|
(vf =~ '2160.') ? //4K
|
|
(peso > 30 && numericBps >= 26000000)
|
|
? "UHDRemux"
|
|
: (peso > 15)
|
|
? "UHDRip"
|
|
: "microUHD"
|
|
: es1080 ? //1080
|
|
es1080Remux
|
|
? vf+" BDRemux"
|
|
: (numericBps > 8000000)
|
|
? vf
|
|
: "microHD"
|
|
: vf
|
|
def fuente = {try{ source } catch(err){null}}()
|
|
if (fuente!=null) calidad = calidad.startsWith("micro") ? calidad : vf
|
|
|
|
/***************************/
|
|
/** Formato distribución **/
|
|
formato_distribucion = fuente!=null ? fuente : relocation ? '' :
|
|
fn=~/(?i)\bblu.?ray\b|\bbdrip\b/ ? (calidad=~/(?i).+rip/ ? '' : 'BDRip') :
|
|
fn=~/(?i)remux/ ? (calidad=~/(?i).+remux/ ? '' : 'BDRemux') :
|
|
fn=~/(?i)\bWEB.??(DL|RIP)\b/ ? 'WEB-DL' :
|
|
''
|
|
if (formato_distribucion=='WEB-DL') {
|
|
def 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 = formato_distribucion+(plataforma!=null?(' '+plataforma.toUpperCase()):'')
|
|
} else if (hayEAC3) //por el audio también se determina que es web-dl
|
|
formato_distribucion = '¿WEB-DL'
|
|
if (formato_distribucion!='') formato_distribucion=' '+formato_distribucion
|
|
/**********************************/
|
|
|
|
/**** HDR ********/
|
|
def hdr_info=''
|
|
try{
|
|
def mHDRCol = ["BT.709" : "NO", "BT.2020" : "YES"]
|
|
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
|
|
}
|
|
hdr_info = _HDRMap.find { k, v -> k =~ _HDR }?.value
|
|
if (hdr_info!=null) hdr_info=' '+hdr_info
|
|
else 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){}
|
|
/***************************/
|
|
|
|
/* BLOQUE VIDEO */
|
|
def bloqueCalidadVideo = calidad + formato_distribucion
|
|
def bloqueDescVideo = myBitrate + profundidadColor + myFps + hdr_info
|
|
def bloqueVideo = ' ['+codecVideo+' '+bloqueCalidadVideo+' '+bloqueDescVideo+']'
|
|
/**********************************************************************************************************/
|
|
|
|
/** AUDIO (ejecución) **/
|
|
def bloqueAudio=''
|
|
def audiosMap = [:]
|
|
for (aud in audio) {
|
|
def shortDesc = aud.Language_String3 !=null ? aud.Language_String3
|
|
: (aud.Title=~/(?i).+spa.+/?'spa': aud.Title.substring(0,3).toLowerCase())
|
|
audiosMap[shortDesc] = audiosMap[shortDesc] ?: [:]
|
|
audiosMap[shortDesc][aud.Format] = audiosMap[shortDesc][aud.Format] ?: []
|
|
audiosMap[shortDesc][aud.Format] << aud
|
|
}
|
|
def groupedAudiosMap = [:]
|
|
for (audioElms in audiosMap) {
|
|
def k = audioElms.key
|
|
def v = audioElms.value
|
|
if (!k.contains('+') && countAudiosInMap(v)>1) k += '+'
|
|
def mQ = getMaxQuality(v)
|
|
def mQstr = (mQ==null || mQ.isEmpty()) ? 'und' : printAudio(mQ)
|
|
if (groupedAudiosMap.containsKey(mQstr)) groupedAudiosMap[mQstr].add(k)
|
|
else groupedAudiosMap[mQstr] = [k]
|
|
}
|
|
audiosMap=null
|
|
def temp=''
|
|
for (audioGroup in groupedAudiosMap) {
|
|
def k = audioGroup.key
|
|
def v = audioGroup.value
|
|
def gS = v.size()
|
|
def str=''
|
|
for (int i=0; i<gS; i++) {
|
|
str += (v[i]!=null?v[i]:'und') +', '
|
|
if (i==gS-1) {
|
|
str = removeLastComa(str)+' '
|
|
str += k+', '
|
|
}
|
|
}
|
|
bloqueAudio += str
|
|
}
|
|
groupedAudiosMap=null
|
|
bloqueAudio = '['+removeLastComa(bloqueAudio)+']'
|
|
|
|
|
|
/***** subtitulos *******/
|
|
def bloqueSubs
|
|
try {
|
|
def capturedSubs = [:]
|
|
bloqueSubs = '['
|
|
for (sub in text) handleSub(sub, capturedSubs)
|
|
for (entry in capturedSubs) bloqueSubs += (entry.value!='null'?entry.value:'und')+', '
|
|
bloqueSubs = bloqueSubs.substring(0,bloqueSubs.size()-2)+']'
|
|
}catch(err){bloqueSubs=''}
|
|
/************************/
|
|
|
|
|
|
/*************************************************************************************************************/
|
|
/**** 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/} && !(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"*/
|
|
}
|
|
tipoYaSeteado = esDocu || esAnime
|
|
|
|
//*** española ***
|
|
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
|
|
}
|
|
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} }()
|
|
|| { 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*/
|
|
|
|
}
|
|
}
|
|
|
|
//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 + bloqueVideo + bloqueAudio + bloqueSubs
|
|
def trackerCatch = fn.find(/(?i)\bHDO(limpo)?\b|\bRedBits\b/)
|
|
def tracker = trackerCatch != null ? '['+trackerCatch.replace("HDOlimpo", "HDO")+']' : ''
|
|
|
|
return ruta + inicial + carpetaPeli + nomPrincipal + tracker + 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
|
|
}
|
|
|
|
|
|
|
|
/********************************************************/
|
|
/********************************************************/
|
|
/************** FUNCIONES *******************************/
|
|
/********************************************************/
|
|
/********************************************************/
|
|
|
|
|
|
/********* AUDIO *****************/
|
|
def removeLastComa(txt) {
|
|
return txt.substring(0, txt.size()-2)
|
|
}
|
|
def getMaxQuality (mapAudioIndexedByFormat) {
|
|
def formatSet = ["PCM", "MLP FBA" ,"DTS", "FLAC", "AC-3", "E-AC-3", "EAC3", "AAC", "MPEG Audio", "MP3"]
|
|
for (cFormat in formatSet) {
|
|
if (mapAudioIndexedByFormat.containsKey(cFormat)){
|
|
def difChannelsList = mapAudioIndexedByFormat[cFormat]
|
|
return difChannelsList.size()==1 ? difChannelsList[0] : getBestChannelFromList(difChannelsList)
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
def printAudio (audio2Print) {
|
|
def formato_audio = audio2Print.Format_Commercial
|
|
.replaceAll(/Dolby Digital/, 'Dolby')
|
|
.replaceAll(/ Plus/, 'P')
|
|
.replaceAll(/DTS-HD Master Audio/, 'DTS-MA')
|
|
.replaceAll(/DTS-HD High Resolution Audio/, 'DTS-HR')
|
|
.replaceAll(/MPEG Audio/, 'MPEG')
|
|
.replaceAll(/HE-AAC/, 'hAAC')
|
|
.replaceAll(/ with Dolby Atmos/, 'Atmos')
|
|
.replaceAll(/TrueHD/, 'tHD')
|
|
def canales = audio2Print.Channels.replace(2:'2.0', 6:'5.1', 8:'7.1')
|
|
return formato_audio + ' ' + canales
|
|
}
|
|
def getBestChannelFromList (audiosFormatFound) {
|
|
def bestChanel
|
|
def currentValue=0
|
|
for (myAudio2 in audiosFormatFound) {
|
|
if (myAudio2.Channels>currentValue) {
|
|
currentValue = myAudio2.Channels
|
|
bestChanel = myAudio2
|
|
}
|
|
}
|
|
return bestChanel
|
|
}
|
|
def countAudiosInMap(audMap){
|
|
int count=0
|
|
for (aud in audMap) count += aud.value.size()
|
|
return count
|
|
}
|
|
/********* SUBS ***************/
|
|
def handleSub(sub, capturedSubs) {
|
|
def lang = sub.Language_String3 !=null ? sub.Language_String3
|
|
: (sub.Title=~/(?i).+spa.+/?'spa': sub.Title.substring(0,3).toLowerCase())
|
|
if (sub.Title!=null && sub.Title=~/(?i).*latin.*/) lang='lat'
|
|
def forced = sub.title!=null ? sub.title.toLowerCase().contains("forzado") : false
|
|
if (!capturedSubs.containsKey(lang)) {
|
|
capturedSubs[lang] = lang+(forced?' F':'')
|
|
} else {
|
|
def existing=capturedSubs[lang]
|
|
def newTxt=''+existing
|
|
if (!existing.contains('+')) newTxt += '+'
|
|
if (forced && !existing.contains('F')) newTxt += ' F'
|
|
capturedSubs[lang]=newTxt.replace(" F+","+F")
|
|
}
|
|
}
|
|
|
|
/***********/
|
|
/* 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
|
|
}
|
|
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!=null ? oldId == newId.toString() : true
|
|
}
|
|
/***********/
|