OSDN Git Service

implemnt rec10 0.9.0 function.
[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     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     tv2b25ts(pout + ".b25", ch, time)
30     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
31         status.changeBSCSRecording(-1)
32     else:
33         status.changeTERecording(-1)
34     b252tsmix(pout + ".b25", pout + ".tsmix")
35     tch="0"
36     if csch!="0":
37         tch=csch
38     elif ch=="101":
39         tch="101"
40     elif ch=="102":
41         tch="102"
42     #else:
43     #    tch=ch
44     tsmix2ts(pout + ".tsmix", pout, tch)
45     if os.access(pout, os.F_OK):
46         try:
47             #os.remove(path + "/" + t + ext)
48             ""
49         except:
50             ""
51 def b252ts(pout, ch, csch):
52     ext = os.path.splitext(pout)[1]#ext=".なんたら"
53     tempt = os.path.split(pout)
54     path = tempt[0]
55     b252tsmix(pout + ".b25", pout + ".tsmix")
56     tch="0"
57     if csch!="0":
58         tch=csch
59     elif ch=="101":
60         tch="101"
61     elif ch=="102":
62         tch="102"
63     #else:
64     #    tch=ch
65     tsmix2ts(pout + ".tsmix", pout, tch)
66     if os.access(pout, os.F_OK):
67         try:
68             #os.remove(path + "/" + t + ext)
69             ""
70         except:
71             ""
72 def tv2b25ts(pout, ch, time):
73     exe = configreader.getpath('recpt1')
74     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
75         status.changeBSCSRecording(1)
76     else:
77         status.changeTERecording(1)
78     doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
79     print doexe
80     txt="####recpt1-log####\n"
81     txt = txt + commands.getoutput(doexe)
82     logo=pout.replace(".ts.b25",".log")
83     f=open(logo,'w')
84     f.write(txt)
85     f.close()
86     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
87         status.changeBSCSRecording(-1)
88     else:
89         status.changeTERecording(-1)
90 def tv2b25ts_b25(pout, ch, time):
91     exe = configreader.getpath('recpt1')
92     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
93     os.system(doexe)
94 def b252tsmix(pin, pout):
95     if not (os.path.exists(pout) and os.path.getsize(pin)==os.path.getsize(pout)):
96         exe=""
97         if configreader.getpath('b25_remote')=="1":
98             try:
99                 exe = configreader.getpath('b25_enc')+" && "
100             except:
101                 print u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。"
102         exe = exe + configreader.getpath('b25')
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         shutil.move(pin,pout)
127     else:"""
128     doexe = configreader.getpath("tssplitter") + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
129     doexe = "nice -n 18 " + doexe
130     logo=pin.replace(".ts.tsmix",".log")
131     os.environ['LANG']="ja_JP.UTF-8"
132     txt = commands.getoutput(doexe)
133     stxt=txt
134     txt = "\n####tssplit-log####\nCommand:"+doexe+"\nlog:\n"+stxt
135     f=open(logo,'a')
136     f.write(txt)
137     f.close()
138     time.sleep(1)
139     if os.access(pout, os.F_OK):
140         os.remove(pin)
141