Обработка Unicode-листов, убрана отладочная печать.
authorRoman Bazalevsky <rvb@rvb.name>
Thu, 22 Oct 2015 10:12:28 +0000 (13:12 +0300)
committerRoman Bazalevsky <rvb@rvb.name>
Thu, 22 Oct 2015 10:12:28 +0000 (13:12 +0300)
clientcounter.py
plugins/m3u_plugin.py
plugins/modules/M3uParser.py
vlcclient/vlcclient.py
vphttp.py

index bd86cbeeeb01c499dec022991b1b032fb56a9a29..bcfd0b2eff746eb230f48297f6a1edf2e65d6d8e 100644 (file)
@@ -34,6 +34,5 @@ class ClientCounter(object):
         else:
             return False
 
         else:
             return False
 
-        print "Total:", self.total
         return self.clients[id][0]
 
         return self.clients[id][0]
 
index fc4d3e3268e75e36d3a7cdb583f8992609a6a68e..00a6193f674184bdcb777c7b28ef04f6a176d846 100644 (file)
@@ -104,7 +104,6 @@ class M3u(VPProxyPlugin):
         elif self.splitted_path[1]=="play":
             channel=self.splitted_path[len(self.splitted_path)-1]
             channel=urllib.unquote(channel).decode('utf-8')
         elif self.splitted_path[1]=="play":
             channel=self.splitted_path[len(self.splitted_path)-1]
             channel=urllib.unquote(channel).decode('utf-8')
-            print channel
             if len(self.splitted_path)<=4:
               prefix="get"
             elif len(self.splitted_path)==5:  
             if len(self.splitted_path)<=4:
               prefix="get"
             elif len(self.splitted_path)==5:  
@@ -117,10 +116,8 @@ class M3u(VPProxyPlugin):
             for record in playlist:
                 if record.title.decode('utf-8').replace('/','')==channel:
                     url=record.path.decode('utf-8')
             for record in playlist:
                 if record.title.decode('utf-8').replace('/','')==channel:
                     url=record.path.decode('utf-8')
-                    print url
             if url:
                 redirect='/'+prefix+'/'+url
             if url:
                 redirect='/'+prefix+'/'+url
-                print redirect
                 connection.send_response(302)
                 connection.send_header('Location', redirect)
                 connection.end_headers()
                 connection.send_response(302)
                 connection.send_header('Location', redirect)
                 connection.end_headers()
@@ -147,7 +144,8 @@ class M3u(VPProxyPlugin):
              exported = ""
             
              for record in playlist:
              exported = ""
             
              for record in playlist:
-                 exported = exported + "" + record.title.decode('utf-8').replace('/','') + "\n"
+                 if record.title:
+                     exported = exported + "" + record.title.decode('utf-8').replace('/','') + "\n"
         
         else:    
 
         
         else:    
 
@@ -160,8 +158,9 @@ class M3u(VPProxyPlugin):
                 playlistgen.addItem(channel)
 
             exported = playlistgen.exportm3u(hostport,prefix)
                 playlistgen.addItem(channel)
 
             exported = playlistgen.exportm3u(hostport,prefix)
-            
+
         exported = exported.encode('utf-8')
         exported = exported.encode('utf-8')
+        
         connection.wfile.write(exported)
 
     def getparam(self, key):
         connection.wfile.write(exported)
 
     def getparam(self, key):
index 01dbcc9f73ecdf2d1ba7cf04bdcf0739746afa8c..9e2fce64aeb79ffdb7d69bcb84c0ed2d5a256bb5 100644 (file)
@@ -2,6 +2,8 @@
 # http://n4k3d.com/the-m3u-file-format/
 
 import sys
 # http://n4k3d.com/the-m3u-file-format/
 
 import sys
+import hexdump
+import codecs
 
 class track():
     def __init__(self, length, title, path):
 
 class track():
     def __init__(self, length, title, path):
@@ -23,6 +25,9 @@ def parseM3U(infile):
         #EXTM3U
     # this is not a valid M3U and we should stop..
     line = inf.readline()
         #EXTM3U
     # this is not a valid M3U and we should stop..
     line = inf.readline()
+    line = line.lstrip('\xef\xbb\xbf')
+    line = line.rstrip('\n')
+    line = line.strip()
     if not line.startswith('#EXTM3U'):
        return
 
     if not line.startswith('#EXTM3U'):
        return
 
@@ -31,10 +36,13 @@ def parseM3U(infile):
     song=track(None,None,None)
 
     for line in inf:
     song=track(None,None,None)
 
     for line in inf:
-        line=line.strip()
+        line = line.lstrip('\xef\xbb\xbf')
+        line = line.rstrip('\n')
+        line = line.strip()
         if line.startswith('#EXTINF:'):
             # pull length and title from #EXTINF line
             length,title=line.split('#EXTINF:')[1].split(',',1)
         if line.startswith('#EXTINF:'):
             # pull length and title from #EXTINF line
             length,title=line.split('#EXTINF:')[1].split(',',1)
+            title=title.decode('string_escape')
             song=track(length,title,None)
         elif (len(line) != 0):
             # pull song path from all other, non-blank lines
             song=track(length,title,None)
         elif (len(line) != 0):
             # pull song path from all other, non-blank lines
index 048fd2ffe40d76bd96c7d29769fb43da465592af..dbe6f3fe395e48466029bc265b7369a4f95c0912 100644 (file)
@@ -98,13 +98,16 @@ class VlcClient(object):
                 pass
 
     def _write(self, message):
                 pass
 
     def _write(self, message):
+
+        logger = logging.getLogger("VlcClient_write")
+
         # Return if in the middle of destroying
         if self._shuttingDown.isSet():
             return
 
         try:
             # Write message
         # Return if in the middle of destroying
         if self._shuttingDown.isSet():
             return
 
         try:
             # Write message
-            print 'VLC command:',message
+            logger.debug('VLC command:',message)
             self._socket.write(message + "\r\n")
         except EOFError as e:
             raise VlcException("Vlc Write error! ERROR: " + repr(e))
             self._socket.write(message + "\r\n")
         except EOFError as e:
             raise VlcException("Vlc Write error! ERROR: " + repr(e))
@@ -150,7 +153,7 @@ class VlcClient(object):
             logger.debug("Broadcast stopped")
 
     def startBroadcast(self, stream_name, input, muxer='ts', pre_access='', qtype='default'):
             logger.debug("Broadcast stopped")
 
     def startBroadcast(self, stream_name, input, muxer='ts', pre_access='', qtype='default'):
-        print "Starting broadcast......"
+        logger.debig("Starting broadcast......")
         return self._broadcast(True, stream_name, input, muxer, pre_access, qtype)
 
     def stopBroadcast(self, stream_name):
         return self._broadcast(True, stream_name, input, muxer, pre_access, qtype)
 
     def stopBroadcast(self, stream_name):
index d5f90181ee05a141fb707dc3a35802df21c8b0e7..bda34851d4be98e4ef5b7df5b6ef2d710e5e44ee 100644 (file)
--- a/vphttp.py
+++ b/vphttp.py
@@ -187,7 +187,6 @@ class HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
     def handleRequest(self, headers_only):
 
         # Limit concurrent connections
     def handleRequest(self, headers_only):
 
         # Limit concurrent connections
-        print VPStuff.clientcounter.total
         if 0 < VPConfig.maxconns <= VPStuff.clientcounter.total:
             logger.debug("Maximum connections reached, can't serve this")
             self.dieWithError(503)  # 503 Service Unavailable
         if 0 < VPConfig.maxconns <= VPStuff.clientcounter.total:
             logger.debug("Maximum connections reached, can't serve this")
             self.dieWithError(503)  # 503 Service Unavailable