-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvodserver.py
More file actions
executable file
·94 lines (78 loc) · 1.89 KB
/
vodserver.py
File metadata and controls
executable file
·94 lines (78 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
import os
import sys
import time
import socket
import udpsender
def valid_ip(ip):
try:
socket.inet_aton(ip)
return True
except:
return False
hint = '''\
Usage: %s [IP]
''' % __file__
if len(sys.argv) == 1:
ip = '255.255.255.255'
elif len(sys.argv) == 2:
if sys.argv[1] == '-h':
print hint
sys.exit()
else:
ip = sys.argv[1]
print ip
if not valid_ip(ip):
print 'Error: invalid ip address'
sys.exit(1)
else:
print 'Error: multiple arguments'
print usage
sys.exit(2)
path = os.path.split(os.path.realpath(__file__))[0]
senders = {}
try:
f = open(path + os.path.sep + 'videomap', 'r')
except IOError as e:
print 'Error:', e
sys.exit(2)
for line in f.readlines():
line = line.strip()
if not len(line) or line.startswith('#'):
continue
try:
fip, fport, fname, fbr = line.split('|')
except Exception as e:
print 'Warning:', e
continue
if (fip is None) or (fport is None) or (fname is None):
continue
fip = fip.strip()
fport = fport.strip()
fname = path + os.path.sep + fname.strip()
if fbr[-1] in ('m', 'M'):
bitrate = float(fbr[:-1]) * 1024 * 1024
elif fbr[-1] in ('k', 'K'):
bitrate = float(fbr[:-1]) * 1024
elif fbr == '*':
bitrate = detect_bitrate(fname)
else:
bitrate = float(a)
faddr = (fip, int(fport))
if faddr not in senders.keys():
senders[faddr] = udpsender.Sender(
fname, (ip, int(fport)), True, bitrate=bitrate)
senders[faddr].start()
f.close()
print 'Vod server is now running.'
print 'Press q to exit.'
try:
while True:
i = raw_input('# ').strip()
if i == 'q':
break
finally:
print 'Bye'
for k in senders.keys():
senders[k].stop()
del senders[k]