Code: Select all
Title : Dolby Digital Plus Audio / 7.1 / 48 kHz / 1280 kbps
Might be useful, but probably won't be defined for the vast majority of files.
Code: Select all
Title : Dolby Digital Plus Audio / 7.1 / 48 kHz / 1280 kbps
Code: Select all
{
def codecList =
[
'MP3' : 'mp3',
'FLAC' : 'flac',
'PCM' : 'pcm',
'AAC LC' : 'aac',
'AAC LC SBR' : 'aac',
'AC 3' : 'ac3',
'AC 3 Dep' : 'eac3',
'E AC 3' : 'eac3',
'E AC 3 JOC' : 'eac3 Atmos',
'DTS' : 'dts',
'DTS 96 24' : 'dts',
'DTS ES' : 'dtses',
'DTS ES XXCH' : 'dtses',
'DTS XBR' : 'dts',
'DTS ES XBR' : 'dtses',
'DTS ES XXCH XBR' : 'dtses',
'DTS XLL' : 'dts',
'DTS ES XLL' : 'dtses',
'DTS ES XXCH XLL' : 'dtses',
'DTS XLL X' : 'dtsx',
'MLP FBA' : 'truehd',
'MLP FBA 16 ch' : 'truehd Atmos'
]
def filter = { [it.lang, it.codec, it.ch, it.objects] }
def audioStreams = []
def audioClean = { it.replaceAll(/[\p{Pd}\p{Space}]/, ' ').replaceAll(/\p{Space}{2,}/, ' ').slash(' ') }
def channelClean = { it.replaceAll(/Debug.+|Object\sBased\s?\/?|(\d+)?\sobjects\s\/\s|0.(?=\d.\d)|20/).replaceAll(/6.0/,'5.1').replaceAll(/8.0/,'7.1')}
def oneStream = { it.collect{ filter(it) }*.minus(null).unique().flatten().join(' ') }
def dString = { it.toDouble().toString() }
def toInt = { it.toInteger() }
audio.collect{ au ->
def codec = audioClean(any{ au['CodecID/Hint'] }{ au['Format'] })
def format_profile = any{ audioClean(au['Format_AdditionalFeatures'])}{}
def String ch = any{ channelClean(au.ChannelPositionsString2).tokenize('\\/')*.toDouble().toString().sum() }
{ channelClean(dString(au.ChannelsOriginal)) } { channelClean(dString(au.Channels)) }
def chFilter = (( ( (ac == 'AAC'||ac == 'MP3') && ch != '2.0') || ( (ac == 'AC3'||ac == 'EAC3'||ac == 'DTS'||ac == 'TrueHD'||ac == 'MLPFBA') && ch != '5.1' ) ) ? ch : null)
def combined = allOf{codec}{format_profile}.join(' ')
audioStreams << ['index' : codecList.findIndexOf {it.key == combined}, 'default' : au['default'][0].toBoolean(),
'codec' : codecList.get(combined, 'UNKNOWN_FORMAT'), 'combined' : combined, 'ch' : ch,
'bitrate' : any{toInt(au.BitRate)}{toInt(au.BitRate_Maximum)}{au.FrameRate.toDouble()}{null},
'objects' : any{'[' + au['NumberOfDynamicObjects'] + ' Objs]'}{null}, 'lang' : any{au.'LanguageString3'.upper().replaceAll("SPA","ESP")}{null} ]
return audioStreams
}
def allStreams = audioStreams.collect{ filter(it) }*.minus(null).unique()*.join(' ')
def preferredStream = oneStream(audioStreams.findAll{ it.index == audioStreams.index.max() })
def bestBitRate = oneStream(audioStreams.findAll{ it.bitrate == audioStreams.bitrate.max() })
def defaultStream = oneStream(audioStreams.findAll{it.default == true})
allStreams.join(' ').space(' ')
preferredStream.space(' ')
defaultStream.space(' ')
bestBitRate.space(' ')
[bestBitRate, preferredStream].unique().join(' ')
[defaultStream, bestBitRate].unique().join(' ')
}