3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2012 Yukikaze
21 tmppath = configreader.getConfPath("tmp")+"/"
22 def channel2freq(channel):##freqを返す
24 if channel[0:2].upper() != "CS" and channel[0:2].upper() != "BS":
26 if ch<65:#TE 13ch 473_142857
27 freq=str(473+(ch-13)*6)+u"142857"
28 elif channel[0:2].upper() == "CS":#CS2,CS4,CS6...CS24
29 ch=int(channel.upper().replace("CS",""))
30 #freq = 12291000 + (CH_IDX - 2) * 40000 / 2 - 10678000;
31 freq=str((ch-2)*40000/2+1613000)
32 elif channel[0:2].upper() == "BS":#BS1,BS3,BS5...BS23
33 ch=int(channel.upper().replace("BS",""))
34 freq=str((ch-1)*38360/2+1049480)
36 def testTune(adapter,channel,tsid):
37 my_env=recdblist.getEnv()
38 #tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapter+u" "+channel2freq(channel)
39 #p1=subprocess.Popen(tunecmd,shell=True)
40 recdblist.printutf8_Important([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel),tsid,"0.2","/dev/null"])
41 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel),tsid,"0.2","/dev/null"],env=my_env,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
44 os.kill(p1.pid,signal.SIGKILL)
47 if p1.communicate()[1].find("busy")>-1:
59 def getAdapter(channel):
61 if channel[0:2].upper()=="BS" or channel[0:2].upper()=="CS":
62 chl=configreader.getConfDVB("DVBBSCS").split(",")
64 chl=configreader.getConfDVB("DVBTE").split(",")
69 def getActiveAdapter(channel,tsid="0"):
70 for i in getAdapter(channel):
71 rt=testTune(str(i),channel,tsid)
74 def record(channel,tsid,out,timelength,decode=0):
75 if not os.path.exists(tmppath+u"rec.sh"):
76 ft=open(tmppath+u"rec.sh","w")
77 ft.write(u"#!/bin/bash\n/bin/cat $1 > \"$2\"")
79 os.system(u"chmod +x "+tmppath+u"rec.sh")
80 adapt=getActiveAdapter(channel,tsid)
81 my_env=recdblist.getEnv()
83 tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapt+u" "+channel2freq(channel)+u" "+tsid+u" "+timelength+u" "+out
84 #reccmd=u"/bin/cat \""+configreader.getConfDVB("DVBadapter")+adapt+u"/dvr0\" > \""+out+u"\""
86 # reccmd=configreader.getConfPath("b25")+u" -v 0 \""+configreader.getConfDVB("DVBadapter")+adapt+u"/dvr0\" \""+out+"\""
87 recdblist.addLog(out, tunecmd, "record(DVB)",100)
88 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapt,channel2freq(channel),tsid,timelength,out],env=my_env)
91 # 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)
93 # p2=subprocess.Popen([tmppath+u"rec.sh",configreader.getConfDVB("DVBadapter")+adapt+"/dvr0",out],preexec_fn=os.setsid,env=my_env,bufsize=-1)
94 #p2=subprocess.Popen(reccmd,shell=True,preexec_fn=os.setsid,env=my_env,bufsize=-1)
95 #time.sleep(float(timelength))
96 #os.killpg(p2.pid,signal.SIGKILL)
98 #os.kill(p1.pid,signal.SIGKILL)
101 recdblist.printutf8ex(u"tuner busy",100,100)
104 if int(configreader.getConfDVB("useDVB").replace(" ",""))==1: