3 This module can generate .m3u playlists with tv guide
9 class PlaylistGenerator(object):
12 '#EXTM3U url-tvg="http://www.teleguide.info/download/new3/jtv.zip"\n'
13 m3uemptyheader = '#EXTM3U\n'
14 m3uchanneltemplate = \
15 '#EXTINF:-1 group-title="%s" tvg-name="%s" tvg-logo="%s" country="%s",%s\n%s\n'
18 self.itemlist = list()
20 def addItem(self, itemdict):
23 itemdict is a dictionary with the following fields:
26 tvg - item JTV name (optional)
27 country - country of origin (optional)
28 group - item playlist group (optional)
29 logo - item logo file name (optional)
31 self.itemlist.append(itemdict)
34 def _generatem3uline(item):
36 Generates EXTINF line with url
39 return PlaylistGenerator.m3uchanneltemplate % (
40 item.get('group', ''),
43 item.get('country', ''),
47 def exportm3u(self, hostport, prefix="get", add_ts=False, empty_header=False, archive=False):
52 itemlist = PlaylistGenerator.m3uheader
54 itemlist = PlaylistGenerator.m3uemptyheader
56 # Adding ts:// after http:// for some players
57 hostport = 'ts://' + hostport
59 for item in self.itemlist:
60 item['tvg'] = item.get('tvg', '') if item.get('tvg') else \
61 item.get('name').replace(' ', '_')
62 # For .acelive and .torrent
63 item['url'] = 'http://' + hostport + '/' + prefix + '/' + item['url']
64 itemlist += PlaylistGenerator._generatem3uline(item)
72 itemlist = PlaylistGenerator.m3uemptyheader
74 for item in self.itemlist:
75 item['tvg'] = item.get('tvg', '') if item.get('tvg') else \
76 item.get('name').replace(' ', '_')
77 # For .acelive and .torrent
78 itemlist += PlaylistGenerator._generatem3uline(item)