OSDN Git Service

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