OSDN Git Service

fix many encoding errors
[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         print "error occures in tv2ts.py tv2ts"
33         print type(inst)
34         print 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         txt=u"####recpt1-log####\n"
87         txt = txt + unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
88         logo=pout.replace(".ts.b25",".log")
89         f=open(logo,'w')
90         f.write(txt.encode('utf-8'))
91         f.close()
92     except Exception, inst:
93         print "error occures in tv2ts.py tv2b25ts"
94         print type(inst)
95         print inst
96     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
97         status.changeBSCSRecording(-1)
98     else:
99         status.changeTERecording(-1)
100 def tv2b25ts_b25(pout, ch, time):
101     exe = configreader.getpath('recpt1')
102     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
103     os.system(doexe)
104 def b252tsmix(pin, pout):
105     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):
106         exe=""
107         if configreader.getpath('b25_remote')=="1":
108             try:
109                 exe = configreader.getpath('b25_env')+" && "
110             except:
111                 recdblist.printutf8(u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。")
112         exe = exe + "nice -n 17 " + configreader.getpath('b25')
113         doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
114         recdblist.printutf8(doexe)
115         logo=pin.replace(".ts.b25",".log")
116         txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
117         s=len(txt)
118         stxt=""
119         if s>1000:
120             s=s-1000
121             stxt=txt[s:]
122         else:
123             stxt=txt
124         s=stxt.find("\n")
125         if s>0:
126             s=s+len("\n")
127             stxt=stxt[s:]
128         txt = "\n####b25-log####\n"+stxt
129         f=open(logo,'a')
130         f.write(txt.encode('utf-8'))
131         f.close()
132 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
133     """if csch==0:
134         shutil.move(pin,pout)
135     else:"""
136     doexe = configreader.getpath("tssplitter") + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
137     doexe = "nice -n 18 " + doexe
138     logo=pin.replace(".ts.tsmix",".log")
139     os.environ['LANG']="ja_JP.UTF-8"
140     txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
141     stxt=txt
142     txt = "\n####tssplit-log####\nCommand:"+doexe+"\nlog:\n"+stxt
143     f=open(logo,'a')
144     f.write(txt.encode('utf-8'))
145     f.close()
146     time.sleep(1)
147     if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000:
148         os.remove(pin)
149