-import time
#!/usr/bin/python
# coding: UTF-8
# Rec10 TS Recording Tools
-# Copyright (C) 2009 Yukikaze
-import sys
+# Copyright (C) 2009-2010 Yukikaze
+import status
+import os
import commands
import tv2avi
+import os.path
+import time
+import re
+import recdblist
+import configreader
def ts2mkv(pin, pout, opt):
- tv2avi.ts2avi(pin, pout.replace(".mkv",".avi"), opt)
+ dir=os.path.split(pout)[0]
+ title=os.path.split(pout)[1]
+ title=os.path.splitext(title)[0]
+ ##use avi
+ """tpavi=os.path.join(dir,title+".avi")
+ tpmkv=os.path.join(dir, title+".mkv")
+ tv2avi.ts2avi(pin, tpavi, opt)
+ time.sleep(10)
+ avi2mkv(tpavi,tpmkv,opt)"""
+ tpraw=os.path.join(dir, title+".264")
+ tpmkv=os.path.join(dir, title+".mkv")
+ tv2avi.ts2raw(pin, tpraw, opt)
time.sleep(10)
- avi2mkv(pout.replace(".mkv",".avi"),pout)
-def avi2mkv(pin,pout):
- exe = "mkvmerge"
- #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
- doexe = exe + u" -o '" + pout + u"' '" + pin + u"'"
- doexe = "nice -n 17 " + doexe
- print doexe
- logo=pin.replace(".avi",".log")
- txt = commands.getoutput(doexe)
- txt = "\n####mkvmerge-log####\n"+txt
- f=open(logo,'a')
- f.write(txt)
- f.close()
- sys.stdout.flush()
\ No newline at end of file
+ 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=""
+ os.environ['LANG']="ja_JP.UTF-8"
+ if isdualaac==1:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".264",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ 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):
+ txt=txt+u"\n Cmd:"+e1s+u"\n"+execcomd(e1s)
+ else:
+ txt=txt+u"\n Cmd:"+e1+u"\n"+execcomd(e1)
+ elif ispentaaudio==1:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".264",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ 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):
+ txt=txt+u"\n Cmd:"+e1s+u"\n"+execcomd(e1s)
+ else:
+ txt=txt+u"\n Cmd:"+e1+u"\n"+execcomd(e1)
+ else:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".264",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ 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):
+ txt=txt+u"\n Cmd:"+e2s+"\n"+execcomd(e2s)
+ recdblist.printutf8(e2s)
+ else:
+ txt=txt+u"\n Cmd:"+e2+"\n"+execcomd(e2)
+ recdblist.printutf8(e2)
+ recdblist.addlog(pout, txt, "mkvmerge-log")
+ logo=pout.replace(".mkv",".log")
+ if status.getSettings_auto_del_tmp()==1:
+ if os.path.exists(pout):
+ if os.path.getsize(pout)>100*1000*1000:
+ deltitle(dir,title)
+def avi2mkv(pin,pout,opt):
+ dir=os.path.split(pout)[0]
+ title=os.path.split(pout)[1]
+ title=os.path.splitext(title)[0]
+ isdualaac=0
+ ispentaaudio=0
+ if re.search("d",opt):
+ isdualaac=1
+ elif re.search("5",opt):
+ ispentaaudio=1
+ exe = configreader.getpath("mkvmerge")
+ txt=""
+ os.environ['LANG']="ja_JP.UTF-8"
+ if isdualaac==1:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".avi",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ pints=pin.replace(".avi",".ts")
+ paac1=pin.replace(".avi","_1.aac")
+ paac2=pin.replace(".avi","_2.aac")
+ recdblist.printutf8(paac1)
+ if not os.path.exists(paac1):
+ paac1=pin.replace(".avi","_1.mp3")
+ if not os.path.exists(paac2):
+ paac2=pin.replace(".avi","_2.mp3")
+ e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
+ e1=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 --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 -d 0 -A -S \""+pin+"\" --sync 0:0 --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):
+ txt=txt+execcomd(e1s)
+ else:
+ txt=txt+execcomd(e1)
+ elif ispentaaudio==1:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".avi",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ pints=pin.replace(".avi",".ts")
+ paac1=pin.replace(".avi","_1.aac")
+ paac2=pin.replace(".avi","_2.aac")
+ recdblist.printutf8(paac1)
+ if not os.path.exists(paac1):
+ paac1=pin.replace(".avi","_1.mp3")
+ if not os.path.exists(paac2):
+ paac2=pin.replace(".avi","_2.mp3")
+ e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
+ e1=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 --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 -d 0 -A -S \""+pin+"\" --sync 0:0 --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):
+ txt=txt+execcomd(e1s)
+ else:
+ txt=txt+execcomd(e1)
+ else:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".avi",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ pints=pin.replace(".avi",".ts")
+ pinaac=pin.replace(".avi",".aac")
+ e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
+ e1=ffmpeg+u" -i \""+pints+u"\" -vn -f aac -acodec copy \""+pinaac+"\""
+ e2=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 --forced-track 0:no -a 0 -D -S \""+pinaac+"\" --track-order 0:0,1:0"
+ e2s=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 --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):
+ txt=txt+execcomd(e2s)
+ else:
+ txt=txt+execcomd(e2)
+ recdblist.addlog(pout, txt, "mkvmerge-log")
+ logo=pout.replace(".mkv",".log")
+ 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 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