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):
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 len(self.splitted_path)>3:
32 connection.dieWithError()
35 if len(self.splitted_path)<3:
37 m3u_file=config.m3u_directory+'/'+config.m3u_default
41 if self.splitted_path[2]=='index':
42 for dir in os.walk(config.m3u_directory):
43 if dir[0]==config.m3u_directory:
44 text='\n'.join(dir[2])
46 connection.send_response(200)
47 connection.send_header('Content-Type', 'text/plain')
48 connection.end_headers()
50 listing = text.encode('utf-8')
51 connection.wfile.write(listing)
55 m3u_file=config.m3u_directory+'/'+self.splitted_path[2]
57 connection.send_response(200)
58 connection.send_header('Content-Type', 'application/x-mpegurl')
59 connection.end_headers()
62 playlist=parseM3U(m3u_file)
64 connection.dieWithError()
68 connection.dieWithError()
71 playlistgen = PlaylistGenerator()
73 for record in playlist:
75 channel['name']=record.title.decode('utf-8')
76 channel['url']=record.path.decode('utf-8')
77 playlistgen.addItem(channel)
79 exported = playlistgen.exportm3u(hostport)
80 exported = exported.encode('utf-8')
81 connection.wfile.write(exported)
83 def getparam(self, key):
84 if key in self.params:
85 return self.params[key][0]