transcoding option for web-video added
[vpproxy.git] / clientcounter.py
1 '''
2 Simple Client Counter for VLC VLM
3 '''
4
5
6 class ClientCounter(object):
7
8     def __init__(self):
9         self.clients = dict()
10         self.total = 0
11
12     def get(self, id):
13         return self.clients.get(id, (False,))[0]
14
15     def add(self, id, ip):
16         if self.clients.has_key(id):
17             self.clients[id][0] += 1
18             self.clients[id][1].append(ip)
19         else:
20             self.clients[id] = [1, [ip]]
21
22         self.total += 1
23         return self.clients[id][0]
24
25     def delete(self, id, ip):
26         if self.clients.has_key(id):
27             self.total -= 1
28             if self.clients[id][0] == 1:
29                 del self.clients[id]
30                 return False
31             else:
32                 self.clients[id][0] -= 1
33                 self.clients[id][1].remove(ip)
34         else:
35             return False
36
37         print "Total:", self.total
38         return self.clients[id][0]
39