OSDN Git Service

fix status double counting bug.
[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     tsmix2ts(pout + ".tsmix", pout, csch)
44     if os.access(pout, os.F_OK):
45         try:
46             os.remove(path + "/" + t + ext)
47         except:
48             ""
49 def b252ts(pout, ch, csch):
50     ext = os.path.splitext(pout)[1]#ext=".なんたら"
51     tempt = os.path.split(pout)
52     path = tempt[0]
53     b252tsmix(pout + ".b25", pout + ".tsmix")
54     tsmix2ts(pout + ".tsmix", pout, csch)
55     if os.access(pout, os.F_OK):
56         try:
57             os.remove(path + "/" + t + ext)
58         except:
59             ""
60 def tv2b25ts(pout, ch, time):
61     exe = configreader.getpath('recpt1')
62     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
63         status.changeBSCSRecording(1)
64     else:
65         status.changeTERecording(1)
66     doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
67     print doexe
68     txt="####recpt1-log####\n"
69     txt = txt + commands.getoutput(doexe)
70     logo=pout.replace(".ts.b25",".log")
71     f=open(logo,'w')
72     f.write(txt)
73     f.close()
74     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
75         status.changeBSCSRecording(-1)
76     else:
77         status.changeTERecording(-1)
78 def tv2b25ts_b25(pout, ch, time):
79     exe = configreader.getpath('recpt1')
80     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
81     os.system(doexe)
82 def b252tsmix(pin, pout):
83     exe = configreader.getpath('b25')
84     #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
85     doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
86     doexe = "nice -n 17 " + doexe
87     print doexe
88     sys.stdout.flush()
89     logo=pin.replace(".ts.b25",".log")
90     txt = commands.getoutput(doexe)
91     s=len(txt)
92     stxt=""
93     if s>1000:
94         s=s-1000
95         stxt=txt[s:]
96     else:
97         stxt=txt
98     s=stxt.find("\n")
99     if s>0:
100         s=s+len("\n")
101         stxt=stxt[s:]
102     txt = "\n####b25-log####\n"+stxt
103     f=open(logo,'a')
104     f.write(txt)
105     f.close()
106 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
107     if csch == "0":
108         time.sleep(1)
109         shutil.move(pin, pout)
110     else:
111         doexe = configreader.getpath("tssplitter_lite") + " \"" + pin + "\" \"" + pout + "\" " + str(csch)
112         doexe = "nice -n 18 " + doexe
113         print doexe
114         sys.stdout.flush()
115         os.system(doexe)
116         time.sleep(1)
117         if os.access(pout, os.F_OK):
118             os.remove(pin)
119