-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveReplicator.py
More file actions
71 lines (57 loc) · 2.38 KB
/
LiveReplicator.py
File metadata and controls
71 lines (57 loc) · 2.38 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
import datetime
import optparse
import sys
from urlparse import urlparse
from twisted.internet import reactor
from twisted.python import log
from dash.DashPuller import DashPuller
from dash.DashPusher import DashPusher
from common.Statistic import Statistics
import logging
root = logging.getLogger()
root.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
def parse_args():
parser = optparse.OptionParser(usage=__doc__)
parser.add_option("-s", "--src", type="string", dest="source", help="Set source HTTP path (master manifest)")
parser.add_option("-m", "--mpd-repeat", type="int", dest="mpd_repeat", help="Repeat manifest for every x rounds", default = 1)
parser.add_option("-i", "--init-repeat", type="int", dest="init_repeat", help="Repeat init segment for every x rounds", default = 5)
parser.add_option("-D", "--delete-after", type="int", dest="delete_after", help="Delete segments after x seconds", default = 60)
(options, args) = parser.parse_args()
if not options.source:
parser.error('Source path must be set')
if not args:
parser.error('No destination is given.')
def check_url(url):
x = urlparse(url)
if not x.scheme or not x.netloc:
parser.error('{} is not proper url.'.format(url))
# check validity
check_url(options.source)
map(check_url, args)
# copy the arguments to the option tuple
options.destination = args
return options
def proxy_main():
logger = logging.getLogger(__name__)
""" Parse argument """
options = parse_args()
logger.info("Started: %s", datetime.datetime.now())
stat = Statistics()
""" Pulling data and buffer them internally """
if options.source.endswith(".mpd"):
puller = DashPuller(options.source)
pusher = DashPusher(options.destination, puller.consume, stat,
mpd_repeat=options.mpd_repeat, init_segment_repeat=options.init_repeat, delete_after=options.delete_after)
reactor.callWhenRunning(puller.start)
reactor.callWhenRunning(pusher.start)
reactor.run()
else:
# later other protocol could be added.
logger.error("Not supported input: %s", options.source)
if __name__ == '__main__':
proxy_main()