OSDN Git Service

fix vfr.
[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 time
7
8 import configreader
9 import status
10 import recdblist
11 mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
12 def tv2tsmix(pout, ch, time):
13     tv2b25ts(pout + ".b25", ch, time)
14     b252tsmix(pout + ".b25", pout)
15     #if os.access(pout, os.F_OK):
16     #    try:
17     #        os.remove(pout + ".b25")
18     #    except:
19     #        ""
20 def tv2ts(pout, ch, csch, time):
21     ext = os.path.splitext(pout)[1]#ext=".なんたら"
22     tempt = os.path.split(pout)
23     path = tempt[0]
24     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
25         status.changeBSCSRecording(1)
26     else:
27         status.changeTERecording(1)
28     try:
29         tv2b25ts(pout + ".b25", ch, time)
30     except Exception, inst:
31         print "error occures in tv2ts.py tv2ts"
32         print type(inst)
33         print inst
34     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
35         status.changeBSCSRecording(-1)
36     else:
37         status.changeTERecording(-1)
38     b252tsmix(pout + ".b25", pout + ".tsmix")
39     tch="0"
40     if csch!=u"0":
41         tch=csch
42     elif ch==u"101":
43         tch="101"
44     elif ch==u"102":
45         tch="102"
46     #else:
47     #    tch=ch
48     tsmix2ts(pout + ".tsmix", pout, tch)
49     if os.access(pout, os.F_OK):
50         try:
51             #os.remove(path + "/" + t + ext)
52             ""
53         except:
54             ""
55 def b252ts(pout, ch, csch):
56     ext = os.path.splitext(pout)[1]#ext=".なんたら"
57     tempt = os.path.split(pout)
58     path = tempt[0]
59     b252tsmix(pout + ".b25", pout + ".tsmix")
60     tch=u"0"
61     if csch!=u"0":
62         tch=csch
63     elif ch==u"101":
64         tch=u"101"
65     elif ch==u"102":
66         tch=u"102"
67     #else:
68     #    tch=ch
69     tsmix2ts(pout + ".tsmix", pout, tch)
70     if os.access(pout, os.F_OK):
71         try:
72             #os.remove(path + "/" + t + ext)
73             ""
74         except:
75             ""
76 def tv2b25ts(pout, ch, time):
77     exe = configreader.getpath('recpt1')
78     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
79         status.changeBSCSRecording(1)
80     else:
81         status.changeTERecording(1)
82     try:
83         doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
84         recdblist.printutf8(doexe)
85         txt=u"####recpt1-log####\n"
86         txt = txt + unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
87         logo=pout.replace(".ts.b25",".log")
88         f=open(logo,'w')
89         f.write(txt.encode('utf-8'))
90         f.close()
91     except Exception, inst:
92         print "error occures in tv2ts.py tv2b25ts"
93         print type(inst)
94         print inst
95     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
96         status.changeBSCSRecording(-1)
97     else:
98         status.changeTERecording(-1)
99 def tv2b25ts_b25(pout, ch, time):
100     exe = configreader.getpath('recpt1')
101     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
102     os.system(doexe)
103 def b252tsmix(pin, pout):
104     if not (os.path.exists(pout) and os.path.getsize(pin)==os.path.getsize(pout)):
105         exe=""
106         if configreader.getpath('b25_remote')=="1":
107             try:
108                 exe = configreader.getpath('b25_env')+" && "
109             except:
110                 recdblist.printutf8(u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。")
111         exe = exe + "nice -n 17 " + configreader.getpath('b25')
112         doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
113         recdblist.printutf8(doexe)
114         logo=pin.replace(".ts.b25",".log")
115         txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
116         s=len(txt)
117         stxt=""
118         if s>1000:
119             s=s-1000
120             stxt=txt[s:]
121         else:
122             stxt=txt
123         s=stxt.find("\n")
124         if s>0:
125             s=s+len("\n")
126             stxt=stxt[s:]
127         txt = "\n####b25-log####\n"+stxt
128         f=open(logo,'a')
129         f.write(txt.encode('utf-8'))
130         f.close()
131 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
132     """if csch==0:
133         shutil.move(pin,pout)
134     else:"""
135     doexe = configreader.getpath("tssplitter") + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
136     doexe = "nice -n 18 " + doexe
137     logo=pin.replace(".ts.tsmix",".log")
138     os.environ['LANG']="ja_JP.UTF-8"
139     txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
140     stxt=txt
141     txt = "\n####tssplit-log####\nCommand:"+doexe+"\nlog:\n"+stxt
142     f=open(logo,'a')
143     f.write(txt.encode('utf-8'))
144     f.close()
145     time.sleep(1)
146     if os.access(pout, os.F_OK):
147         os.remove(pin)
148