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",%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 group - item playlist group (optional)
28 logo - item logo file name (optional)
30 self.itemlist.append(itemdict)
33 def _generatem3uline(item):
35 Generates EXTINF line with url
37 return PlaylistGenerator.m3uchanneltemplate % (
38 item.get('group', ''), item.get('tvg', ''), item.get('logo', ''),
39 item.get('name'), item.get('url'))
41 def exportm3u(self, hostport, prefix="get", add_ts=False, empty_header=False, archive=False):
46 itemlist = PlaylistGenerator.m3uheader
48 itemlist = PlaylistGenerator.m3uemptyheader
50 # Adding ts:// after http:// for some players
51 hostport = 'ts://' + hostport
53 for item in self.itemlist:
54 item['tvg'] = item.get('tvg', '') if item.get('tvg') else \
55 item.get('name').replace(' ', '_')
56 # For .acelive and .torrent
57 item['url'] = 'http://' + hostport + '/' + prefix + '/' + item['url']
58 itemlist += PlaylistGenerator._generatem3uline(item)