OSDN Git Service

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