OSDN Git Service

implement new logging system.
[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
9 import configreader
10 import status
11 import recdblist
12 mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
13 def tv2tsmix(pout, ch, time):
14     tv2b25ts(pout + ".b25", ch, time)
15     b252tsmix(pout + ".b25", pout)
16     #if os.access(pout, os.F_OK):
17     #    try:
18     #        os.remove(pout + ".b25")
19     #    except:
20     #        ""
21 def tv2ts(pout, ch, csch, time):
22     ext = os.path.splitext(pout)[1]#ext=".なんたら"
23     tempt = os.path.split(pout)
24     path = tempt[0]
25     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
26         status.changeBSCSRecording(1)
27     else:
28         status.changeTERecording(1)
29     try:
30         tv2b25ts(pout + ".b25", ch, time)
31     except Exception, inst:
32         recdblist.printutf8("error occures in tv2ts.py tv2ts")
33         recdblist.printutf8(str(type(inst)))
34         recdblist.printutf8(str(inst))
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.getpath('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, unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8'), u"recpt1-log")
87     except Exception, inst:
88         recdblist.printutf8("error occures in tv2ts.py tv2b25ts")
89         recdblist.printutf8(str(type(inst)))
90         recdblist.printutf8(str(inst))
91     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
92         status.changeBSCSRecording(-1)
93     else:
94         status.changeTERecording(-1)
95 def tv2b25ts_b25(pout, ch, time):
96     exe = configreader.getpath('recpt1')
97     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
98     os.system(doexe)
99 def b252tsmix(pin, pout):
100     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):
101         exe=""
102         if configreader.getpath('b25_remote')=="1":
103             try:
104                 exe = configreader.getpath('b25_env')+" && "
105             except:
106                 recdblist.printutf8(u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。")
107         exe = exe + "nice -n 17 " + configreader.getpath('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, txt, u"b25-log")
112 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
113     """if csch==0:
114         shutil.move(pin,pout)
115     else:"""
116     doexe = configreader.getpath("tssplitter") + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
117     doexe = "nice -n 18 " + doexe
118     os.environ['LANG']="ja_JP.UTF-8"
119     txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
120     txt = doexe+"\n\n"+txt
121     recdblist.addlog(pin, txt, "tssplit-log")
122     time.sleep(1)
123     if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000:
124         os.remove(pin)
125