# -*- coding: UTF-8 -*- import sys, socket, urllib, locale FILES = { '': 'text/html', 'playlist.m3u': 'application/x-mpegurl', 'layout.css': 'text/css', 'controls.js': 'application/javascript' } TEMPLATE='''\ VideoRelay
Quality:

Resolution:

%s
 
Target URL:


''' channels_py_example = '''\ # -*- coding: UTF-8 -*- def multicast(*args): return list(args) CHANNELS = [ [u"Channel name", "rtp://232.10.10.10:1234/", "GROUP"], ] ''' try: from channels import CHANNELS except ImportError, err: if str(err).startswith("No module"): print "ERROR: no channels.py file. Example file:" print channels_py_example sys.exit() raise class page(object): def __init__(self): locale.setlocale(locale.LC_COLLATE, 'sk_SK.utf8') CHANNELS.sort(locale.strcoll, key=lambda x: x[0]) # get channel list self.ch_groups = ['Favorites', 'TV', 'HDTV', 'Radio'] for ch_name, ch_url, ch_grp in CHANNELS: if ch_grp=="TEST": continue if ch_grp not in self.ch_groups: self.ch_groups.append(ch_grp) self.channels = CHANNELS def rtp2url(self, ch_name, ch_url): ch_name = ch_name.replace("/", "-").encode("UTF-8") ch_ip = ch_url.split("/")[2].split(":")[0] url = "ip=%s//%s" % (ch_ip, urllib.quote_plus(ch_name)) return ch_name, url def index(self, prefix=""): ret = [] for group in self.ch_groups: #ksort($chlist, SORT_LOCALE_STRING); ret.append('
%s:
' % group) ret.append( '''
') return TEMPLATE % (prefix, '\n'.join(ret)) def m3u(self, prefix="", format="rawvideo"): ret = ["#EXTM3U"] for group in ['Favorites', 'TV']: for ch_name, ch_url, ch_grp in self.channels: if ch_grp!=group: continue ch_name, url = self.rtp2url(ch_name, ch_url) ret.append("#EXTINF:-1,%s" % ch_name) ret.append("%s/%s/%s" % (prefix, format, url)) return "\n".join(ret)+"\n" if __name__=="__main__": print page().index()