+ else:
+
+ filename = self.splitted_path[2]
+ if filename:
+ m3u_file=config.m3u_directory+'/'+self.splitted_path[2]
+ else:
+ m3u_file=config.m3u_directory+'/'+config.m3u_default
+
+ try:
+ playlist=parseM3U(m3u_file)
+ except:
+ connection.dieWithError(404)
+ return
+
+ if self.splitted_path[1]=="list":
+ connection.send_response(200)
+ connection.send_header('Content-Type', 'text/plain; charset=utf-8')
+ connection.end_headers()
+ elif self.splitted_path[1]=="play":
+ channel=self.splitted_path[len(self.splitted_path)-1]
+ channel=urllib.unquote(channel).decode('utf-8')
+ if len(self.splitted_path)<=4:
+ prefix="get"
+ elif len(self.splitted_path)==5:
+ prefix=self.splitted_path[len(self.splitted_path)-2]
+ if prefix not in ('get','mp4','webm'):
+ connection.dieWithError()
+ else:
+ connection.dieWithError()
+ url=None
+ for record in playlist:
+ if record.title.decode('utf-8').replace('/','')==channel:
+ url=record.path.decode('utf-8')
+ if url:
+ redirect='/'+prefix+'/'+url
+ connection.send_response(302)
+ connection.send_header('Location', redirect)
+ connection.end_headers()
+ else:
+ connection.dieWithError(404)
+
+ else:
+ connection.send_response(200)
+ connection.send_header('Content-Type', 'application/x-mpegurl')
+ connection.end_headers()