OSDN Git Service

implement tmp config.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2ts.py
index 4ccf620..a01b026 100644 (file)
 #!/usr/bin/python
 # coding: UTF-8
 #import sys # モジュール属性 argv を取得するため
+import commands
 import os
 import shutil
-import commands
-import configreader
-#import japanesenkf
-import random
-import base64
-#import re
-#import glob
 import time
-import hashlib
-#japanesenkf.overrideEncodings()
+import sys
 
-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")
+import configreader
+import status
+mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
+def tv2tsmix(pout, ch, time):
+    tv2b25ts(pout + ".b25", ch, time)
+    b252tsmix(pout + ".b25", pout)
+    #if os.access(pout, os.F_OK):
+    #    try:
+    #        os.remove(pout + ".b25")
+    #    except:
+    #        ""
+def tv2ts(pout, ch, csch, time):
+    ext = os.path.splitext(pout)[1]#ext=".なんたら"
+    tempt = os.path.split(pout)
+    path = tempt[0]
+    if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+        status.changeBSCSRecording(1)
+    else:
+        status.changeTERecording(1)
+    tv2b25ts(pout + ".b25", ch, time)
+    if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+        status.changeBSCSRecording(-1)
+    else:
+        status.changeTERecording(-1)
+    b252tsmix(pout + ".b25", pout + ".tsmix")
+    tch="0"
+    if csch!="0":
+        tch=csch
+    elif ch=="101":
+        tch="101"
+    elif ch=="102":
+        tch="102"
+    #else:
+    #    tch=ch
+    tsmix2ts(pout + ".tsmix", pout, tch)
     if os.access(pout, os.F_OK):
         try:
-            os.remove(pout+".b25")
-        except:
+            #os.remove(path + "/" + t + ext)
             ""
-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(".")
-    ext=os.path.splitext(pout)[1]#ext=".なんたら"
-    #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+ext)
-    tsmix2ts(path+"/"+t+ext,pout,csch)
-    #os.remove(path+"/"+t+"."+temp[1])
-    if os.access(pout, os.F_OK):
-        try:
-            os.remove(path+"/"+t+ext)
         except:
             ""
-
-def b252ts(pout,ch,csch):
-    temp=pout.split(".")
-    ext=os.path.splitext(pout)[1]#ext=".なんたら"
-    #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+ext)
-    tsmix2ts(path+"/"+t+ext,pout,csch)
-    #os.remove(path+"/"+t+"."+temp[1])
+def b252ts(pout, ch, csch):
+    ext = os.path.splitext(pout)[1]#ext=".なんたら"
+    tempt = os.path.split(pout)
+    path = tempt[0]
+    b252tsmix(pout + ".b25", pout + ".tsmix")
+    tch="0"
+    if csch!="0":
+        tch=csch
+    elif ch=="101":
+        tch="101"
+    elif ch=="102":
+        tch="102"
+    #else:
+    #    tch=ch
+    tsmix2ts(pout + ".tsmix", pout, tch)
     if os.access(pout, os.F_OK):
         try:
-            os.remove(path+"/"+t+ext)
+            #os.remove(path + "/" + t + ext)
+            ""
         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'))
+def tv2b25ts(pout, ch, time):
+    exe = configreader.getpath('recpt1')
+    if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+        status.changeBSCSRecording(1)
+    else:
+        status.changeTERecording(1)
+    doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
+    print doexe
+    txt="####recpt1-log####\n"
+    txt = txt + commands.getoutput(doexe)
+    logo=pout.replace(".ts.b25",".log")
+    f=open(logo,'w')
+    f.write(txt)
+    f.close()
+    if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
+        status.changeBSCSRecording(-1)
     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):
-            try:
-                shutil.move(outpath.encode('utf-8'),pout.encode('utf-8'))
-                break
-            except:
-                time.sleep(1)
-        if os.access(pout, os.F_OK):
-            os.remove(pin.encode('utf-8'))
+        status.changeTERecording(-1)
+def tv2b25ts_b25(pout, ch, time):
+    exe = configreader.getpath('recpt1')
+    doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
+    os.system(doexe)
+def b252tsmix(pin, pout):
+    if not (os.path.exists(pout) and os.path.getsize(pin)==os.path.getsize(pout)):
+        exe = configreader.getpath('b25')
+        #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
+        doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
+        doexe = "nice -n 17 " + doexe
+        print doexe
+        sys.stdout.flush()
+        logo=pin.replace(".ts.b25",".log")
+        txt = commands.getoutput(doexe)
+        s=len(txt)
+        stxt=""
+        if s>1000:
+            s=s-1000
+            stxt=txt[s:]
+        else:
+            stxt=txt
+        s=stxt.find("\n")
+        if s>0:
+            s=s+len("\n")
+            stxt=stxt[s:]
+        txt = "\n####b25-log####\n"+stxt
+        f=open(logo,'a')
+        f.write(txt)
+        f.close()
+def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
+    """if csch==0:
+        shutil.move(pin,pout)
+    else:"""
+    doexe = configreader.getpath("tssplitter") + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
+    doexe = "nice -n 18 " + doexe
+    logo=pin.replace(".ts.tsmix",".log")
+    os.environ['LANG']="ja_JP.UTF-8"
+    txt = commands.getoutput(doexe)
+    stxt=txt
+    txt = "\n####tssplit-log####\nCommand:"+doexe+"\nlog:\n"+stxt
+    f=open(logo,'a')
+    f.write(txt)
+    f.close()
+    time.sleep(1)
+    if os.access(pout, os.F_OK):
+        os.remove(pin)