Many, Many titles

Everything related to MakeMKV
Post Reply
kryojenik
Posts: 1
Joined: Mon Jun 30, 2014 9:20 pm

Many, Many titles

Post by kryojenik »

I was recently wanted to play around with python and saw the discussion of trying to find the right title on Ender's Game. So, I hacked (and it is hackey) together this bit of python that helps out. You still need to pass it the correct running time, but it does find the correct title for Enders Game. If there are any other discs you'd like me to run through this with I'll see if I can.

It takes the output of makemkvcon -r info, filters on the supplied runtime, computes an md5 hash of the segments that are <1 GB in size and eliminated titles with duplicate segments. If you don't supply a running time, it will list out all the running times possible.

The script, or this method, may prove useful to someone here.

kryojenik

Code: Select all

$ ./right_title.py /Volumes/Storage/Questionable/ENDERS_GAME/ 1:53:48
Possible, good titles are:
159 - 1:53:48 - 00815.mpls - 502,512,510,516,506,509,515,523,521,513,520,503,507,522,514

Code: Select all

#! /usr/bin/env python

from subprocess import check_output
import csv
import os
import sys

if len(sys.argv) > 1:
    path = sys.argv[1]
else:
    print "You at least need to specify a path"
    quit()

if len(sys.argv) > 2:
    rt = sys.argv[2]

keyMap = { '8': "Chapters", '9': "Runtime", '10': "Size", '16': "Playlist", '25': "SegmentCount", '26': "SegmentMap" }
maxsize = 1000*1000*1000 # 1 GB
fulltitles =  {}


def filterruntime(time, it):
    out = []
    for t,v in it.iteritems():
        if v['Runtime'] == time:
            out.append(t)
    return out

# Start primary logic
diskInfo=check_output(["makemkvcon", "--noscan", "--minlength=1800", "-r", "info", "file:" + path]).rstrip().splitlines(True)

#with open("endersgame.tinfo", "r") as f:
#    diskInfo=f.readlines()

reader = csv.reader(diskInfo)
for row in reader:
    if row[0].startswith("TINFO"):
        ik = row[1]
        if ik in keyMap:
            ik = keyMap[ik]
            k = row[0].split(":")[1]
            if k in fulltitles:
                if ik == 'SegmentMap':
                    fulltitles[k][ik] = row[3].split(",")
                else:
                    fulltitles[k][ik] = row[3]
            else:
                fulltitles[k] = {ik: row[3], 'HashCount': {}}

# Pick a specific runtime
if 'rt' in locals():
    titles = filterruntime(rt,fulltitles)
else:
    runtimes = {}
    for t,v in fulltitles.iteritems():
        if not v['Runtime'] in runtimes:
            runtimes[v['Runtime']] = 1
        else:
            runtimes[v['Runtime']] += 1
    print "Runtimes and the number of associated titles."
    for r in sorted(runtimes):
        print r + ":", runtimes[r]
    quit()

segmentData = {}
for t in titles:
    for s in fulltitles[t]['SegmentMap']:
        if not s in segmentData:
            segmentData[s] = {'UsedBy': [t]}
        else:
            segmentData[s]['UsedBy'].append(t)

for s,v in segmentData.iteritems():
    bn = ("0" * (5 - len(s))) + s + ".m2ts"
    f = path + "BDMV/STREAM/" + bn
    v['Size'] = os.stat(f).st_size
    if v['Size'] < maxsize:
        v['Hash'] = check_output(["md5sum", f]).split()[0]
        for u in v['UsedBy']:
            if not v['Hash'] in fulltitles[u]['HashCount']:
                fulltitles[u]['HashCount'][v['Hash']] = 1
            else:
                fulltitles[u]['HashCount'][v['Hash']] += 1

possible = []
for t in titles:
    good = True
    for h,v in fulltitles[t]['HashCount'].iteritems():
        if v>1:
            good = False
    if good:
        possible.append(t)

print("Possible, good titles are:")
for t in possible:
    title = fulltitles[t]
    print t,"-",title['Runtime'],"-",title['Playlist'],"-",",".join(title['SegmentMap'])
Post Reply