3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
7 import xml.parsers.expat
10 #from xml.sax.saxutils import DefaultHandler
16 def xml2db(xmlpath,dbpath,bctypetemp):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る
21 #db.execute('drop table tv')
22 #db.execute('drop table ch')
24 p=xml.parsers.expat.ParserCreate()
26 p.StartElementHandler=start_element
27 p.EndElementHandler=end_element
28 p.CharacterDataHandler=char_data
29 parseDocument(p,xmlpath)
32 global db,bctype,fpath
34 db=sqlite3.connect(fpath)
37 db.execute("delete from tv where bctype = \'"+bctype+"\'")
41 db.execute("delete from ch where bctype = \'"+bctype+"\'")
45 db.execute('create table tv (bctype TEXT,channel TEXT NOT NULL,start TEXT,stop TEXT,title TEXT,desc TEXT)')
49 db.execute('create table ch (bctype TEXT,channel TEXT NOT NULL,display TEXT)')
55 def writetvDB(datetv):#tvdateは(放送種別,チャンネル,start,stop,title,desc)の形式
57 #db=sqlite3.connect(fpath)
59 db.execute('insert into tv values '+datetv)
64 def writechDB(datech):#tvdateは(チャンネル,display)の形式
66 #db=sqlite3.connect(fpath)
68 db.execute('insert into ch values '+datech)
73 def parseDocument(p,xmlfile):
77 def start_element(name,attrs):
78 global flags,lastflag,xmldate
81 for (key,val) in attrs.iteritems():
82 xmldate[name+":"+key]=val
83 def end_element(name):
84 global flags,lastflag,xmldate,db
87 xmld="(\'"+bctype+"\',\'"+xmldate['channel:id']+"\',\'"+xmldate['display-name']+"\')"
90 xmldate['channel:id']=""
91 xmldate['display-name']=""
94 elif name=="programme":
96 xmld="(\'"+bctype+"\',\'"+xmldate['programme:channel']+"\',\'"+xmldate['programme:start'].replace(" +0900","")+"\',\'"+xmldate['programme:stop'].replace(" +0900","")+"\',\'"+xmldate['title'].replace(",","-")+"\',\'"+xmldate['desc']+"\')"
105 r=db.execute("SELECT * FROM tv")
113 global flags,lastflag,xmldate
115 date=date.replace("\n","")
116 date=date.replace(" ","")
117 date=date.replace("(","[")
118 date=date.replace(")","]")
119 date=date.replace("(","[")
120 date=date.replace(")","]")
121 date=date.replace("\"","")
122 date=date.replace("\'","")
123 date=date.encode('utf-8')
125 if xmldate.has_key(lastflag):
126 if xmldate[lastflag]!=date:
127 xmldate[lastflag]+=date
129 xmldate[lastflag]=date
130 #if lastflag=='category':