OSDN Git Service

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