OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / branches / 0.5 / src / tv2ts.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 #import sys # モジュール属性 argv を取得するため
4 import os
5 import shutil
6 import commands
7 import configreader
8 #import re
9 #import glob
10 import time
11 import hashlib
12 import status
13 #japanesenkf.overrideEncodings()
14
15 mypath=str(os.path.dirname(os.path.abspath(__file__)))+"/"
16 def tv2tsmix(pout,ch,time):
17     if len(ch)>2:#BS/CSは100とかCS??とかなので3文字以上
18         status.setBSCSRecording(status.getBSCSRecording()+1)
19     else:
20         status.setTERecording(status.getTERecording()+1)
21     tv2b25ts(pout+".b25",ch,time)
22     if len(ch)>2:#BS/CSは100とかCS??とかなので3文字以上
23         status.setBSCSRecording(status.getBSCSRecording()-1)
24     else:
25         status.setTERecording(status.getTERecording()-1)
26     
27     b252tsmix(pout+".b25",pout)
28     #os.remove(pout+".b25")
29     if os.access(pout, os.F_OK):
30         try:
31             os.remove(pout+".b25")
32         except:
33             ""
34 def tv2ts(pout,ch,csch,time):
35     ext=os.path.splitext(pout)[1]#ext=".なんたら"
36     t=hashlib.md5(pout).hexdigest()
37     tempt=os.path.split(pout)
38     path=tempt[0]
39     if len(ch)>2:#BS/CSは100とかCS??とかなので3文字以上
40         status.setBSCSRecording(status.getBSCSRecording()+1)
41     else:
42         status.setTERecording(status.getTERecording()+1)
43     tv2b25ts(pout+".b25",ch,time)
44     if len(ch)>2:#BS/CSは100とかCS??とかなので3文字以上
45         status.setBSCSRecording(status.getBSCSRecording()-1)
46     else:
47         status.setTERecording(status.getTERecording()-1)
48     b252tsmix(pout+".b25",path+"/"+t+ext)
49     tsmix2ts(path+"/"+t+ext,pout,csch)
50     #os.remove(path+"/"+t+"."+temp[1])
51     if os.access(pout, os.F_OK):
52         try:
53             os.remove(path+"/"+t+ext)
54         except:
55             ""
56
57 def b252ts(pout,ch,csch):
58     ext=os.path.splitext(pout)[1]#ext=".なんたら"
59     t=hashlib.md5(pout).hexdigest()
60     tempt=os.path.split(pout)
61     path=tempt[0]
62     b252tsmix(pout+".b25",path+"/"+t+ext)
63     tsmix2ts(path+"/"+t+ext,pout,csch)
64     if os.access(pout, os.F_OK):
65         try:
66             os.remove(path+"/"+t+ext)
67         except:
68             ""
69
70 def tv2b25ts(pout,ch,time):
71     exe=configreader.getpath('recpt1')
72     doexe=exe+' '+ch+' '+time+' \''+pout+'\''
73     os.system(doexe)
74 def tv2b25ts_b25(pout,ch,time):
75     exe=configreader.getpath('recpt1')
76     doexe=exe+' --b25 '+ch+' '+time+' \''+pout+'\''
77     os.system(doexe)
78 def b252tsmix(pin,pout):
79     exe=configreader.getpath('b25')
80     doexe=exe.encode('utf-8')+u' \''+pin.encode('utf-8')+u'\' \''+pout.encode('utf-8')+u'\''
81     doexe="/usr/bin/nice -n 17 "+doexe
82     txt=commands.getoutput(doexe)
83 def tsmix2ts(pin,pout,csch):#csch=0ならcsの処理をしない
84     wine=configreader.getpath('wine')
85     exe=configreader.getpath('splitt')
86     if csch == "0":
87         time.sleep(1)
88         shutil.move(pin.encode('utf-8'),pout.encode('utf-8'))
89     else:
90         csopt='-CS'+str(csch)+" "
91         dirname=os.path.dirname(pin)
92         filename=os.path.basename(pin)
93         fn=os.path.splitext(filename)[0]                
94         fileext=os.path.splitext(filename)[1]
95         outpath=dirname+"/"+fn+'_CS1('+str(csch)+')'+fileext
96         #print dirname+" : "+filename+" : "+fn+" : "+fileext
97         path=dirname
98         outpath=os.path.join(dirname,fn+'_CS1('+str(csch)+')'+fileext)
99         time.sleep(1)
100         #doexe=wine+u' '+exe+u' -SD -1SEG -EIT '+csopt+u'-SEPA3 -OUT '+path+'/ '+pin
101         doexe=wine+u' '+exe+u' -SD -1SEG -EIT '+csopt+' -OUT '+path.encode('utf-8')+'/ '+pin.encode('utf-8')
102         doexe='xvfb-run -a -e xvfberror.txt '+doexe
103         doexe="/usr/bin/nice -n 18 "+doexe
104         os.system(doexe)
105         time.sleep(1)
106         for i in xrange(10):
107             try:
108                 shutil.move(outpath.encode('utf-8'),pout.encode('utf-8'))
109                 break
110             except:
111                 time.sleep(1)
112         if os.access(pout, os.F_OK):
113             os.remove(pin.encode('utf-8'))
114