OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / trunk / src / tv2ts.py
index 189204f..bb87965 100644 (file)
 #!/usr/bin/python
 # coding: UTF-8
+# Rec10 TS Recording Tools
+# Copyright (C) 2009-2012 Yukikaze
 #import sys # モジュール属性 argv を取得するため
-import os
-import shutil
 import commands
-import configreader
-#import japanesenkf
-import random
-import base64
-#import re
-#import glob
+import os
+import os.path
 import time
-import hashlib
-#japanesenkf.overrideEncodings()
+import traceback
 
-mypath=str(os.path.dirname(os.path.abspath(__file__)))+"/"
-def tv2tsmix(pout,ch,time):
-    tv2b25ts(pout+".b25",ch,time)
-    b252tsmix(pout+".b25",pout)
-    #os.remove(pout+".b25")
-    if os.access(pout, os.F_OK):
+import configreader
+import status
+import recdblist
+import recording_earth_pt1
+mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
+def tv2tsmix(pout, ch, time,tsid="0",getlog=0):
+    tv2b25ts(pout + ".b25", ch, time,tsid)
+    txt=b252tsmix(pout + ".b25", pout)
+    return txt
+    #if os.access(pout, os.F_OK):
+    #    try:
+    #        os.remove(pout + ".b25")
+    #    except:
+    #        ""
+def tv2ts(pout, ch, csch, time,tsid):
+    if ch.replace(" ","").replace("CS","").isdigit():
+        if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+            status.changeBSCSRecording(1)
+        else:
+            status.changeTERecording(1)
         try:
-            os.remove(pout+".b25")
-        except:
-            ""
-def tv2ts(pout,ch,csch,time):
-    #print "1"+pout
-    #print "2"+temp[0]
-    #print "3"+temp[1]
-    #tv2tsmix(temp[0]+"mix."+temp[1],ch,time)
-    #tsmix2ts(temp[0]+"mix."+temp[1],pout,csch)
-    #os.remove(temp[0]+"mix."+temp[1])
-    temp=pout.split(".")
-    #t=base64.b16encode(pout)
-    #t=t[0:30]
-    t=hashlib.md5(pout).hexdigest()
-    #m.update(pout)
-    #t=m.hexdigest()
-    #t=str(random.randint(10000,90000))
-    tempt=os.path.split(pout)
-    path=tempt[0]
-    tv2b25ts(pout+".b25",ch,time)
-    b252tsmix(pout+".b25",path+"/"+t+"."+temp[1])
-    tsmix2ts(path+"/"+t+"."+temp[1],pout,csch)
-    #os.remove(path+"/"+t+"."+temp[1])
+            tv2b25ts(pout + ".b25", ch, time,tsid)
+        except Exception, inst:
+            recdblist.addCommonlogEX(u"Error",u"tv2ts(tv2ts.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+        if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+            status.changeBSCSRecording(-1)
+        else:
+            status.changeTERecording(-1)
+    else:
+         ch="0"
+         csch="0"
+    b252tsmix(pout + ".b25", pout + ".tsmix")
+    tch="0"
+    if csch!=u"0":
+        tch=csch
+    elif ch==u"101":
+        tch="101"
+    elif ch==u"102":
+        tch="102"
+    #else:
+    #    tch=ch
+    tsmix2ts(pout + ".tsmix", pout, tch)
     if os.access(pout, os.F_OK):
         try:
-            os.remove(path+"/"+t+"."+temp[1])
+            #os.remove(path + "/" + t + ext)
+            ""
         except:
             ""
-
-def b252ts(pout,ch,csch):
-    temp=pout.split(".")
-    #m=hashlib.md5
-    #m.update(pout)
-    #t=m.hexdigest()
-    t=hashlib.md5(pout).hexdigest()
-    #t=base64.b16encode(pout)
-    #t=t[0:30]
-    #t=str(random.randint(10000,90000))
-    tempt=os.path.split(pout)
-    path=tempt[0]
-    #tv2b25ts(pout+".b25",ch,time)
-    b252tsmix(pout+".b25",path+"/"+t+"."+temp[1])
-    tsmix2ts(path+"/"+t+"."+temp[1],pout,csch)
-    #os.remove(path+"/"+t+"."+temp[1])
-    if os.access(pout, os.F_OK):
+def b252ts(pout, ch, csch):
+    b252tsmix(pout + ".b25", pout + ".tsmix")
+    tch=u"0"
+    if ch.replace(" ","").replace("CS","").isdigit():
+        if csch!=u"0":
+            tch=csch
+        elif ch==u"101":
+            tch=u"101"
+        elif ch==u"102":
+            tch=u"102"
+    else:
+        tch="0"
+    tsmix2ts(pout + ".tsmix", pout, tch)
+def tv2b25ts(pout, ch, time,tsid):
+    if recording_earth_pt1.useDVB()==0:
+        exe = configreader.getConfPath('recpt1')
+        if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+            status.changeBSCSRecording(1)
+        else:
+            status.changeTERecording(1)
+        try:
+            doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
+            recdblist.printutf8(doexe)
+            recdblist.addLog(pout, doexe, u"recpt1ログ-コマンド")
+            recdblist.addLog(pout, unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8'), u"recpt1ログ-詳細")
+        except Exception, inst:
+            recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst))
+        if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+            status.changeBSCSRecording(-1)
+        else:
+            status.changeTERecording(-1)
+    elif recording_earth_pt1.useDVB()==1:
+        if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+            status.changeBSCSRecording(1)
+        else:
+            status.changeTERecording(1)
         try:
-            os.remove(path+"/"+t+"."+temp[1])
+            recording_earth_pt1.record(ch,tsid,pout,time,0)
+        except Exception, inst:
+            recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst))
+        if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+            status.changeBSCSRecording(-1)
+        else:
+            status.changeTERecording(-1)
+    if os.path.exists(pout):
+        try:
+            os.chmod(pout,0755)
         except:
             ""
-
-def tv2b25ts(pout,ch,time):
-    exe=configreader.getpath('recpt1')
-    #print exe+' '+ch
-    doexe=exe+' '+ch+' '+time+' \''+pout+'\''
-    #print doexe
-    os.system(doexe)
-def tv2b25ts_b25(pout,ch,time):
-    exe=configreader.getpath('recpt1')
-    #print exe+' '+ch
-    doexe=exe+' --b25 '+ch+' '+time+' \''+pout+'\''
-    #print doexe
-    os.system(doexe)
-def b252tsmix(pin,pout):
-    #print "t1"
-    exe=configreader.getpath('b25')
-    doexe=exe.encode('utf-8')+u' \''+pin.encode('utf-8')+u'\' \''+pout.encode('utf-8')+u'\''
-    #print doexe
-    doexe="/usr/bin/nice -n 17 "+doexe
-    txt=commands.getoutput(doexe)
-
-    #os.system(doexe)
-    #print "t2"
-def tsmix2ts(pin,pout,csch):#csch=0ならcsの処理をしない
-    wine=configreader.getpath('wine')
-    exe=configreader.getpath('splitt')
-    if csch == "0":
-        time.sleep(1)
-        #mvexe="mv \'"+outpath+"\' \'"+pout+"\'"
-        #print mvexe
-        #print outpath
-        #os.rename(outpath,pout)
-        #i=0
-        shutil.move(pin.encode('utf-8'),pout.encode('utf-8'))
-    else:
-        csopt='-CS'+str(csch)+" "
-        dirname=os.path.dirname(pin)
-        filename=os.path.basename(pin)
-        fn=os.path.splitext(filename)[0]               
-        fileext=os.path.splitext(filename)[1]
-        outpath=dirname+"/"+fn+'_CS1('+str(csch)+')'+fileext
-        #print dirname+" : "+filename+" : "+fn+" : "+fileext
-        path=dirname
-        outpath=os.path.join(dirname,fn+'_CS1('+str(csch)+')'+fileext)
-        time.sleep(1)
-        #doexe=wine+u' '+exe+u' -SD -1SEG -EIT '+csopt+u'-SEPA3 -OUT '+path+'/ '+pin
-        doexe=wine+u' '+exe+u' -SD -1SEG -EIT '+csopt+' -OUT '+path.encode('utf-8')+'/ '+pin.encode('utf-8')
-        doexe='xvfb-run -a -e xvfberror.txt '+doexe
-        doexe="/usr/bin/nice -n 18 "+doexe
-        os.system(doexe)
-        time.sleep(1)
-        for i in xrange(10):
+def b252tsmix(pin, pout):
+    if not (os.path.exists(pout) and os.path.getsize(pin)>os.path.getsize(pout)*0.95 and os.path.getsize(pin)<os.path.getsize(pout)*1.05):
+        exe=""
+        if configreader.getConfPath('b25_remote')=="1":
             try:
-                shutil.move(outpath.encode('utf-8'),pout.encode('utf-8'))
-                break
+                exe = configreader.getConfPath('b25_env')+" && "
             except:
-                time.sleep(1)
-        if os.access(pout, os.F_OK):
-            os.remove(pin.encode('utf-8'))
+                inst=u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。"
+                recdblist.addCommonlogEX(u"Error",u"b252tsmix(tv2ts.py)", "",inst)
+        exe = exe + "nice -n 17 " + configreader.getConfPath('b25')
+        doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
+        recdblist.printutf8(doexe)
+        recdblist.addCommandSelfLog(pin,doexe)
+        txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
+        recdblist.addLog(pin, doexe, u"b25ログ-コマンド")
+        recdblist.addLog(pin, txt, u"b25ログ-詳細")
+        recdblist.addCommandLogZip(pin, "b25", "b25", doexe, txt)
+        return txt
+def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
+    tssplitterex=configreader.getConfPath("java")+" -jar "+configreader.getConfPath("jTsSplitter")
+    doexe =tssplitterex + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
+    doexe = "nice -n 18 " + doexe
+    os.environ['LANG']="ja_JP.UTF-8"
+    txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
+    recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド")
+    recdblist.addLog(pin, txt, u"TsSplitログ-詳細")
+    time.sleep(1)
+    if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000:
+        os.remove(pin)