OSDN Git Service

change function name.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2ts.py
index 06ab9d0..d9cfb75 100644 (file)
@@ -3,12 +3,13 @@
 #import sys # モジュール属性 argv を取得するため
 import commands
 import os
-import shutil
+import os.path
 import time
-import sys
+import traceback
 
 import configreader
 import status
+import recdblist
 mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
 def tv2tsmix(pout, ch, time):
     tv2b25ts(pout + ".b25", ch, time)
@@ -26,18 +27,21 @@ def tv2ts(pout, ch, csch, time):
         status.changeBSCSRecording(1)
     else:
         status.changeTERecording(1)
-    tv2b25ts(pout + ".b25", ch, time)
+    try:
+        tv2b25ts(pout + ".b25", ch, time)
+    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)
     b252tsmix(pout + ".b25", pout + ".tsmix")
     tch="0"
-    if csch!="0":
+    if csch!=u"0":
         tch=csch
-    elif ch=="101":
+    elif ch==u"101":
         tch="101"
-    elif ch=="102":
+    elif ch==u"102":
         tch="102"
     #else:
     #    tch=ch
@@ -53,13 +57,13 @@ def b252ts(pout, ch, csch):
     tempt = os.path.split(pout)
     path = tempt[0]
     b252tsmix(pout + ".b25", pout + ".tsmix")
-    tch="0"
-    if csch!="0":
+    tch=u"0"
+    if csch!=u"0":
         tch=csch
-    elif ch=="101":
-        tch="101"
-    elif ch=="102":
-        tch="102"
+    elif ch==u"101":
+        tch=u"101"
+    elif ch==u"102":
+        tch=u"102"
     #else:
     #    tch=ch
     tsmix2ts(pout + ".tsmix", pout, tch)
@@ -70,72 +74,49 @@ def b252ts(pout, ch, csch):
         except:
             ""
 def tv2b25ts(pout, ch, time):
-    exe = configreader.getpath('recpt1')
+    exe = configreader.getPathSetting('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.encode('utf-8'))
-    logo=pout.replace(".ts.b25",".log")
-    f=open(logo,'w')
-    f.write(txt)
-    f.close()
+    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)
 def tv2b25ts_b25(pout, ch, time):
-    exe = configreader.getpath('recpt1')
+    exe = configreader.getPathSetting('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)):
+    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.getpath('b25_remote')=="1":
+        if configreader.getPathSetting('b25_remote')=="1":
             try:
-                exe = configreader.getpath('b25_enc')+" && "
+                exe = configreader.getPathSetting('b25_env')+" && "
             except:
-                print u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。"
-        exe = exe + configreader.getpath('b25')
+                inst=u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。"
+                recdblist.addCommonlogEX(u"Error",u"b252tsmix(tv2ts.py)", "",inst)
+        exe = exe + "nice -n 17 " + configreader.getPathSetting('b25')
         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.encode('utf-8'))
-        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()
+        recdblist.printutf8(doexe)
+        txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
+        recdblist.addLog(pin, doexe, u"b25ログ-コマンド")
+        recdblist.addlog(pin, txt, u"b25ログ-詳細")
 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 = configreader.getPathSetting("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.encode('utf-8'))
-    stxt=txt
-    txt = "\n####tssplit-log####\nCommand:"+doexe+"\nlog:\n"+stxt
-    f=open(logo,'a')
-    f.write(txt)
-    f.close()
+    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):
+    if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000:
         os.remove(pin)