3 # tvfs - a simple fuse-module to mount a tv-guide as a filesystem
4 # Copyright (C) 2008, Kristian Rumberg (kristianrumberg@gmail.com)
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 class Error(Exception):
26 def __init__(self
, value
):
27 Exception.__init
__(self
)
30 return repr(self
.value
)
33 def __init__(self
, url
):
37 stream
= urllib
.urlopen(self
.url
)
39 f
= tempfile
.NamedTemporaryFile()
42 gs
= gzip
.open(f
.name
)
49 def __init__(self
, timestr
):
50 o
= re
.match("([0-9][0-9]):([0-9][0-9])", timestr
)
52 raise Error("Unable to parse time string")
53 self
.hour
= str(o
.group(1))
54 self
.minute
= str(o
.group(2))
57 return self
.hour
+ ":" + self
.minute
60 def __init__(self
, name
, desc
, start_str
, end_str
):
63 self
.start
= Time(start_str
)
64 self
.end
= Time(end_str
)
69 def get_description(self
):
79 def __init__(self
, name
, url
):
84 istream
= GZStream(url
)
85 doc
= libxml2
.parseDoc(istream
.read())
87 namelist
= doc
.xpathEval('//programme//title/text()')
88 desclist
= doc
.xpathEval('//programme//desc/text()')
89 startlist
= doc
.xpathEval('//programme/attribute::start')
90 endlist
= doc
.xpathEval('//programme/attribute::stop')
92 for name
,desc
,start
,end
in zip(namelist
,desclist
,startlist
,endlist
):
93 name
= str(name
.content
)
94 desc
= str(desc
.content
)
96 start
= str(start
.content
)[8:12]
97 start
= start
[0:2] + ":" + start
[2:4]
99 end
= str(end
.content
)[8:12]
100 end
= end
[0:2] + ":" + end
[2:4]
102 self
.cl
.append( Program(name
, desc
, start
, end
) )
105 return self
.cl
.__iter
__()
108 def __init__(self
, name
, baseurl
):
110 self
.baseurl
= baseurl
113 def list_today(self
):
114 if None == self
.today
:
115 d
= datetime
.datetime
.now()
116 path
= self
.baseurl
+ "_" + d
.strftime("%Y-%m-%d") + ".xml.gz"
117 self
.today
= ProgramList(self
.name
, path
)
125 basepath
= "http://tv.swedb.se/xmltv/"
128 istream
= GZStream(basepath
+ "channels.xml.gz")
129 doc
= libxml2
.parseDoc(istream
.read())
131 namelist
= doc
.xpathEval('//display-name/text()')
132 idlist
= doc
.xpathEval('//channel/attribute::id')
133 baselist
= doc
.xpathEval('//base-url/text()')
135 for name
,idn
,base
in zip(namelist
,idlist
,baselist
):
136 name
= str(name
.content
)
137 idn
= str(idn
.content
)
138 base
= str(base
.content
)
139 self
.cl
.append( Channel(name
, base
+ idn
))
142 return self
.cl
.__iter
__()
144 def has_channel(self
, chanstr
):
145 return -1 != self
.cl
.index
[chanstr
]
157 print p
.get_description()
159 if __name__
== "__main__":