Converter ClientSstreaming: add three query modes.
authorErik Slagter <erik@openpli.org>
Thu, 17 Dec 2015 21:19:02 +0000 (22:19 +0100)
committerErik Slagter <erik@openpli.org>
Thu, 17 Dec 2015 21:19:02 +0000 (22:19 +0100)
INFO: get a complete list of all clients including streaming/transcoding,
client's address and the service (resolved)
INFO_RESOLVE: same as above but resolve the client's address (slow!)
INFO_RESOLVE_SHORT: same as INFO_RESOLVE but only show the host part of
the client's address, no domain part.

lib/python/Components/Converter/ClientsStreaming.py

index f3ff51b..71fc923 100644 (file)
@@ -3,8 +3,10 @@ from Poll import Poll
 from Components.Element import cached
 from enigma import eStreamServer
 from ServiceReference import ServiceReference
+import socket
 
 class ClientsStreaming(Converter, Poll, object):
+       UNKNOWN = -1
        REF = 0
        IP = 1
        NAME = 2
@@ -12,6 +14,9 @@ class ClientsStreaming(Converter, Poll, object):
        NUMBER = 4
        SHORT_ALL = 5
        ALL = 6
+       INFO = 7
+       INFO_RESOLVE = 8
+       INFO_RESOLVE_SHORT = 9
 
        def __init__(self, type):
                Converter.__init__(self, type)
@@ -30,8 +35,17 @@ class ClientsStreaming(Converter, Poll, object):
                        self.type = self.NUMBER
                elif type == "SHORT_ALL":
                        self.type = self.SHORT_ALL
-               else:
+               elif type == "ALL":
                        self.type = self.ALL
+               elif type == "INFO":
+                       self.type = self.INFO
+               elif type == "INFO_RESOLVE":
+                       self.type = self.INFO_RESOLVE
+               elif type == "INFO_RESOLVE_SHORT":
+                       self.type = self.INFO_RESOLVE_SHORT
+               else:
+                       self.type = self.UNKNOWN
+
                self.streamServer = eStreamServer.getInstance()
 
        @cached
@@ -44,6 +58,8 @@ class ClientsStreaming(Converter, Poll, object):
                ips = []
                names = []
                encoders = []
+               info = ""
+
                for x in self.streamServer.getConnectedClients():
                        refs.append((x[1]))
                        servicename = ServiceReference(x[1]).getServiceName() or "(unknown service)"
@@ -54,11 +70,26 @@ class ClientsStreaming(Converter, Poll, object):
                        ips.append((ip))
 
                        if int(x[2]) == 0:
+                               strtype = "S"
                                encoder = _('NO')
                        else:
+                               strtype = "T"
                                encoder = _('YES')
 
                        encoders.append((encoder))
+
+                       if self.type == self.INFO_RESOLVE or self.type == self.INFO_RESOLVE_SHORT:
+                               try:
+                                       raw = socket.gethostbyaddr(ip)
+                                       ip  = raw[0]
+                               except:
+                                       pass
+
+                               if self.type == self.INFO_RESOLVE_SHORT:
+                                       ip, sep, tail = ip.partition('.')
+
+                       info += ("%s %-8s %s\n") % (strtype, ip, service_name)
+
                        clients.append((ip, service_name, encoder))
 
                if self.type == self.REF:
@@ -73,8 +104,13 @@ class ClientsStreaming(Converter, Poll, object):
                        return str(len(clients))
                elif self.type == self.SHORT_ALL:
                        return _("Total clients streaming: %d (%s)") % (len(clients), ' '.join(names))
-               else:
+               elif self.type == self.ALL:
                        return '\n'.join(' '.join(elems) for elems in clients)
+               elif self.type == self.INFO or self.type == self.INFO_RESOLVE or self.type == self.INFO_RESOLVE_SHORT:
+                       return info
+               else:
+                       return "(unknown)"
+
                return ""
 
        text = property(getText)