OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / dist / trunk / rec10 / tv2ts.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
5 #import sys # モジュール属性 argv を取得するため
6 import commands
7 import os
8 import os.path
9 import time
10 import traceback
11
12 import configreader
13 import status
14 import recdblist
15 mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
16 def tv2tsmix(pout, ch, time,getlog=0):
17     tv2b25ts(pout + ".b25", ch, time)
18     txt=b252tsmix(pout + ".b25", pout)
19     return txt
20     #if os.access(pout, os.F_OK):
21     #    try:
22     #        os.remove(pout + ".b25")
23     #    except:
24     #        ""
25 def tv2ts(pout, ch, csch, time):
26     if ch.replace(" ","").replace("CS","").isdigit():
27         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
28             status.changeBSCSRecording(1)
29         else:
30             status.changeTERecording(1)
31         try:
32             tv2b25ts(pout + ".b25", ch, time)
33         except Exception, inst:
34             recdblist.addCommonlogEX(u"Error",u"tv2ts(tv2ts.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
35         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
36             status.changeBSCSRecording(-1)
37         else:
38             status.changeTERecording(-1)
39     else:
40          ch="0"
41          csch="0"
42     b252tsmix(pout + ".b25", pout + ".tsmix")
43     tch="0"
44     if csch!=u"0":
45         tch=csch
46     elif ch==u"101":
47         tch="101"
48     elif ch==u"102":
49         tch="102"
50     #else:
51     #    tch=ch
52     tsmix2ts(pout + ".tsmix", pout, tch)
53     if os.access(pout, os.F_OK):
54         try:
55             #os.remove(path + "/" + t + ext)
56             ""
57         except:
58             ""
59 def b252ts(pout, ch, csch):
60     b252tsmix(pout + ".b25", pout + ".tsmix")
61     tch=u"0"
62     if ch.replace(" ","").replace("CS","").isdigit():
63         if csch!=u"0":
64             tch=csch
65         elif ch==u"101":
66             tch=u"101"
67         elif ch==u"102":
68             tch=u"102"
69     else:
70         tch="0"
71     tsmix2ts(pout + ".tsmix", pout, tch)
72 def tv2b25ts(pout, ch, time):
73     exe = configreader.getConfPath('recpt1')
74     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
75         status.changeBSCSRecording(1)
76     else:
77         status.changeTERecording(1)
78     try:
79         doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
80         recdblist.printutf8(doexe)
81         recdblist.addLog(pout, doexe, u"recpt1ログ-コマンド")
82         recdblist.addLog(pout, unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8'), u"recpt1ログ-詳細")
83     except Exception, inst:
84         recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst))
85     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
86         status.changeBSCSRecording(-1)
87     else:
88         status.changeTERecording(-1)
89 def b252tsmix(pin, pout):
90     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):
91         exe=""
92         if configreader.getConfPath('b25_remote')=="1":
93             try:
94                 exe = configreader.getConfPath('b25_env')+" && "
95             except:
96                 inst=u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。"
97                 recdblist.addCommonlogEX(u"Error",u"b252tsmix(tv2ts.py)", "",inst)
98         exe = exe + "nice -n 17 " + configreader.getConfPath('b25')
99         doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
100         recdblist.printutf8(doexe)
101         recdblist.addCommandSelfLog(pin,doexe)
102         txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
103         recdblist.addLog(pin, doexe, u"b25ログ-コマンド")
104         recdblist.addLog(pin, txt, u"b25ログ-詳細")
105         recdblist.addCommandLogZip(pin, "b25", "b25", doexe, txt)
106         return txt
107 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
108     tssplitterex=configreader.getConfPath("java")+" -jar "+configreader.getConfPath("jTsSplitter")
109     doexe =tssplitterex + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
110     doexe = "nice -n 18 " + doexe
111     os.environ['LANG']="ja_JP.UTF-8"
112     txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
113     recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド")
114     recdblist.addLog(pin, txt, u"TsSplitログ-詳細")
115     time.sleep(1)
116     if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000:
117         os.remove(pin)
118