-
Notifications
You must be signed in to change notification settings - Fork 1
/
xmltv.py
758 lines (642 loc) · 25.3 KB
/
xmltv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
"""
xmltv.py - Python interface to XMLTV format, based on XMLTV.pm
Copyright (C) 2001 James Oakley <[email protected]>
This library is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this software; if not, see <http://www.gnu.org/licenses/>.
"""
import re
import sys
import types
if sys.hexversion >= 0x2050000:
from xml.etree.cElementTree import ElementTree, Element, SubElement, tostring
else:
try:
from cElementTree import ElementTree, Element, SubElement, tostring
except ImportError:
from elementtree.ElementTree import ElementTree, Element, SubElement, tostring
# The Python-XMLTV version
VERSION = "1.4.4"
# The date format used in XMLTV (the %Z will go away in 0.6)
date_format = '%Y%m%d%H%M%S %Z'
date_format_notz = '%Y%m%d%H%M%S'
def set_attrs(d, elem, attrs):
"""
set_attrs(d, elem, attrs) -> None
Add any attributes in 'attrs' found in 'elem' to 'd'
"""
for attr in attrs:
if attr in elem:
d[attr] = elem.get(attr)
def set_boolean(d, name, elem):
"""
set_boolean(d, name, elem) -> None
If element, 'name' is found in 'elem', set 'd'['name'] to a boolean
from the 'yes' or 'no' content of the node
"""
node = elem.find(name)
if node is not None:
if node.text.lower() == 'yes':
d[name] = True
elif node.text.lower() == 'no':
d[name] = False
def append_text(d, name, elem, with_lang=True):
"""
append_text(d, name, elem, with_lang=True) -> None
Append any text nodes with 'name' found in 'elem' to 'd'['name']. If
'with_lang' is 'True', a tuple of ('text', 'lang') is appended
"""
for node in elem.findall(name):
if name not in d:
d[name] = []
if with_lang:
d[name].append((node.text, node.get('lang', '')))
else:
d[name].append(node.text)
def set_text(d, name, elem, with_lang=True):
"""
set_text(d, name, elem, with_lang=True) -> None
Set 'd'['name'] to the text found in 'name', if found under 'elem'. If
'with_lang' is 'True', a tuple of ('text', 'lang') is set
"""
node = elem.find(name)
if node is not None:
if with_lang:
d[name] = (node.text, node.get('lang', ''))
else:
d[name] = node.text
def append_icons(d, elem):
"""
append_icons(d, elem) -> None
Append any icons found under 'elem' to 'd'
"""
for iconnode in elem.findall('icon'):
if 'icon' not in d:
d['icon'] = []
icond = {}
set_attrs(icond, iconnode, ('src', 'width', 'height'))
d['icon'].append(icond)
def elem_to_channel(elem):
"""
elem_to_channel(Element) -> dict
Convert channel element to dictionary
"""
d = {'id': elem.get('id'),
'display-name': []}
append_text(d, 'display-name', elem)
append_icons(d, elem)
append_text(d, 'url', elem, with_lang=False)
return d
def read_channels(fp=None, tree=None):
"""
read_channels(fp=None, tree=None) -> list
Return a list of channel dictionaries from file object 'fp' or the
ElementTree 'tree'
"""
if fp:
et = ElementTree()
tree = et.parse(fp)
return [elem_to_channel(elem) for elem in tree.findall('channel')]
def elem_to_programme(elem):
"""
elem_to_programme(Element) -> dict
Convert programme element to dictionary
"""
d = {'start': elem.get('start'),
'channel': elem.get('channel'),
'title': []}
set_attrs(d, elem, ('stop', 'pdc-start', 'vps-start', 'showview',
'videoplus', 'clumpidx'))
append_text(d, 'title', elem)
append_text(d, 'sub-title', elem)
append_text(d, 'desc', elem)
crednode = elem.find('credits')
if crednode is not None:
creddict = {}
# TODO: actor can have a 'role' attribute
for credtype in ('director', 'actor', 'writer', 'adapter', 'producer',
'presenter', 'commentator', 'guest', 'composer',
'editor'):
append_text(creddict, credtype, crednode, with_lang=False)
d['credits'] = creddict
set_text(d, 'date', elem, with_lang=False)
append_text(d, 'category', elem)
set_text(d, 'language', elem)
set_text(d, 'orig-language', elem)
lennode = elem.find('length')
if lennode is not None:
lend = {'units': lennode.get('units'),
'length': lennode.text}
d['length'] = lend
append_icons(d, elem)
append_text(d, 'url', elem, with_lang=False)
append_text(d, 'country', elem)
for epnumnode in elem.findall('episode-num'):
if 'episode-num' not in d:
d['episode-num'] = []
d['episode-num'].append((epnumnode.text,
epnumnode.get('system', 'xmltv_ns')))
vidnode = elem.find('video')
if vidnode is not None:
vidd = {}
for name in ('present', 'colour'):
set_boolean(vidd, name, vidnode)
for videlem in ('aspect', 'quality'):
venode = vidnode.find(videlem)
if venode is not None:
vidd[videlem] = venode.text
d['video'] = vidd
audnode = elem.find('audio')
if audnode is not None:
audd = {}
set_boolean(audd, 'present', audnode)
stereonode = audnode.find('stereo')
if stereonode is not None:
audd['stereo'] = stereonode.text
d['audio'] = audd
psnode = elem.find('previously-shown')
if psnode is not None:
psd = {}
set_attrs(psd, psnode, ('start', 'channel'))
d['previously-shown'] = psd
set_text(d, 'premiere', elem)
set_text(d, 'last-chance', elem)
if elem.find('new') is not None:
d['new'] = True
for stnode in elem.findall('subtitles'):
if 'subtitles' not in d:
d['subtitles'] = []
std = {}
set_attrs(std, stnode, ('type',))
set_text(std, 'language', stnode)
d['subtitles'].append(std)
for ratnode in elem.findall('rating'):
if 'rating' not in d:
d['rating'] = []
ratd = {}
set_attrs(ratd, ratnode, ('system',))
set_text(ratd, 'value', ratnode, with_lang=False)
append_icons(ratd, ratnode)
d['rating'].append(ratd)
for srnode in elem.findall('star-rating'):
if 'star-rating' not in d:
d['star-rating'] = []
srd = {}
set_attrs(srd, srnode, ('system',))
set_text(srd, 'value', srnode, with_lang=False)
append_icons(srd, srnode)
d['star-rating'].append(srd)
for revnode in elem.findall('review'):
if 'review' not in d:
d['review'] = []
rd = {}
set_attrs(rd, revnode, ('type', 'source', 'reviewer',))
set_text(rd, 'value', revnode, with_lang=False)
d['review'].append(rd)
return d
def read_programmes(fp=None, tree=None):
"""
read_programmes(fp=None, tree=None) -> list
Return a list of programme dictionaries from file object 'fp' or the
ElementTree 'tree'
"""
if fp:
et = ElementTree()
tree = et.parse(fp)
return [elem_to_programme(elem) for elem in tree.findall('programme')]
def read_data(fp=None, tree=None):
"""
read_data(fp=None, tree=None) -> dict
Get the source and other info from file object fp or the ElementTree
'tree'
"""
if fp:
et = ElementTree()
tree = et.parse(fp)
d = {}
set_attrs(d, tree, ('date', 'source-info-url', 'source-info-name',
'source-data-url', 'generator-info-name',
'generator-info-url'))
return d
def indent(elem, level=0):
"""
Indent XML for pretty printing
"""
i = "\n" + level*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
class Writer:
"""
A class for generating XMLTV data
**All strings passed to this class must be Unicode, except for dictionary
keys**
"""
def __init__(self, encoding="UTF-8", date=None,
source_info_url=None, source_info_name=None,
generator_info_url=None, generator_info_name=None):
"""
Arguments:
'encoding' -- The text encoding that will be used.
*Defaults to 'UTF-8'*
'date' -- The date this data was generated. *Optional*
'source-info-url' -- A URL for information about the source of the
data. *Optional*
'source-info-name' -- A human readable description of
'source-info-url'. *Optional*
'generator-info-url' -- A URL for information about the program
that is generating the XMLTV document.
*Optional*
'generator-info-name' -- A human readable description of
'generator-info-url'. *Optional*
"""
self.encoding = encoding
self.data = {'date': date,
'source-info-url': source_info_url,
'source-info-name': source_info_name,
'generator-info-url': generator_info_url,
'generator-info-name': generator_info_name}
self.root = Element('tv')
for attr in self.data:
if self.data[attr]:
self.root.set(attr, self.data[attr])
def setattr(self, node, attr, value):
"""
setattr(node, attr, value) -> None
Set 'attr' in 'node' to 'value'
"""
node.set(attr, value)
def settext(self, node, text, with_lang=True):
"""
settext(node, text) -> None
Set 'node's text content to 'text'
"""
if with_lang:
if text[0] == None:
node.text = None
else:
node.text = text[0]
if text[1]:
node.set('lang', text[1])
else:
if text == None:
node.text = None
else:
node.text = text
def seticons(self, node, icons):
"""
seticon(node, icons) -> None
Create 'icons' under 'node'
"""
for icon in icons:
if 'src' not in icon:
raise ValueError("'icon' element requires 'src' attribute")
i = SubElement(node, 'icon')
for attr in ('src', 'width', 'height'):
if attr in icon:
self.setattr(i, attr, icon[attr])
def set_zero_ormore(self, programme, element, p):
"""
set_zero_ormore(programme, element, p) -> None
Add nodes under p for the element 'element', which occurs zero
or more times with PCDATA and a 'lang' attribute
"""
if element in programme:
for item in programme[element]:
e = SubElement(p, element)
self.settext(e, item)
def set_zero_orone(self, programme, element, p):
"""
set_zero_ormore(programme, element, p) -> None
Add nodes under p for the element 'element', which occurs zero
times or once with PCDATA and a 'lang' attribute
"""
if element in programme:
e = SubElement(p, element)
self.settext(e, programme[element])
def addProgramme(self, programme):
"""
Add a single XMLTV 'programme'
Arguments:
'programme' -- A dict representing XMLTV data
"""
p = SubElement(self.root, 'programme')
# programme attributes
for attr in ('start', 'channel'):
if attr in programme:
self.setattr(p, attr, programme[attr])
else:
raise ValueError("'programme' must contain '%s' attribute" % attr)
for attr in ('stop', 'pdc-start', 'vps-start', 'showview', 'videoplus', 'clumpidx'):
if attr in programme:
self.setattr(p, attr, programme[attr])
for title in programme['title']:
t = SubElement(p, 'title')
self.settext(t, title)
# Sub-title and description
for element in ('sub-title', 'desc'):
self.set_zero_ormore(programme, element, p)
# Credits
if 'credits' in programme:
c = SubElement(p, 'credits')
for credtype in ('director', 'actor', 'writer', 'adapter',
'producer', 'presenter', 'commentator', 'guest'):
if credtype in programme['credits']:
for name in programme['credits'][credtype]:
cred = SubElement(c, credtype)
self.settext(cred, name, with_lang=False)
# Date
if 'date' in programme:
d = SubElement(p, 'date')
self.settext(d, programme['date'], with_lang=False)
# Category
self.set_zero_ormore(programme, 'category', p)
# Language and original language
for element in ('language', 'orig-language'):
self.set_zero_orone(programme, element, p)
# Length
if 'length' in programme:
l = SubElement(p, 'length')
self.setattr(l, 'units', programme['length']['units'])
self.settext(l, programme['length']['length'], with_lang=False)
# Icon
if 'icon' in programme:
self.seticons(p, programme['icon'])
# URL
if 'url' in programme:
for url in programme['url']:
u = SubElement(p, 'url')
self.settext(u, url, with_lang=False)
# Country
self.set_zero_ormore(programme, 'country', p)
# Episode-num
if 'episode-num' in programme:
for epnum in programme['episode-num']:
e = SubElement(p, 'episode-num')
self.setattr(e, 'system', epnum[1])
self.settext(e, epnum[0], with_lang=False)
# Video details
if 'video' in programme:
e = SubElement(p, 'video')
for videlem in ('aspect', 'quality'):
if videlem in programme['video']:
v = SubElement(e, videlem)
self.settext(v, programme['video'][videlem], with_lang=False)
for attr in ('present', 'colour'):
if attr in programme['video']:
a = SubElement(e, attr)
if programme['video'][attr]:
self.settext(a, 'yes', with_lang=False)
else:
self.settext(a, 'no', with_lang=False)
# Audio details
if 'audio' in programme:
a = SubElement(p, 'audio')
if 'stereo' in programme['audio']:
s = SubElement(a, 'stereo')
self.settext(s, programme['audio']['stereo'], with_lang=False)
if 'present' in programme['audio']:
p = SubElement(a, 'present')
if programme['audio']['present']:
self.settext(p, 'yes', with_lang=False)
else:
self.settext(p, 'no', with_lang=False)
# Previously shown
if 'previously-shown' in programme:
ps = SubElement(p, 'previously-shown')
for attr in ('start', 'channel'):
if attr in programme['previously-shown']:
self.setattr(ps, attr, programme['previously-shown'][attr])
# Premiere / last chance
for element in ('premiere', 'last-chance'):
self.set_zero_orone(programme, element, p)
# New
if 'new' in programme:
n = SubElement(p, 'new')
# Subtitles
if 'subtitles' in programme:
for subtitles in programme['subtitles']:
s = SubElement(p, 'subtitles')
if 'type' in subtitles:
self.setattr(s, 'type', subtitles['type'])
if 'language' in subtitles:
l = SubElement(s, 'language')
self.settext(l, subtitles['language'])
# Rating
if 'rating' in programme:
for rating in programme['rating']:
r = SubElement(p, 'rating')
if 'system' in rating:
self.setattr(r, 'system', rating['system'])
v = SubElement(r, 'value')
self.settext(v, rating['value'], with_lang=False)
if 'icon' in rating:
self.seticons(r, rating['icon'])
# Star rating
if 'star-rating' in programme:
for star_rating in programme['star-rating']:
sr = SubElement(p, 'star-rating')
if 'system' in star_rating:
self.setattr(sr, 'system', star_rating['system'])
v = SubElement(sr, 'value')
self.settext(v, star_rating['value'], with_lang=False)
if 'icon' in star_rating:
self.seticons(sr, rating['icon'])
# Review
if 'review' in programme:
for review in programme['review']:
r = SubElement(p, 'review')
for attr in ('type', 'source', 'reviewer'):
if attr in review:
self.setattr(r, attr, review[attr])
v = SubElement(r, 'value')
self.settext(v, review['value'], with_lang=False)
def addChannel(self, channel):
"""
add a single XMLTV 'channel'
Arguments:
'channel' -- A dict representing XMLTV data
"""
c = SubElement(self.root, 'channel')
self.setattr(c, 'id', channel['id'])
# Display Name
for display_name in channel['display-name']:
dn = SubElement(c, 'display-name')
self.settext(dn, display_name)
# Icon
if 'icon' in channel:
self.seticons(c, channel['icon'])
# URL
if 'url' in channel:
for url in channel['url']:
u = SubElement(c, 'url')
self.settext(u, url, with_lang=False)
def write(self, file, pretty_print=False):
"""
write(file, pretty_print=False) -> None
Write XML to filename of file object in 'file'. If pretty_print is
True, the XML will contain whitespace to make it human-readable.
"""
if pretty_print:
indent(self.root)
et = ElementTree(self.root)
et.write(file, self.encoding, xml_declaration=True)
if __name__ == '__main__':
# Tests
from pprint import pprint
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import sys
# An example file
xmldata = StringIO("""<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE tv SYSTEM "xmltv.dtd">
<tv date="20030811003608 -0300" source-info-url="http://www.funktronics.ca/python-xmltv" source-info-name="Funktronics" generator-info-name="python-xmltv" generator-info-url="http://www.funktronics.ca/python-xmltv">
<channel id="C10eltv.zap2it.com">
<display-name>Channel 10 ELTV</display-name>
<url>http://www.eastlink.ca/</url>
</channel>
<channel id="C11cbht.zap2it.com">
<display-name lang="en">Channel 11 CBHT</display-name>
<icon src="http://tvlistings2.zap2it.com/tms_network_logos/cbc.gif"/>
</channel>
<programme start="20030702000000 ADT" channel="C23robtv.zap2it.com" stop="20030702003000 ADT">
<title>This Week in Business</title>
<category>Biz</category>
<category>Fin</category>
<date>2003</date>
<audio>
<stereo>stereo</stereo>
</audio>
</programme>
<programme start="20030702000000 ADT" channel="C36wuhf.zap2it.com" stop="20030702003000 ADT">
<title>Seinfeld</title>
<sub-title>The Engagement</sub-title>
<desc>In an effort to grow up, George proposes marriage to former girlfriend Susan.</desc>
<category>Comedy</category>
<country>USA</country>
<language>English</language>
<orig-language>English</orig-language>
<premiere lang="en">Not really. Just testing</premiere>
<last-chance>Hah!</last-chance>
<credits>
<actor>Jerry Seinfeld</actor>
<producer>Larry David</producer>
<composer>Jonathan Wolff</composer>
</credits>
<date>1995</date>
<length units="minutes">22</length>
<episode-num system="xmltv_ns">7 . 1 . 1/1</episode-num>
<video>
<colour>yes</colour>
<present>yes</present>
<aspect>4:3</aspect>
<quality>standard</quality>
</video>
<audio>
<stereo>stereo</stereo>
</audio>
<previously-shown start="19950921103000 ADT" channel="C12whdh.zap2it.com"/>
<new/>
<subtitles type="teletext">
<language>English</language>
</subtitles>
<rating system="VCHIP">
<value>PG</value>
<icon src="http://some.ratings/PGicon.png" width="64" height="64"/>
</rating>
<star-rating>
<value>4/5</value>
<icon src="http://some.star/icon.png" width="32" height="32"/>
</star-rating>
<review type="url">
<value>http://some.review/</value>
</review>
<url>http://www.nbc.com</url>
</programme>
</tv>
""")
pprint(read_data(xmldata))
xmldata.seek(0)
pprint(read_channels(xmldata))
xmldata.seek(0)
pprint(read_programmes(xmldata))
# Test the writer
programmes = [{'audio': {'stereo': u'stereo'},
'category': [(u'Biz', u''), (u'Fin', u'')],
'channel': u'C23robtv.zap2it.com',
'date': u'2003',
'start': u'20030702000000 ADT',
'stop': u'20030702003000 ADT',
'title': [(u'This Week in Business', u'')]},
{'audio': {'stereo': u'stereo'},
'category': [(u'Comedy', u'')],
'channel': u'C36wuhf.zap2it.com',
'country': [(u'USA', u'')],
'credits': {'producer': [u'Larry David'], 'actor': [u'Jerry Seinfeld']},
'date': u'1995',
'desc': [(u'In an effort to grow up, George proposes marriage to former girlfriend Susan.',
u'')],
'episode-num': [(u'7 . 1 . 1/1', u'xmltv_ns')],
'language': (u'English', u''),
'last-chance': (u'Hah!', u''),
'length': {'units': u'minutes', 'length': '22'},
'new': True,
'orig-language': (u'English', u''),
'premiere': (u'Not really. Just testing', u'en'),
'previously-shown': {'channel': u'C12whdh.zap2it.com',
'start': u'19950921103000 ADT'},
'rating': [{'icon': [{'height': u'64',
'src': u'http://some.ratings/PGicon.png',
'width': u'64'}],
'system': u'VCHIP',
'value': u'PG'}],
'review': [{'type': 'url', 'value': 'http://some.review/'}],
'star-rating': [{'icon': [{'height': u'32',
'src': u'http://some.star/icon.png',
'width': u'32'}],
'value': u'4/5'}],
'start': u'20030702000000 ADT',
'stop': u'20030702003000 ADT',
'sub-title': [(u'The Engagement', u'')],
'subtitles': [{'type': u'teletext', 'language': (u'English', u'')}],
'title': [(u'Seinfeld', u'')],
'url': [(u'http://www.nbc.com/')],
'video': {'colour': True, 'aspect': u'4:3', 'present': True,
'quality': 'standard'}}]
channels = [{'display-name': [(u'Channel 10 ELTV', u'')],
'id': u'C10eltv.zap2it.com',
'url': [u'http://www.eastlink.ca/']},
{'display-name': [(u'Channel 11 CBHT', u'en')],
'icon': [{'src': u'http://tvlistings2.zap2it.com/tms_network_logos/cbc.gif'}],
'id': u'C11cbht.zap2it.com'}]
w = Writer(encoding="us-ascii",
date="20030811003608 -0300",
source_info_url="http://www.funktronics.ca/python-xmltv",
source_info_name="Funktronics",
generator_info_name="python-xmltv",
generator_info_url="http://www.funktronics.ca/python-xmltv")
for c in channels:
w.addChannel(c)
for p in programmes:
w.addProgramme(p)
try:
w.write(sys.stdout.buffer, pretty_print=True)
except AttributeError:
w.write(sys.stdout, pretty_print=True)