hls-player: some modernization
[hls-player:hls-player.git] / HLS / __init__.py
1 # -*- Mode: Python -*-
2 # vi:si:et:sw=4:sts=4:ts=4
3 #
4 # Copyright (C) 2009-2010 Fluendo, S.L. (www.fluendo.com).
5 # Copyright (C) 2009-2010 Marc-Andre Lureau <marcandre.lureau@gmail.com>
6
7 # This file may be distributed and/or modified under the terms of
8 # the GNU General Public License version 2 as published by
9 # the Free Software Foundation.
10 # This file is distributed without any warranty; without even the implied
11 # warranty of merchantability or fitness for a particular purpose.
12 # See "LICENSE" in the source distribution for more information.
13
14 import os
15 import urlparse
16
17
18 def make_url(base_url, url):
19     if urlparse.urlsplit(url).scheme == '':
20         url = urlparse.urljoin(base_url, url)
21     if 'HLS_PLAYER_SHIFT_PORT' in os.environ.keys():
22         shift = int(os.environ['HLS_PLAYER_SHIFT_PORT'])
23         p = urlparse.urlparse(url)
24         loc = p.netloc
25         if loc.find(":") != -1:
26             loc, port = loc.split(':')
27             port = int(port) + shift
28             loc = loc + ":" + str(port)
29         elif p.scheme == "http":
30             port = 80 + shift
31             loc = loc + ":" + str(shift)
32         p = urlparse.ParseResult(scheme=p.scheme,
33                                  netloc=loc,
34                                  path=p.path,
35                                  params=p.params,
36                                  query=p.query,
37                                  fragment=p.fragment)
38         url = urlparse.urlunparse(p)
39     return url