OSDN Git Service

change function name.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2mkv.py
index 01911d0..0bcc9b2 100644 (file)
 # coding: UTF-8
 # Rec10 TS Recording Tools
 # Copyright (C) 2009-2010 Yukikaze
-import status
 import os
-import commands
-import tv2avi
 import os.path
-import time
-import re
-import recdblist
+import tv2mp4
 import configreader
+import subprocess
+import auto_process
 def ts2mkv(pin, pout, opt):
-    dir=os.path.split(pout)[0]
-    title=os.path.split(pout)[1]
-    title=os.path.splitext(title)[0]
-    tpraw=os.path.join(dir, title+".264")
-    tpmkv=os.path.join(dir, title+".mkv")
-    if os.path.isfile(pin) and os.path.getsize(pin)>10*1000:
-        tv2avi.ts2raw(pin, tpraw, opt)
-        time.sleep(10)
-        if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000:
-            raw2mkv(tpraw, tpmkv, opt)
-def raw2mkv(pin,pout,opt):#x264
-    dir=os.path.split(pout)[0]
-    title=os.path.split(pout)[1]
-    title=os.path.splitext(title)[0]
-    duration="--default-duration 0:30000/1001fps "
-    ffmpeg=configreader.getpath("ffmpeg")
-    isdualaac=0
-    ispentaaudio=0
-    if re.search("a",opt):
-        duration="--default-duration 0:24000/1001fps "
-    elif re.search("v",opt):
-        duration="--default-duration 0:24000/1001fps "
-    if re.search("d",opt):
-        isdualaac=1
-        duration="--default-duration 0:30000/1001fps "##ffmpegが24fpsに対応していないための措置
-    elif re.search("5",opt):
-        ispentaaudio=1
-        duration="--default-duration 0:30000/1001fps "##ffmpegが24fpsに対応していないための措置
-    exe = configreader.getpath("mkvmerge")
-    txt=""
-    txt2=""
-    os.environ['LANG']="ja_JP.UTF-8"
-    if isdualaac==1:
-        wineexe=configreader.getpath("wine")
-        pincap=pin.replace(".264",".srt")
-        try:
-            cap2ass=configreader.getpath("caption2ass")
-        except:
-            cap2ass=""
-        pints=pin.replace(".264",".ts")
-        paac1=pin.replace(".264","_1.aac")
-        paac2=pin.replace(".264","_2.aac")
-        recdblist.printutf8(paac1)
-        if not os.path.exists(paac1):
-            paac1=pin.replace(".264","_1.mp3")
-        if not os.path.exists(paac2):
-            paac2=pin.replace(".264","_2.mp3")
-        e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
-        e1=exe +" -o \""+pout+u"\" --forced-track 0:no "+duration+"-d 0 -A -S \""+pin+"\" --forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --track-order 0:0,1:1,2:1"
-        e1s=exe +" -o \""+pout+u"\" --forced-track 0:no "+duration+"-d 0 -A -S \""+pin+"\" --forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --forced-track 0:no -s 0 -D -A \""+pincap+"\" --track-order 0:0,1:1,2:1,3:0"
-        if os.path.isfile(cap2ass):
-            txt=txt+execcomd(e0)
-        if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
-            txt2=txt2+u"\n Cmd:"+e1s+u"\n"+execcomd(e1s)
-        else:
-            txt2=txt2+u"\n Cmd:"+e1+u"\n"+execcomd(e1)
-    elif ispentaaudio==1:
-        wineexe=configreader.getpath("wine")
-        pincap=pin.replace(".264",".srt")
-        try:
-            cap2ass=configreader.getpath("caption2ass")
-        except:
-            cap2ass=""
-        pints=pin.replace(".264",".ts")
-        paac1=pin.replace(".264","_1.aac")
-        paac2=pin.replace(".264","_2.aac")
-        recdblist.printutf8(paac1)
-        if not os.path.exists(paac1):
-            paac1=pin.replace(".264","_1.mp3")
-        if not os.path.exists(paac2):
-            paac2=pin.replace(".264","_2.mp3")
-        e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
-        e1=exe +" -o \""+pout+u"\" --forced-track 0:no "+duration+"-d 0 -A -S \""+pin+"\" --forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --track-order 0:0,1:1,2:1"
-        e1s=exe +" -o \""+pout+u"\" --forced-track 0:no "+duration+"-d 0 -A -S \""+pin+"\" --forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --forced-track 0:no -s 0 -D -A \""+pincap+"\" --track-order 0:0,1:1,2:1,3:0"
-        if os.path.isfile(cap2ass):
-            txt=txt+execcomd(e0)
-        if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
-            txt2=txt2+u"\n Cmd:"+e1s+u"\n"+execcomd(e1s)
-        else:
-            txt2=txt2+u"\n Cmd:"+e1+u"\n"+execcomd(e1)
-    else:
-        wineexe=configreader.getpath("wine")
-        pincap=pin.replace(".264",".srt")
-        try:
-            cap2ass=configreader.getpath("caption2ass")
-        except:
-            cap2ass=""
-        pints=pin.replace(".264",".ts")
-        pinaac=pin.replace(".264",".aac")
-        e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
-        e1=ffmpeg+" -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\""
-        e2=exe +" -o \""+pout+u"\" --forced-track 0:no "+duration+"-d 0 -A -S \""+pin+"\" --forced-track 0:no -a 0 -D -S \""+pinaac+"\" --track-order 0:0,1:0"
-        e2s=exe +" -o \""+pout+u"\" --forced-track 0:no "+duration+"-d 0 -A -S \""+pin+"\" --forced-track 0:no -a 0 -D -S \""+pinaac+"\" --forced-track 0:no -s 0 -D -A \""+pincap+"\" --track-order 0:0,1:0,2:0"
-        if os.path.isfile(cap2ass):
-            txt=txt+execcomd(e0)
-        txt=txt+execcomd(e1)
-        if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
-            txt2=txt2+u"\n Cmd:"+e2s+"\n"+execcomd(e2s)
-            recdblist.printutf8(e2s)
-        else:
-            txt2=txt2+u"\n Cmd:"+e2+"\n"+execcomd(e2)
-            recdblist.printutf8(e2)
-    recdblist.addlog(pout, txt, "mkvmerge-log1")
-    recdblist.addlog(pout, txt2, "mkvmerge-log2")
-    if status.getSettings_auto_del_tmp()==1:
-        if os.path.exists(pout):
-            if os.path.getsize(pout)>100*1000*1000:
-                deltitle(dir,title)
-def execcomd(cmd):
-    txt=""
-    cmdt=u"nice -n 17 "+cmd
-    try:
-        txt=u"Cmd : "+cmd+"\n"
-        txt2=commands.getoutput(cmdt.encode('utf-8'))
-        txt=txt+unicode(txt2,"utf-8")+"\n"
-    except:
-        ""
-    return txt
-def deltitle(path,title):
-    dp=[]
-    dp.append(os.path.join(path,title+".avi"))
-    dp.append(os.path.join(path,title+".264"))
-    dp.append(os.path.join(path,title+".120.avi"))
-    dp.append(os.path.join(path,title+".noodml.avi"))
-    dp.append(os.path.join(path,title+".aac"))
-    dp.append(os.path.join(path,title+".m2v"))
-    dp.append(os.path.join(path,title+"_1.aac"))
-    dp.append(os.path.join(path,title+"_2.aac"))
-    dp.append(os.path.join(path,title+"_1.mp3"))
-    dp.append(os.path.join(path,title+"_2.mp3"))
-    dp.append(os.path.join(path,title+".srt"))
-    if configreader.getenv("remove_ts")=="1":
-        dp.append(os.path.join(path,title+".ts"))
-    if os.path.exists(os.path.join(path,title+".ts"))and os.path.exists(os.path.join(path,title+".ts.b25")):
-        if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
-            if os.path.getsize(os.path.join(path,title+".ts"))>1000*1000*100:
-                dp.append(os.path.join(path,title+".ts.b25"))
-    if os.path.exists(os.path.join(path,title+".mkv")):
-        if os.path.getsize(os.path.join(path,title+".mkv"))>1000*1000*10:
-            for ip in dp:
-                try:
-                    os.remove(ip)
-                except:
-                    ""
-    
\ No newline at end of file
+    tpout=pout.replace(".mkv",".mp4")
+    tv2mp4.ts2mp4(pin, tpout, opt)
+    mp42mkv(pout, tpout)
+    if os.path.exists(pout) and os.path.getsize(pout)>os.path.getsize(tpout)*0.9:
+        os.remove(tpout)
+def mp42mkv(pmkv,pmp4):
+    exe = configreader.getPathSetting("mkvmerge")
+    e1=exe +" -o \""+pmkv+u"\" \""+pmp4+"\""
+    p=subprocess.Popen(e1,shell=True)
+    os.waitpid(p.pid, 0)