From ee81d1a0a2af1064b153bb5f66a1f915440b0aa1 Mon Sep 17 00:00:00 2001 From: back-to Date: Fri, 21 Dec 2018 02:46:38 +0000 Subject: [PATCH] plugins.afreeca: use Referer for every connection (#2204) * plugins.afreeca: use Referer for every connection * plugins.afreeca: removed old domains that won't work with the plugin --- docs/plugin_matrix.rst | 3 +-- src/streamlink/plugins/afreeca.py | 9 +++------ tests/plugins/test_afreeca.py | 7 +++++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/plugin_matrix.rst b/docs/plugin_matrix.rst index d4f25cb9..6bd754a1 100644 --- a/docs/plugin_matrix.rst +++ b/docs/plugin_matrix.rst @@ -15,8 +15,7 @@ Name URL(s) Live VOD Notes abematv abema.tv Yes Yes Streams are geo-restricted to Japan. abweb abweb.com Yes No Requires a login and a subscription. adultswim adultswim.com Yes Yes Streams may be geo-restricted, some VOD streams are protected by DRM. -afreeca - afreecatv.com Yes No - - afreeca.tv +afreeca play.afreecatv.com Yes No aljazeeraen aljazeera.com Yes Yes English version of the site. animelab animelab.com -- Yes Requires a login. Streams may be geo-restricted to Australia and New Zealand. app17 17app.co Yes -- diff --git a/src/streamlink/plugins/afreeca.py b/src/streamlink/plugins/afreeca.py index a9fec3f6..319bc4f4 100644 --- a/src/streamlink/plugins/afreeca.py +++ b/src/streamlink/plugins/afreeca.py @@ -19,7 +19,7 @@ QUALITY_WEIGHTS = { "sd": 480 } -_url_re = re.compile(r"http(s)?://(?P\w+\.)?afreeca(tv)?\.com/(?P\w+)(/\d+)?") +_url_re = re.compile(r"https?://play\.afreecatv\.com/(?P\w+)(?:/\d+)?") _channel_schema = validate.Schema( { @@ -86,10 +86,6 @@ class AfreecaTV(Plugin): return self.session.http.json(res, schema=_channel_schema) def _get_hls_key(self, broadcast, username, quality): - headers = { - "Referer": self.url - } - data = { "bid": username, "bno": broadcast, @@ -97,7 +93,7 @@ class AfreecaTV(Plugin): "quality": quality, "type": "pwd" } - res = self.session.http.post(CHANNEL_API_URL, data=data, headers=headers) + res = self.session.http.post(CHANNEL_API_URL, data=data) return self.session.http.json(res, schema=_channel_schema) def _get_stream_info(self, broadcast, quality, cdn, rmd): @@ -139,6 +135,7 @@ class AfreecaTV(Plugin): return False def _get_streams(self): + self.session.http.headers.update({"Referer": self.url}) if not self.session.get_option("hls-segment-ignore-names"): ignore_segment = ["preloading"] self.session.set_option("hls-segment-ignore-names", ignore_segment) diff --git a/tests/plugins/test_afreeca.py b/tests/plugins/test_afreeca.py index fffc7cab..ab7b98d6 100644 --- a/tests/plugins/test_afreeca.py +++ b/tests/plugins/test_afreeca.py @@ -6,15 +6,18 @@ from streamlink.plugins.afreeca import AfreecaTV class TestPluginAfreecaTV(unittest.TestCase): def test_can_handle_url(self): should_match = [ - "http://afreecatv.com/exampleuser", - "http://afreecatv.com/exampleuser/123123123", "http://play.afreecatv.com/exampleuser", "http://play.afreecatv.com/exampleuser/123123123", + "https://play.afreecatv.com/exampleuser", ] for url in should_match: self.assertTrue(AfreecaTV.can_handle_url(url)) should_not_match = [ + "http://afreeca.com/exampleuser", + "http://afreeca.com/exampleuser/123123123", + "http://afreecatv.com/exampleuser", + "http://afreecatv.com/exampleuser/123123123", "http://www.afreecatv.com.tw", "http://www.afreecatv.jp", ]