3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2012 Yukikaze
17 tmppath = configreader.getConfPath("tmp")+"/"
18 if not os.path.exists(tmppath):
20 tssplitterp =configreader.getConfPath("java")+" -jar "+configreader.getConfPath("jTsSplitter")
22 if rec10d.rec10db.select_installed_in_status()<2:
23 rec10d.rec10db.change_installed_in_status(2)
25 for i in xrange(13,52):#62
26 recdblist.printutf8ex(u"チャンネルスキャン:地上デジタル CH "+str(i), 200, 200)
28 addCh(str(i),u"te"+str(i),str(i))
31 recdblist.printutf8ex(u"チャンネルスキャン:BSデジタル ", 200, 200)
32 for i in xrange(100,299):#240
33 recdblist.printutf8ex(u"チャンネルスキャン:BSデジタル CH "+str(i), 200, 200)
35 addCh(str(i),u"bs","BS")
36 for i2 in xrange(0,11):
39 recdblist.printutf8ex(u"チャンネルスキャン:BSデジタル CH "+chi, 200, 200)
40 for ts_offset in xrange(0,4):
41 for ts_idx in xrange(0,8):
42 t_tsid=16384+chii*16+ts_offset*512+ts_idx
43 recdblist.printutf8ex(u"TransportID "+str(t_tsid), 200, 200)
44 if checkTs(chi,str(t_tsid))>0:
45 addCh(str(chi),u"bs","BS",str(t_tsid))
48 #http://www5e.biglobe.ne.jp/~kazu_f/digital-sat/trapon-nsat110.html
52 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS2 ", 200, 200)
53 addCh("CS2","cs1","CS")
55 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS8", 200, 200)
56 addCh("CS8","cs1","CS")
58 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS10", 200, 200)
59 addCh("CS10","cs1","CS")
62 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS4", 200, 200)
63 addCh("CS4","cs2","CS")
65 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS6", 200, 200)
66 addCh("CS6","cs2","CS")
68 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS12", 200, 200)
69 addCh("CS12","cs2","CS")
71 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS14", 200, 200)
72 addCh("CS14","cs2","CS")
74 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS16", 200, 200)
75 addCh("CS16","cs2","CS")
77 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS18", 200, 200)
78 addCh("CS18","cs2","CS")
80 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS20", 200, 200)
81 addCh("CS20","cs2","CS")
83 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS22", 200, 200)
84 addCh("CS22","cs2","CS")
86 recdblist.printutf8ex(u"チャンネルスキャン:CSSデジタル CH:CS24", 200, 200)
87 addCh("CS24","cs2","CS")
88 rec10d.rec10db.change_installed_in_status(100)
89 def checkTs(ch,tsid="0"):
90 if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")):
91 os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts"))
92 if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25")):
93 os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25"))
94 tv2ts.tv2b25ts(os.path.join(tmppath,"ch_"+str(ch)+".ts"), ch, "1",tsid)
95 if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25")):
96 os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts.b25"))
97 if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")):
98 os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts"))
103 def addCh(ch,bctype,chtxthead,tsid="0"):
104 prglist=getChProgNum(ch,tsid)##[prglist,logt]
105 for lstr in prglist[0]:
106 #print [bctype,chtxthead+"_"+lstr, ch, lstr]
108 if int(lstr)<1000000:
111 tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
112 rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr,tsid, u"2010-01-01 00:00:00", u"2010-01-01 00:00:00",tnow)
114 tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
115 rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr,tsid, u"2010-01-01 00:00:00", u"2010-01-01 00:00:00",tnow)
116 except Exception, inst:
117 recdblist.addCommonlogEX("Warning", "addCh (scan_ch.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
118 checkB25Purchased(ch, prglist[1])
119 def getChProgNum(ch,tsid):
120 pout=os.path.join(tmppath,"ch_"+str(ch)+".ts")
122 pout=os.path.join(tmppath,"ch_"+str(ch)+"_"+tsid+".ts")
123 logt=tv2ts.tv2tsmix(pout, ch, "10",tsid)
124 retl=getTsProgNum(ch,pout)
130 def getTsProgNum(ch,tspath):
132 pout=os.path.join(tmppath,"chscan.txt")
134 if ch.find("CS")>-1 or ch.find("BS")>-1 :
138 doexe = tssplitterp + " "+chopt+" \""+ pin + "\" \""+ pout + "\""
139 doexe = "nice -n 18 " + doexe
140 os.environ['LANG']="ja_JP.UTF-8"
141 os.system(u"touch \""+pout+"\"")
142 txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8','ignore')
151 ret.append(str(int(l)))
154 recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド")
155 recdblist.addLog(pin, txt, u"TsSplitログ-詳細")
163 def getB25UnparchasedList(logtxt):
166 for strt in logtxt.splitlines():
167 if strt.find("unpurchased ECM")>-1:
169 if strt.find("total TS packet")>-1 and warning>0:
171 if strt.find("channel")>-1 and warning>0:
172 txt=strt.replace("channel:","")
173 txt=txt.replace("\n","")
174 txt=txt.replace(" ","")
177 def checkB25Purchased(ch,logtxt):
178 chlists=chdb.searchAllCHFromCh(ch)
179 upl=getB25UnparchasedList(logtxt)
180 if len(upl)>0 and len(chlists)>0:
183 if chl['csch'] in upl:
184 chdb.changeCHShow(chl['chtxt'],"0")