Skip to content

Commit

Permalink
plugins.dogus: fix for ntv streams not being found
Browse files Browse the repository at this point in the history
  • Loading branch information
beardypig committed Jan 31, 2017
1 parent 1d8ba08 commit 68b3490
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/streamlink/plugins/dogus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from streamlink.plugin.api import validate
from streamlink.stream import HDSStream
from streamlink.stream import HLSStream
from streamlink.utils import update_scheme


class Dogus(Plugin):
Expand All @@ -22,11 +23,11 @@ class Dogus(Plugin):
kralmuzik.com.tr/tv/kral-tv|
kralmuzik.com.tr/tv/kral-pop-tv
)/?""", re.VERBOSE)
mobile_url_re = re.compile(r"""(?P<q>[\"'])(?P<url>https?://[^'"]*?/live/hls/[^'"]*?\?token=)
mobile_url_re = re.compile(r"""(?P<q>["'])(?P<url>(https?:)?//[^'"]*?/live/hls/[^'"]*?\?token=)
(?P<token>[^'"]*?)(?P=q)""", re.VERBOSE)
desktop_url_re = re.compile(r"""(?P<q>[\"'])(?P<url>https?://[^'"]*?/live/hds/[^'"]*?\?token=)
desktop_url_re = re.compile(r"""(?P<q>["'])(?P<url>(https?:)?//[^'"]*?/live/hds/[^'"]*?\?token=)
(?P<token>[^'"]*?)(?P=q)""", re.VERBOSE)
token_re = re.compile(r"""token=(?P<q>[\"'])(?P<token>[^'"]*?)(?P=q)""")
token_re = re.compile(r"""token=(?P<q>["'])(?P<token>[^'"]*?)(?P=q)""")

hds_schema = validate.Schema(validate.all(
{
Expand Down Expand Up @@ -69,8 +70,8 @@ def _get_streams(self):
mobile_url_m = self.mobile_url_re.search(res.text)
desktop_url_m = self.desktop_url_re.search(res.text)

desktop_url = desktop_url_m and desktop_url_m.group("url")
mobile_url = mobile_url_m and mobile_url_m.group("url")
desktop_url = desktop_url_m and update_scheme(self.url, desktop_url_m.group("url"))
mobile_url = mobile_url_m and update_scheme(self.url, mobile_url_m.group("url"))

token = (desktop_url_m and desktop_url_m.group("token")) or (mobile_url_m and mobile_url_m.group("token"))
if not token:
Expand Down
15 changes: 15 additions & 0 deletions src/streamlink/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ def rtmpparse(url):
return (tcurl, playpath)


def update_scheme(current, target):
"""
Take the scheme from the current URL and applies it to the
target URL if the target URL startswith //
:param current: current URL
:param target: target URL
:return: target URL with the current URLs schema
"""
scheme = urlparse(current).scheme
if target.startswith("//"):
return "{0}:{1}".format(scheme, target)
else:
return target


#####################################
# Deprecated functions, do not use. #
#####################################
Expand Down
15 changes: 15 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys

from streamlink.plugin.api.validate import xml_element, text
from streamlink.utils import update_scheme

try:
import xml.etree.cElementTree as ET
Expand Down Expand Up @@ -79,3 +80,17 @@ def test_parse_qsd(self):
self.assertEqual(
{"test": "1", "foo": "bar"},
parse_qsd("test=1&foo=bar", schema=validate.Schema({"test": validate.text, "foo": "bar"})))

def test_update_scheme(self):
self.assertEqual(
"https://example.com/foo",
update_scheme("https://other.com/bar", "//example.com/foo")
)
self.assertEqual(
"http://example.com/foo",
update_scheme("http://other.com/bar", "//example.com/foo")
)
self.assertEqual(
"http://example.com/foo",
update_scheme("https://other.com/bar", "http://example.com/foo")
)

0 comments on commit 68b3490

Please sign in to comment.