OSDN Git Service

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