4 (based on ytv plugin by ValdikSS)
6 http://ip:port/m3u/index
7 http://ip:port/m3u{/list-name}
12 from modules.PluginInterface import VPProxyPlugin
13 from modules.PlaylistGenerator import PlaylistGenerator
14 from modules.M3uParser import parseM3U
15 import config.m3u as config
18 class M3u(VPProxyPlugin):
20 handlers = ('m3u', 'm3ut' )
22 logger = logging.getLogger('plugin_m3u')
25 def handle(self, connection):
27 hostport = connection.headers['Host']
29 self.splitted_path=connection.path.split('/')
31 if self.splitted_path[1]=='m3u':
33 elif self.splitted_path[1]=='m3ut':
36 connection.dieWithError(404)
38 if len(self.splitted_path)>3:
39 connection.dieWithError()
42 if len(self.splitted_path)<3:
44 m3u_file=config.m3u_directory+'/'+config.m3u_default
48 if self.splitted_path[2]=='index':
49 for dir in os.walk(config.m3u_directory):
50 if dir[0]==config.m3u_directory:
51 text='\n'.join(dir[2])
53 connection.send_response(200)
54 connection.send_header('Content-Type', 'text/plain')
55 connection.end_headers()
57 listing = text.encode('utf-8')
58 connection.wfile.write(listing)
62 m3u_file=config.m3u_directory+'/'+self.splitted_path[2]
64 connection.send_response(200)
65 connection.send_header('Content-Type', 'application/x-mpegurl')
66 connection.end_headers()
69 playlist=parseM3U(m3u_file)
71 connection.dieWithError(404)
75 connection.dieWithError()
78 playlistgen = PlaylistGenerator()
80 for record in playlist:
82 channel['name']=record.title.decode('utf-8')
83 channel['url']=record.path.decode('utf-8')
84 playlistgen.addItem(channel)
86 exported = playlistgen.exportm3u(hostport,prefix)
87 exported = exported.encode('utf-8')
88 connection.wfile.write(exported)
90 def getparam(self, key):
91 if key in self.params:
92 return self.params[key][0]