OSDN Git Service

implement caption/audio 0 byte error auto skip system.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2audio.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import os
6 import configreader
7 import recdblist
8 import commands
9 import os.path
10 import tv2audio
11 import subprocess
12 import signal
13 def wav2aac_nero(pin,pout):
14     os.environ['LANG']="ja_JP.UTF-8"
15     neroaac=configreader.getpath('NeroAAC')
16     exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\""
17     txt=u"Cmd : "+exe+"\n"
18     try:
19         txt=txt+commands.getoutput(exe.encode('utf-8'))
20         recdblist.addlog(pin, txt, "Wav2aac_Nero log")
21     except:
22         if not os.path.exists(pout):
23             lame="lame"
24             exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
25             txt=u"Cmd : "+exe+"\n"
26             txt=txt+commands.getoutput(exe.encode('utf-8'))
27             recdblist.addlog(pin, txt, "Wav2aac_Lame log")
28 def wav2mp3_lame(pin,pout):
29     os.environ['LANG']="ja_JP.UTF-8"
30     lame="lame"
31     exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
32     txt=u"Cmd : "+exe+"\n"
33     try:
34         txt=txt+commands.getoutput(exe.encode('utf-8'))
35     except:
36         ""
37     recdblist.addlog(pin, txt, "Wav2aac_Lame log")
38 def ts2single_audio(pts):
39     paac=pts.replace(".ts",".aac")
40     ffmpeg=configreader.getpath("ffmpeg")
41     e0=ffmpeg+" -i \""+pts+"\" -vn -f aac -acodec copy \""+paac+"\""
42     p0=subprocess.Popen(e0,shell=True)
43     time.sleep(60)
44     if p0.poll==-1:#実行中
45         if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了
46             os.kill(p0.pid,signal.SIGKILL)
47             os.remove(paac)
48             ts2singlewav(pts)
49             useNero=0
50             try:
51                 if configreader.getpath("useNeroAAC")=="1" and os.path.exists(configreader.getpath("NeroAAC")):
52                     useNero=1
53             except:
54                 useNero=0
55             if useNero==1:
56                 aout=pts.replace(".ts",".aac")
57                 ain=pts.replace(".ts",".wav")
58                 tv2audio.wav2aac_nero(ain,aout)
59             else:
60                 aout=pts.replace(".ts",".mp3")
61                 ain=pts.replace(".ts",".wav")
62                 tv2audio.wav2mp3_lame(ain,aout)
63         else:
64             os.waitpid(p0.pid, 0)
65 def ts2singlewav(pts):
66     bontsdemux = configreader.getpath('bontsdemux')
67     bonpin = "Z:\\" + pts[1:]
68     outf = os.path.splitext(pts)[0]
69     bonpout = "Z:\\" + outf[1:]
70     xvfb = configreader.getpath('xvfb-run')
71     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit"
72     #recdblist.printutf8(exe)
73     exe = xvfb + ' -a ' + exe
74     recdblist.printutf8(exe)
75     p=subprocess.Popen(exe.encode('utf-8'),shell=True)
76     os.waitpid(p.pid, 0)