3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
21 nodelist = elm.childNodes
26 if node.nodeType == node.TEXT_NODE:
29 def getText_item(obj):
34 def writeMultiTVDB(bctype,tvlists):
35 rec10d.rec10db.new_epg_timeline(bctype)
36 for channel,start,stop,title,desc,longdesc,category in tvlists:
37 rec10d.rec10db.add_epg_timeline(bctype, channel, start, stop, title, desc, longdesc, category)
38 def writeMultiCHDB(chlists):
39 for chtxt,dn in chlists:
40 rec10d.rec10db.update_chname_by_chtxt_epg_ch(chtxt,dn)
42 chdb.changeCHShow(chtxt,"0")
45 chdb.changeCHShow(chtxt,"0")
46 def writeMultiLogoDB(logolists):
48 for type,sv,pngdata in logolists:
49 chtxt=chdb.searchCHFromCsch(sv)['chtxt']
51 rec10d.rec10db.change_logodata_epg_ch(chtxt,type,pngdata)
52 def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る
53 dtb=datetime.datetime.now()
54 dom=xml.dom.minidom.parse(file(xmlpath))
58 rHisch=re.compile(u"『([^『]+)』(.+)\Z")##History CHのタイトル#01 exp:「#01説明」をタイトルに含める
59 for ch in dom.getElementsByTagName('channel'):
60 chtxtt=ch.getAttribute("id")
61 chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data
62 chlist.append([chtxtt,chname])
63 for tv in dom.getElementsByTagName('programme'):
64 channel=zenhan.toHankaku_ABC123(tv.getAttribute("channel"))
65 start=tv.getAttribute("start").replace(" +0900", "")
66 stop=tv.getAttribute("stop").replace(" +0900", "")
67 title=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("title"))).replace(",", "_")
68 desc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("desc")))
69 longdesc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("longdesc")))
70 category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category")))
71 title=addTitle_Subtitle(rHisch,1,title,desc)
72 tch=chdb.searchCHFromChtxt(channel)
74 if tch.get('bctype',"")==bctype and not tch['visible']==0:
75 bt=bayes.get(tch['chtxt'],["","",0])
76 bt2=[bt[0]+title+" ",bt[1]+desc+" "+longdesc+" ",bt[2]+1]
77 bayes[tch['chtxt']]=bt2
78 tvlist.append([channel,start,stop,title,desc,longdesc,category])
79 p=auto_rec.calcKey(tch['chtxt'], title,desc+" "+longdesc)
81 bttt=datetime.datetime.strptime(start,"%Y%m%d%H%M%S")
82 bttt=bttt-datetime.timedelta(seconds=1200)
83 bttime=bttt.strftime("%Y-%m-%d %H:%M:%S")
84 ettt=datetime.datetime.strptime(stop,"%Y%m%d%H%M%S")
85 ettt=ettt+datetime.timedelta(seconds=1200)
86 ettime=ettt.strftime("%Y-%m-%d %H:%M:%S")
87 chs=rec10d.rec10db.select_bytime_bychtxt_all_timeline(bttime,ettime,tch['chtxt'])
91 p2t=n_gram.trigram(ch['title'],title)
95 if status.getSettings_auto_bayes()==1:
99 maxnum=epgdb.count_schedule_timeline(bttime, ettime)[1]
100 maxnum=int(configreader.getConfEnv("bscs_max"))-maxnum
102 maxnum=epgdb.count_schedule_timeline(bttime, ettime)[0]
103 maxnum=int(configreader.getConfEnv("te_max"))-maxnum
105 topt=status.getSettings_auto_opt()
106 recdb.reserveReckey(recdblist.REC_RESERVE,title,tch['chtxt'], bttime, ettime,topt)
108 recdb.addAutoBayesKeyword(tch['chtxt'],title,start,stop,p)
111 writeMultiCHDB(chlist)
114 writeMultiTVDB(bctype,tvlist)
116 for ct,list in bayes.items():
117 auto_rec.updateRecall(ct,list[0],list[1],list[2])
118 auto_rec.updateRecall("ALL",list[0],list[1],list[2])
119 dtb=datetime.datetime.now()-dtb
120 recdblist.printutf8(bctype + u" epg取り出し終了")
121 recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .")
122 def xml2db_dom_logo(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る
123 dtb=datetime.datetime.now()
124 dom=xml.dom.minidom.parse(file(xmlpath))
126 for logo in dom.getElementsByTagName('logo'):
127 type=int(logo.getAttribute("type"))
128 sv=logo.getAttribute("sv")
129 pngdata=logo.childNodes[0].data
130 logolist.append([type,sv,pngdata])
132 if len(logolist) > 0:
133 writeMultiLogoDB(logolist)
134 dtb=datetime.datetime.now()-dtb
135 recdblist.printutf8(bctype + u" epg取り出し終了")
136 recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating logo DB .")
137 def addTitle_Subtitle(recompiled,num,title,exp):
139 tST=recompiled.match(exp)
142 newtitle=title+u"『"+tST.group(num)+u"』"
145 except Exception, inst:
146 recdblist.addCommonlogEX("Error", "addTitle_Subtitle(xml2db_dob.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)