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', 'm3uw')
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]=='m3uw':
35 elif self.splitted_path[1]=='m3ut':
38 connection.dieWithError(404)
40 if len(self.splitted_path)>3:
41 connection.dieWithError()
44 if len(self.splitted_path)<3:
46 m3u_file=config.m3u_directory+'/'+config.m3u_default
50 if self.splitted_path[2]=='index':
51 for dir in os.walk(config.m3u_directory):
52 if dir[0]==config.m3u_directory:
53 text='\n'.join(dir[2])
55 connection.send_response(200)
56 connection.send_header('Content-Type', 'text/plain')
57 connection.end_headers()
59 listing = text.encode('utf-8')
60 connection.wfile.write(listing)
64 m3u_file=config.m3u_directory+'/'+self.splitted_path[2]
66 connection.send_response(200)
67 connection.send_header('Content-Type', 'application/x-mpegurl')
68 connection.end_headers()
71 playlist=parseM3U(m3u_file)
73 connection.dieWithError(404)
77 connection.dieWithError()
80 playlistgen = PlaylistGenerator()
82 for record in playlist:
84 channel['name']=record.title.decode('utf-8')
85 channel['url']=record.path.decode('utf-8')
86 playlistgen.addItem(channel)
88 exported = playlistgen.exportm3u(hostport,prefix)
89 exported = exported.encode('utf-8')
90 connection.wfile.write(exported)
92 def getparam(self, key):
93 if key in self.params:
94 return self.params[key][0]