OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / branches / 0.9.0 / 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 = configreader.getpath('b25')
97         #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
98         doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
99         doexe = "nice -n 17 " + doexe
100         print doexe
101         sys.stdout.flush()
102         logo=pin.replace(".ts.b25",".log")
103         txt = commands.getoutput(doexe)
104         s=len(txt)
105         stxt=""
106         if s>1000:
107             s=s-1000
108             stxt=txt[s:]
109         else:
110             stxt=txt
111         s=stxt.find("\n")
112         if s>0:
113             s=s+len("\n")
114             stxt=stxt[s:]
115         txt = "\n####b25-log####\n"+stxt
116         f=open(logo,'a')
117         f.write(txt)
118         f.close()
119 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
120     """if csch==0:
121         shutil.move(pin,pout)
122     else:"""
123     doexe = configreader.getpath("tssplitter") + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
124     doexe = "nice -n 18 " + doexe
125     logo=pin.replace(".ts.tsmix",".log")
126     os.environ['LANG']="ja_JP.UTF-8"
127     txt = commands.getoutput(doexe)
128     stxt=txt
129     txt = "\n####tssplit-log####\nCommand:"+doexe+"\nlog:\n"+stxt
130     f=open(logo,'a')
131     f.write(txt)
132     f.close()
133     time.sleep(1)
134     if os.access(pout, os.F_OK):
135         os.remove(pin)
136