OSDN Git Service

change status logging in DB.
[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     
15     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
16         status.changeBSCSRecording(1)
17         #status.setBSCSRecording(status.getBSCSRecording() + 1)
18     else:
19         #status.setTERecording(status.getTERecording() + 1)
20         status.changeTERecording(1)
21     tv2b25ts(pout + ".b25", ch, time)
22     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
23         #status.setBSCSRecording(status.getBSCSRecording()-1)
24         status.changeBSCSRecording(-1)
25     else:
26         #status.setTERecording(status.getTERecording()-1)
27         status.changeTERecording(-1)
28     b252tsmix(pout + ".b25", pout)
29     #os.remove(pout+".b25")
30     if os.access(pout, os.F_OK):
31         try:
32             os.remove(pout + ".b25")
33         except:
34             ""
35 def tv2ts(pout, ch, csch, time):
36     ext = os.path.splitext(pout)[1]#ext=".なんたら"
37     tempt = os.path.split(pout)
38     path = tempt[0]
39     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
40         status.changeBSCSRecording(1)
41         #status.setBSCSRecording(status.getBSCSRecording() + 1)
42     else:
43         #status.setTERecording(status.getTERecording() + 1)
44         status.changeTERecording(1)
45     tv2b25ts(pout + ".b25", ch, time)
46     if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
47         #status.setBSCSRecording(status.getBSCSRecording()-1)
48         status.changeBSCSRecording(-1)
49     else:
50         #status.setTERecording(status.getTERecording()-1)
51         status.changeTERecording(-1)
52     b252tsmix(pout + ".b25", pout + ".tsmix")
53     tsmix2ts(pout + ".tsmix", pout, csch)
54     #os.remove(path+"/"+t+"."+temp[1])
55     if os.access(pout, os.F_OK):
56         try:
57             os.remove(path + "/" + t + ext)
58         except:
59             ""
60 def b252ts(pout, ch, csch):
61     ext = os.path.splitext(pout)[1]#ext=".なんたら"
62     #t=hashlib.md5(pout).hexdigest()
63     tempt = os.path.split(pout)
64     path = tempt[0]
65     b252tsmix(pout + ".b25", pout + ".tsmix")
66     tsmix2ts(pout + ".tsmix", pout, csch)
67     if os.access(pout, os.F_OK):
68         try:
69             os.remove(path + "/" + t + ext)
70         except:
71             ""
72
73 def tv2b25ts(pout, ch, time):
74     exe = configreader.getpath('recpt1')
75     #print [exe,ch,time,pout]
76     #doexe=""
77     doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
78     os.system(doexe)
79 def tv2b25ts_b25(pout, ch, time):
80     exe = configreader.getpath('recpt1')
81     doexe = exe + ' --b25 ' + ch + ' ' + time + ' \'' + pout + '\''
82     os.system(doexe)
83 def b252tsmix(pin, pout):
84     exe = configreader.getpath('b25')
85     #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
86     doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
87     doexe = "nice -n 17 " + doexe
88     print doexe
89     sys.stdout.flush()
90     txt = commands.getoutput(doexe)
91     f=open(pin+".log",'w')
92     f.write(txt)
93     f.close()
94 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
95     if csch == "0":
96         time.sleep(1)
97         shutil.move(pin, pout)
98     else:
99         doexe = configreader.getpath("tssplitter_lite") + " \"" + pin + "\" \"" + pout + "\" " + str(csch)
100         doexe = "nice -n 18 " + doexe
101         print doexe
102         sys.stdout.flush()
103         os.system(doexe)
104         time.sleep(1)
105         if os.access(pout, os.F_OK):
106             os.remove(pin)
107