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 my_env=recdblist.getEnv()
36 tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapter+u" "+channel2freq(channel)
37 #p1=subprocess.Popen(tunecmd,shell=True)
38 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel)],env=my_env,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
41 os.kill(p1.pid,signal.SIGKILL)
44 if p1.communicate()[1].find("busy")>-1:
56 def getAdapter(channel):
58 if channel[0:2].upper()=="BS" or channel[0:2].upper()=="CS":
59 chl=configreader.getConfDVB("DVBBSCS").split(",")
61 chl=configreader.getConfDVB("DVBTE").split(",")
66 def getActiveAdapter(channel):
67 for i in getAdapter(channel):
68 rt=testTune(str(i),channel)
71 def record(channel,tsid,out,timelength,decode=1):
72 adapt=getActiveAdapter(channel)
73 my_env=recdblist.getEnv()
75 tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapt+u" "+channel2freq(channel)+u" "+tsid
76 reccmd=u"/bin/cat \""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\" > "+out
78 reccmd=configreader.getConfPath("b25")+u" -v 0 \""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\" \""+out+"\""
79 recdblist.addLog(out, tunecmd+"\n"+reccmd, "record(DVB)",100)
80 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapt,channel2freq(channel),tsid],env=my_env)
83 p2=subprocess.Popen([configreader.getConfPath("b25"),u"-v 0",u"\""+configreader.getConfDVB("DVBadapter")+adapt+"/dvr0\"","\""+out+"\""],preexec_fn=os.setsid,env=my_env,bufsize=-1)
85 p2=subprocess.Popen(reccmd,shell=True,preexec_fn=os.setsid,env=my_env,bufsize=-1)
86 time.sleep(float(timelength))
87 os.killpg(p2.pid,signal.SIGKILL)
89 os.kill(p1.pid,signal.SIGKILL)
92 recdblist.printutf8ex(u"tuner busy",100,100)
96 if int(configreader.getConfDVB("useDVB").replace(" ",""))==1: