3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2012 Yukikaze
20 def channel2freq(channel):##freqを返す
22 if channel[0:2].upper() != "CS" and channel[0:2].upper() != "BS":
24 if ch<65:#TE 13ch 473_142857
25 freq=str(473+(ch-13)*6)+u"142857"
26 elif channel[0:2].upper() == "CS":#CS2,CS4,CS6...CS24
27 ch=int(channel.upper().replace("CS",""))
28 #freq = 12291000 + (CH_IDX - 2) * 40000 / 2 - 10678000;
29 freq=str((ch-2)*40000/2+1613000)
30 elif channel[0:2].upper() == "BS":#BS1,BS3,BS5...BS23
31 ch=int(channel.upper().replace("BS",""))
32 freq=str((ch-1)*38360/2+1049480)
34 def testTune(adapter,channel):
35 tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapter+u" "+channel2freq(channel)
36 #p1=subprocess.Popen(tunecmd,shell=True)
37 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel)],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
40 os.kill(p1.pid,signal.SIGKILL)
43 if p1.communicate()[1].find("busy")>-1:
55 def getAdapter(channel):
57 if channel[0:2].upper()=="BS" or channel[0:2].upper()=="CS":
58 chl=configreader.getConfDVB("DVBBSCS").split(",")
60 chl=configreader.getConfDVB("DVBTE").split(",")
65 def getActiveAdapter(channel):
66 for i in getAdapter(channel):
67 rt=testTune(str(i),channel)
70 def record(channel,tsid,out,timelength,decode=1):
71 adapt=getActiveAdapter(channel)
73 tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapt+u" "+channel2freq(channel)+u" "+tsid
74 reccmd=u"/bin/cat \""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\" > "+out
76 reccmd=configreader.getConfPath("b25")+u" -v 0 \""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\" \""+out+"\""
77 recdblist.addLog(out, tunecmd+"\n"+reccmd, "record(DVB)",100)
78 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapt,channel2freq(channel),tsid])
81 p2=subprocess.Popen([configreader.getConfPath("b25"),u"-v 0",u"\""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\"","\""+out+"\""],preexec_fn=os.setsid,bufsize=-1)
83 p2=subprocess.Popen(reccmd,shell=True,preexec_fn=os.setsid,bufsize=-1)
84 time.sleep(float(timelength))
85 os.killpg(p2.pid,signal.SIGKILL)
87 os.kill(p1.pid,signal.SIGKILL)
90 recdblist.printutf8ex(u"tuner busy",100,100)
94 if int(configreader.getConfDVB("useDVB").replace(" ",""))==1: