OSDN Git Service

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