OSDN Git Service

implement ch scan system.(alpha)
[rec10/rec10-git.git] / rec10 / trunk / src / chdata.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import os.path
6 import configreader
7 import xml.dom.minidom
8
9 import rec10d
10
11 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
12
13 def chadd(bctype, chtxt, ch, csch):#すべて文字列
14     rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch, u"2010-01-01 00:00:00")
15 def chlistadd(cl):
16     if len(cl)>0:
17         for c in cl:
18             chadd(c[0],c[1],c[2],c[3])
19 def new_chdata(bs,cs):
20     rec10d.rec10db.new_epg_ch()
21     chlistadd(getChList(os.path.join(path,"chlist.xml")))
22     if bs==1:
23         #bs放送の設定 全国共通のはず
24         chlistadd(getChList(os.path.join(path,"chlist_bs.xml")))
25     if cs==1:
26         #CS放送(スカパーe2)主に基本パックに入ってるものを中心に
27         chlistadd(getChList(os.path.join(path,"chlist_cs.xml")))
28 def new_chdata_all():
29     bs=0
30     cs=0
31     try:
32         bs=int(configreader.getenv("bs"))
33         cs=int(configreader.getenv("cs"))
34     except:
35         ""
36     new_chdata(bs,cs)
37 def getChList(xmlpath):
38     dom=xml.dom.minidom.parse(file(xmlpath))
39     chlist=[]
40     for ch in dom.getElementsByTagName('channel'):
41         bctype=ch.getAttribute("bctype")
42         chd=ch.getAttribute("ch")
43         csch=ch.getAttribute("csch")
44         chtxt=ch.getAttribute("chtxt")
45         ontv=ch.getAttribute("ontvcode")
46         chlist.append([bctype,ontv,chtxt,chd,csch])
47     return chlist
48 if __name__ == "__main__":
49     new_chdata_all()