OSDN Git Service

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