OSDN Git Service

fix many bugs.
[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 mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
13 def tv2tsmix(pout, ch, time):
14     #if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
15     #    status.changeBSCSRecording(1)
16     #else:
17     #    status.changeTERecording(1)
18     tv2b25ts(pout + ".b25", ch, time)
19     #if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
20     #    status.changeBSCSRecording(-1)
21     #else:
22     #    status.changeTERecording(-1)
23     b252tsmix(pout + ".b25", pout)
24     #if os.access(pout, os.F_OK):
25     #    try:
26     #        os.remove(pout + ".b25")
27     #    except:
28     #        ""
29 def tv2ts(pout, ch, csch, time):
30     ext = os.path.splitext(pout)[1]#ext=".なんたら"
31     tempt = os.path.split(pout)
32     path = tempt[0]
33     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
34         status.changeBSCSRecording(1)
35     else:
36         status.changeTERecording(1)
37     tv2b25ts(pout + ".b25", ch, time)
38     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
39         status.changeBSCSRecording(-1)
40     else:
41         status.changeTERecording(-1)
42     b252tsmix(pout + ".b25", pout + ".tsmix")
43     tch="0"
44     if csch!="0":
45         tch=csch
46     elif ch=="101":
47         tch="101"
48     elif ch=="102":
49         tch="102"
50     #else:
51     #    tch=ch
52     tsmix2ts(pout + ".tsmix", pout, tch)
53     if os.access(pout, os.F_OK):
54         try:
55             os.remove(path + "/" + t + ext)
56         except:
57             ""
58 def b252ts(pout, ch, csch):
59     ext = os.path.splitext(pout)[1]#ext=".なんたら"
60     tempt = os.path.split(pout)
61     path = tempt[0]
62     b252tsmix(pout + ".b25", pout + ".tsmix")
63     tch="0"
64     if csch!="0":
65         tch=csch
66     elif ch=="101":
67         tch="101"
68     elif ch=="102":
69         tch="102"
70     #else:
71     #    tch=ch
72     tsmix2ts(pout + ".tsmix", pout, tch)
73     if os.access(pout, os.F_OK):
74         try:
75             os.remove(path + "/" + t + ext)
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     doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
85     print doexe
86     txt="####recpt1-log####\n"
87     txt = txt + commands.getoutput(doexe)
88     logo=pout.replace(".ts.b25",".log")
89     f=open(logo,'w')
90     f.write(txt)
91     f.close()
92     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
93         status.changeBSCSRecording(-1)
94     else:
95         status.changeTERecording(-1)
96 def tv2b25ts_b25(pout, ch, time):
97     exe = configreader.getpath('recpt1')
98     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
99     os.system(doexe)
100 def b252tsmix(pin, pout):
101     exe = configreader.getpath('b25')
102     #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
103     doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
104     doexe = "nice -n 17 " + doexe
105     print doexe
106     sys.stdout.flush()
107     logo=pin.replace(".ts.b25",".log")
108     txt = commands.getoutput(doexe)
109     s=len(txt)
110     stxt=""
111     if s>1000:
112         s=s-1000
113         stxt=txt[s:]
114     else:
115         stxt=txt
116     s=stxt.find("\n")
117     if s>0:
118         s=s+len("\n")
119         stxt=stxt[s:]
120     txt = "\n####b25-log####\n"+stxt
121     f=open(logo,'a')
122     f.write(txt)
123     f.close()
124 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
125     if csch == "0":
126         time.sleep(1)
127         shutil.move(pin, pout)
128     else:
129         doexe = configreader.getpath("tssplitter_lite") + " \"" + pin + "\" \"" + pout + "\" " + str(csch)
130         doexe = "nice -n 18 " + doexe
131         print doexe
132         sys.stdout.flush()
133         os.system(doexe)
134         time.sleep(1)
135         if os.access(pout, os.F_OK):
136             os.remove(pin)
137