OSDN Git Service

fix rename miss.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2avi.py
index 934a556..82357b4 100644 (file)
-#!/usr/bin/python
-# coding: UTF-8
-# Rec10 TS Recording Tools
-# Copyright (C) 2009 Yukikaze
-import time
-import chdb
-import configreader
-import datetime
-import os
-import re
-import ts2x264
-import ts2xvid
-import tv2ts
-import recdb
-def timetv2avi(pout, chtxt, btime, etime,opt):
-    bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
-    et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    #tsout=pout####
-    #print "4"+tsout
-    tnow = datetime.datetime.now()
-    wt = bt-tnow
-    waitt = wt.seconds-5
-    time.sleep(waitt)
-    tnow = datetime.datetime.now()
-    dt = et-tnow
-    rectime = dt.seconds-10
-    rectime = str(rectime)
-    #print tsout+".ts,"+chdb.chtxtsearch(chtxt)['ch']+","+chdb.chtxtsearch(chtxt)['csch']+","+rectime
-    tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], rectime)
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    pentaaudio = 0
-    if re.search("5",opt):
-        pentaaudio = 1
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search("\[二\]", pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    if opt=="":
-        opts=""
-        if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-            opts=opts+"S2"
-            if chtxt == "disch":
-                ""
-            elif chtxt == "hisch":
-                ""
-            else:
-                opts=opts+"a"
-        else:
-            opts=opts+"Ha2"
-    else:
-        opts=opt
-    if re.search("x",opt):
-        makexvid = 0
-    else:
-        makexvid = 1
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if pentaaudio ==1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    """
-    if makexvid==1:
-        ts2xvid.ts2xvid(aviin, pout,opts)
-    else:
-        ts2x264.ts2x264(aviin, pout,opts)
-        """
-    bt=datetime.datetime.now()+datetime.timedelta(seconds=600)
-    btime=bt.strftime("%Y-%m-%d %H:%M:%S")
-    et=datetime.datetime.now()+datetime.timedelta(seconds=600)
-    etime=et.strftime("%Y-%m-%d %H:%M:%S")
-    title=os.path.split(tsout)[1]
-    #try:
-    #    os.remove(aviin)
-    #except:
-    #    ""
-def tv2avi(pout, chtxt, btime, etime,opt):
-    bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
-    et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
-    dt = et-bt
-    time = dt.seconds-10
-    time = str(time)
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    #tsout=pout####
-    #print "4"+tsout
-    #print tsout+".ts,"+chdb.chtxtsearch(chtxt)['ch']+","+chdb.chtxtsearch(chtxt)['csch']+","+time
-    tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], time)
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    pentaaudio = 0 
-    if re.search("5",opt):
-        pentaaudio = 1
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search('\[二\]', pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    opts=""
-    if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-        opts=opts+"S2"
-        if chtxt == "disch":
-            ""
-        elif chtxt == "hisch":
-            ""
-        else:
-            opts=opts+"a"
-    else:
-        opts=opts+"Ha2"
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if pentaaudio ==1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    ts2x264.ts2x264(aviin, pout,opts)
-    #os.remove(aviin)
-def b252avi(pout, chtxt,opt):
-    #bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
-    #et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    #tsout=pout####
-    #print "4"+tsout
-    #tnow = datetime.datetime.now()
-    #wt = bt-tnow
-    #waitt = wt.seconds-5
-    #time.sleep(waitt)
-    #tnow = datetime.datetime.now()
-    #dt = et-tnow
-    #rectime = dt.seconds-10
-    #rectime = str(rectime)
-    tv2ts.b252ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'])
-    #tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], rectime)
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    pentaaudio = 0
-    if re.search("5",opt):
-        pentaaudio = 1
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search('\[二\]', pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    if opt=="":
-        opts=""
-        if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-            opts=opts+"S2"
-            if chtxt == "disch":
-                ""
-            elif chtxt == "hisch":
-                ""
-            else:
-                opts=opts+"a"
-        else:
-            opts=opts+"Ha2"
-    else:
-        opts=opt
-    if re.search("x",opt):
-        makexvid = 0
-    else:
-        makexvid = 1
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if pentaaudio ==1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if makexvid==1:
-        ts2xvid.ts2xvid(aviin, pout,opts)
-    else:
-        ts2x264.ts2x264(aviin, pout,opts)
-    #try:
-    #    os.remove(aviin)
-    #except:
-    #    ""
-
-    """
-    pout = pout.encode('utf-8')
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    #print tsout+".ts,"+chdb.chtxtsearch(chtxt)['ch']+","+chdb.chtxtsearch(chtxt)['csch']+","+time
-    tv2ts.b252ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'])
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search('\[二\]', pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    opts=""
-    if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-        opts=opts+"S2"
-        if chtxt == "disch":
-            ""
-        elif chtxt == "hisch":
-            ""
-        else:
-            opts=opts+"a"
-    else:
-        opts=opts+"Ha2"
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    ts2x264.ts2x264(aviin, pout,opts)
-    #os.remove(aviin)
-
-    """
-
-def dualaudiots2avi(pin, pout):
-    bontsdemux = configreader.getpath('bontsdemux')
-    wine = configreader.getpath('wine')
-    cmdwine = configreader.getpath('cmdwine')
-    bonpin = "Z:\\" + pin[1:]
-    outf = os.path.splitext(pin)[0]
-    bonpout = "Z:\\" + outf[1:]
-    exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit"
-    #print exe
-    exe = 'xvfb-run -a ' + exe
-    #exe='export Display=:2&&'+exe
-    print exe
-    os.system(exe)
-    ffpin1 = pin.replace("ts", "wav")
-    ffpin2 = pin.replace("ts", "m2v")
-    exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
-    #print exe
-    os.system(exe)
-    os.remove(ffpin1)
-    os.remove(ffpin2)
-
-def pentaaudiots2avi(pin, pout):
-    bontsdemux = configreader.getpath('bontsdemux')
-    wine = configreader.getpath('wine')
-    cmdwine = configreader.getpath('cmdwine')
-    bonpin = "Z:\\" + pin[1:]
-    outf = os.path.splitext(pin)[0]
-    bonpout = "Z:\\" + outf[1:]
-    exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 3 -o \"" + bonpout + "\" -start -quit"
-    #print exe
-    exe = 'xvfb-run -a ' + exe
-    #exe='export Display=:2&&'+exe
-    print exe
-    os.system(exe)
-    ffpin1 = pin.replace("ts", "wav")
-    ffpin2 = pin.replace("ts", "m2v")
-    exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
-    #print exe
-    os.system(exe)
-    os.remove(ffpin1)
-    os.remove(ffpin2)
-
+#!/usr/bin/python\r
+# coding: UTF-8\r
+# Rec10 TS Recording Tools\r
+# Copyright (C) 2009-2010 Yukikaze\r
+import commands\r
+import datetime\r
+import os\r
+import re\r
+import shutil\r
+import time\r
+import os.path\r
+import traceback\r
+\r
+import chdb\r
+import configreader\r
+import status\r
+import ts2x264\r
+import tv2ts\r
+import recdblist\r
+import tv2audio\r
+\r
+\r
+global Bitrate_SD\r
+global Bitrate_HD\r
+global Bitrate_FHD\r
+global Bitrate_Short\r
+global Bitrate_LowHD\r
+Bitrate_SD = 1250\r
+Bitrate_HD = 3750\r
+Bitrate_LowHD = 2500\r
+Bitrate_FHD = 5000\r
+Bitrate_Short = 1250\r
+def timetv2b25(pout, chtxt, btime, etime, opt):\r
+    """\r
+    poutはタイトル\r
+    """\r
+    bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")\r
+    et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")\r
+    extt = os.path.splitext(pout)\r
+    tsout = extt[0]\r
+    tnow = datetime.datetime.now()\r
+    wt = bt-tnow\r
+    waitt = wt.seconds\r
+    if waitt>0:\r
+        time.sleep(waitt)\r
+    tnow = datetime.datetime.now()\r
+    dt = et-tnow\r
+    rectime = dt.seconds-5\r
+    rectime = str(rectime)\r
+    tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.searchCHFromChtxt(chtxt)['ch'], rectime)\r
+def b252ts(pout, chtxt, btime, etime, opt):\r
+    """\r
+    poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。)\r
+    """\r
+    #status.setB25Decoding(status.getB25Decoding() + 1)\r
+    status.changeB25Decoding(1)\r
+    try:\r
+        try:\r
+            ch=chtxt.split("_")[0]\r
+            csch=chtxt.split("_")[1]\r
+        except:\r
+            ch=0\r
+            csch=0\r
+        tv2ts.b252ts(pout + ".ts", ch, csch)\r
+        tsout = pout\r
+        aviin = pout + ".ts"\r
+        dualaudio = 0\r
+        pentaaudio = 0\r
+        singleaudiosplit = 0\r
+        if re.search("5", opt):\r
+            pentaaudio = 1\r
+        if re.search("d", opt):\r
+            dualaudio = 1\r
+        if re.search(u"\[二\]", pout):\r
+            dualaudio = 1\r
+        elif re.search(u'(二)', pout):\r
+            dualaudio = 1\r
+        elif re.search(u'\(二\)', pout):\r
+            dualaudio = 1\r
+        if dualaudio == 1:\r
+            tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)\r
+        if pentaaudio == 1:\r
+            tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)\r
+    except Exception, inst:\r
+        recdblist.addCommonlogEX("Error", "b252ts(tv2avi.py)", str(type(inst))+traceback.format_exc(), str(inst))\r
+    status.changeB25Decoding(-1)\r
+def ts2avi(pin, pout, opt):\r
+    status.changeEncoding(1)\r
+    try:\r
+        ts2x264.ts2x264(pin, pout, opt)\r
+    except Exception, inst:\r
+        recdblist.printutf8("error occures in tv2avi.py ts2avi")\r
+        recdblist.printutf8(str(type(inst)))\r
+        recdblist.printutf8(str(inst)+traceback.format_exc())\r
+    status.changeEncoding(-1)\r
+def ts2raw(pin, pout, opt):\r
+    status.changeEncoding(1)\r
+    try:\r
+        ts2x264.ts2x264(pin, pout, opt)\r
+    except Exception, inst:\r
+        recdblist.printutf8("error occures in tv2avi.py ts2raw")\r
+        recdblist.printutf8(str(type(inst)))\r
+        recdblist.printutf8(str(inst)+traceback.format_exc())\r
+    status.changeEncoding(-1)\r
+\r