OSDN Git Service

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