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 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapter,channel2freq(channel),tsid,"0.2","/dev/null"],env=my_env,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
43 os.kill(p1.pid,signal.SIGKILL)
46 if p1.communicate()[1].find("busy")>-1:
58 def getAdapter(channel):
60 if channel[0:2].upper()=="BS" or channel[0:2].upper()=="CS":
61 chl=configreader.getConfDVB("DVBBSCS").split(",")
63 chl=configreader.getConfDVB("DVBTE").split(",")
68 def getActiveAdapter(channel,tsid="0"):
69 for i in getAdapter(channel):
70 rt=testTune(str(i),channel,tsid)
73 def record(channel,tsid,out,timelength,decode=0):
74 if not os.path.exists(tmppath+u"rec.sh"):
75 ft=open(tmppath+u"rec.sh","w")
76 ft.write(u"#!/bin/bash\n/bin/cat $1 > \"$2\"")
78 os.system(u"chmod +x "+tmppath+u"rec.sh")
79 adapt=getActiveAdapter(channel,tsid)
80 my_env=recdblist.getEnv()
82 tunecmd=configreader.getConfDVB("DVBtune")+u" "+adapt+u" "+channel2freq(channel)+u" "+tsid+u" "+timelength+u" "+out
83 #reccmd=u"/bin/cat \""+configreader.getConfDVB("DVBadapter")+adapt+u"/dvr0\" > \""+out+u"\""
85 # reccmd=configreader.getConfPath("b25")+u" -v 0 \""+configreader.getConfDVB("DVBadapter")+adapt+u"/dvr0\" \""+out+"\""
86 recdblist.addLog(out, tunecmd, "record(DVB)",100)
87 p1=subprocess.Popen([configreader.getConfDVB("DVBtune"),adapt,channel2freq(channel),tsid,timelength,out],env=my_env)
90 # 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)
92 # p2=subprocess.Popen([tmppath+u"rec.sh",configreader.getConfDVB("DVBadapter")+adapt+"/dvr0",out],preexec_fn=os.setsid,env=my_env,bufsize=-1)
93 #p2=subprocess.Popen(reccmd,shell=True,preexec_fn=os.setsid,env=my_env,bufsize=-1)
94 #time.sleep(float(timelength))
95 #os.killpg(p2.pid,signal.SIGKILL)
97 #os.kill(p1.pid,signal.SIGKILL)
100 recdblist.printutf8ex(u"tuner busy",100,100)
103 if int(configreader.getConfDVB("useDVB").replace(" ",""))==1: