Enigma2 plugin to to play various online streams (mostly Latvian).

util.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. # Copyright (C) 2014 Juan Font Alonso <juanfontalonso@gmail.com>
  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. import os
  14. import urlparse
  15. def make_url(base_url, url):
  16. if urlparse.urlsplit(url).scheme == '':
  17. url = urlparse.urljoin(base_url, url)
  18. if 'HLS_PLAYER_SHIFT_PORT' in os.environ.keys():
  19. shift = int(os.environ['HLS_PLAYER_SHIFT_PORT'])
  20. p = urlparse.urlparse(url)
  21. loc = p.netloc
  22. if loc.find(":") != -1:
  23. loc, port = loc.split(':')
  24. port = int(port) + shift
  25. loc = loc + ":" + str(port)
  26. elif p.scheme == "http":
  27. port = 80 + shift
  28. loc = loc + ":" + str(shift)
  29. p = urlparse.ParseResult(scheme=p.scheme,
  30. netloc=loc,
  31. path=p.path,
  32. params=p.params,
  33. query=p.query,
  34. fragment=p.fragment)
  35. url = urlparse.urlunparse(p)
  36. return url