OSDN Git Service

add caption.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2mkv.py
index 68c9940..f698666 100644 (file)
@@ -2,12 +2,11 @@
 # coding: UTF-8
 # Rec10 TS Recording Tools
 # Copyright (C) 2009 Yukikaze
-import sys
+import os
 import commands
 import tv2avi
 import os.path
 import time
-import shutil
 import re
 import recdblist
 import configreader
@@ -26,41 +25,86 @@ def avi2mkv(pin,pout,opt):
         isvfr=1
     exe = configreader.getpath("mkvmerge")
     exes=[]
+    txt=""
+    os.environ['LANG']="ja_JP.UTF-8"
     if isvfr==1:
         wineexe=configreader.getpath("wine")
         cfr2tc=configreader.getpath("cfr2tc")
+        cap2ass=configreader.getpath("Caption2Ass")
         pin120=pin.replace(".avi",".120.avi")
         pints=pin.replace(".avi",".ts")
         pintimecode=pin.replace(".avi",".timecode.txt")
+        pincap=pin.replace(".avi",".srt")
         pinaac=pin.replace(".avi",".aac")
-        exes.append("ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'")
-        exes.append(wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2")
-        exes.append(exe +" -o '"+pout+u"'  --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0")
+        e0="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"
+        e1=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
+        e2=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" Z:\\"+pincap+"\""
+        e3=exe +" -o '"+pout+u"'  --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0"
+        e3s=exe +" -o '"+pout+u"'  --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --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"
+        #exes.append(exe +" -o '"+pout+u"'  --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:0 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0")
         #exes.append(doexe = exe + u" -o '" + pout + u"' --cues 0:all --forced-track 0:no --default-duration 0:120000/1001fps -d 0 -A -S '" + pin + u"' --sync 0:0 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0")
+        execcomd(e0)
+        execcomd(e1)
+        execcomd(e2)
+        if os.path.exists(pincap):
+            execcomd(e3s)
+        else:
+            execcomd(e3)
+        if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
+            txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
+            ptmp=pin.replace(".avi",".noodml.avi")
+            e1="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
+            e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
+            e3=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" Z:\\"+pincap+"\""
+            e4=exe +" -o '"+pout+u"'  --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0"
+            e4s=exe +" -o '"+pout+u"'  --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --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"
+            recdblist.printutf8(e)
+            txt=txt+e+"\n"
+            cmdt=execcomd(e1)
+            cmdt=cmdt+execcomd(e2)
+            cmdt=cmdt+execcomd(e3)
+            if os.path.exists(pincap):
+                execcomd(e4s)
+            else:
+                execcomd(e4)
+            os.remove(ptmp)
+            txt=txt+cmdt+"\n"
     else:
-        exes.append(doexe = exe + u" -o '" + pout + u"' --cues 0:all --forced-track 0:no --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --track-order 0:0,0:1")
+        wineexe=configreader.getpath("wine")
+        pincap=pin.replace(".avi",".srt")
+        cap2ass=configreader.getpath("Caption2Ass")
+        pints=pin.replace(".avi",".ts")
+        e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" Z:\\"+pincap+"\""
+        e1=exe + u" -o '" + pout + u"' --forced-track 0:no --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --track-order 0:0,0:1"
+        e1s=exe + u" -o '" + pout + u"' --forced-track 0:no --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --forced-track 0:no -s 0 -A -D '"+pincap+"' --track-order 0:0,0:1,1:0"
+        txt=txt+execcomd(e0)
+        if os.path.exists(pincap):
+            txt=txt+execcomd(e1s)
+        else:
+            txt=txt+execcomd(e1)
     logo=pout.replace(".mkv",".log")
-    txt=""
-    os.environ['LANG']="ja_JP.UTF-8"
-    for e in exes:
-        ex= "nice -n 17 "+e
-        recdblist.printutf8(e)
-        txt=txt+e+"\n"
-        cmdt=""
-        try:
-            cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
-        except:
-            ""
-        txt=txt+cmdt+"\n"
-    if (isvfr==1 and (not os.path.exists(pin.replace(".avi",".120.avi"))) and (not os.path.exists(pout))):
+    """if (isvfr==1 and (not os.path.exists(pin.replace(".avi",".120.avi"))) and (not os.path.exists(pout))):
         exes=[]
-        exes.append(doexe = exe + u" -o '" + pout + u"' --cues 0:all --forced-track 0:no --default-duration 0:120000/1001fps -d 0 -A -S '" + pin + u"' --sync 0:0 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0")
+        exes.append(exe + u" -o '" + pout + u"' --cues 0:all --forced-track 0:no --default-duration 0:120000/1001fps -d 0 -A -S '" + pin + u"' --sync 0:0 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0")
         txt=txt+"120fps cfr exection\n"
-        try:
-            txt=txt+unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
-        except:
-            ""
+        for e2 in exes:
+            recdblist.printutf8(e2)
+            try:
+                txt=txt+unicode(commands.getoutput(e2.encode('utf-8')),'utf-8')
+            except:
+                ""
+    """
     txt = "\n####mkvmerge-log####\n"+txt
     f=open(logo,'a')
     f.write(txt.encode('utf-8'))
-    f.close()
\ No newline at end of file
+    f.close()
+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
\ No newline at end of file