Repository: streamlink/streamlink
Pull request #2811 (2020-03-01 01:23:22)

plugins.reuters fix
Update to fix: https://github.com/streamlink/streamlink/issues/2803

- Add support for .com TLD and country specific sub-domains 
- Find IFRAME and then GET its source HTML as necessary
- Update tests to include reuters.com and uk.reuters.com URLs

I've tested this pretty thoroughly, as per: https://github.com/streamlink/streamlink/issues/2803#issuecomment-593011020

closes https://github.com/streamlink/streamlink/issues/2803

codecov[bot]: # [Codecov](https://codecov.io/gh/streamlink/streamlink/pull/2811?src=pr&el=h1) Report
> Merging [#2811](https://codecov.io/gh/streamlink/streamlink/pull/2811?src=pr&el=desc) into [master](https://codecov.io/gh/streamlink/streamlink/commit/7d8106ba7a1a775015567c47f3f8bee2ea21075c&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.


```diff
@@            Coverage Diff             @@
##           master    #2811      +/-   ##
==========================================
- Coverage   52.79%   52.78%   -0.02%     
==========================================
  Files         248      248              
  Lines       15458    15466       +8     
==========================================
+ Hits         8161     8163       +2     
- Misses       7297     7303       +6     
```


Patch:
diff --git a/src/streamlink/plugins/piczel.py b/src/streamlink/plugins/piczel.py
index 1fdaa5b9..7fdec050 100644
--- a/src/streamlink/plugins/piczel.py
+++ b/src/streamlink/plugins/piczel.py
@@ -1,27 +1,25 @@
+import logging
 import re
 
 from streamlink.plugin import Plugin
 from streamlink.plugin.api import validate
-from streamlink.stream import RTMPStream, HLSStream
+from streamlink.stream import HLSStream
 
-STREAMS_URL = "https://piczel.tv:3000/streams/{0}?&page=1&sfw=false&live_only=true"
-HLS_URL = "https://5810b93fdf674.streamlock.net:1936/live/{0}/playlist.m3u8"
-RTMP_URL = "rtmp://piczel.tv:1935/live/{0}"
+log = logging.getLogger(__name__)
+
+
+STREAMS_URL = "https://piczel.tv/api/streams?followedStreams=false&live_only=false&sfw=false"
+HLS_URL = "https://piczel.tv/hls/{0}/index.m3u8"
 
 _url_re = re.compile(r"https://piczel.tv/watch/(\w+)")
 
-_streams_schema = validate.Schema(
+_streams_schema = validate.Schema([
     {
-        "type": validate.text,
-        "data": [
-            {
-                "id": int,
-                "live": bool,
-                "slug": validate.text
-            }
-        ]
+        "id": int,
+        "live": bool,
+        "slug": validate.text
     }
-)
+])
 
 
 class Piczel(Plugin):
@@ -36,37 +34,19 @@ class Piczel(Plugin):
 
         channel_name = match.group(1)
 
-        res = self.session.http.get(STREAMS_URL.format(channel_name))
+        res = self.session.http.get(STREAMS_URL)
         streams = self.session.http.json(res, schema=_streams_schema)
-        if streams["type"] not in ("multi", "stream"):
-            return
 
-        for stream in streams["data"]:
+        for stream in streams:
             if stream["slug"] != channel_name:
                 continue
 
             if not stream["live"]:
                 return
 
-            streams = {}
-
-            try:
-                streams.update(HLSStream.parse_variant_playlist(self.session, HLS_URL.format(stream["id"])))
-            except IOError as e:
-                # fix for hosted offline streams
-                if "404 Client Error" in str(e):
-                    return
-                raise
-
-            streams["rtmp"] = RTMPStream(self.session, {
-                "rtmp": RTMP_URL.format(stream["id"]),
-                "pageUrl": self.url,
-                "live": True
-            })
-
-            return streams
+            log.debug("HLS stream URL: {}", HLS_URL.format(stream["id"]))
 
-        return
+            return {"live": HLSStream(self.session, HLS_URL.format(stream["id"]))}
 
 
 __plugin__ = Piczel
diff --git a/src/streamlink/plugins/reuters.py b/src/streamlink/plugins/reuters.py
index 75aaa306..39dc3f97 100644
--- a/src/streamlink/plugins/reuters.py
+++ b/src/streamlink/plugins/reuters.py
@@ -11,7 +11,9 @@ log = logging.getLogger(__name__)
 
 
 class Reuters(Plugin):
-    _url_re = re.compile(r'https?://(?:www\.)?reuters\.tv')
+    _url_re = re.compile(r'https?://(.*?\.)?reuters\.(com|tv)')
+    _id_re = re.compile(r'(/l/|id=)(?P<id>.*?)(/|\?|$)')
+    _iframe_url = 'https://www.reuters.tv/l/{0}/?nonav=true'
     _hls_re = re.compile(r'''(?<!')https://[^"';!<>]+\.m3u8''')
     _json_re = re.compile(r'''(?P<data>{.*});''')
     _data_schema = validate.Schema(
@@ -58,6 +60,13 @@ class Reuters(Plugin):
 
     def _get_data(self):
         res = self.session.http.get(self.url)
+        for script in itertags(res.text, 'script'):
+            if script.attributes.get('type') == 'text/javascript' and '#rtvIframe' in script.text:
+                m = self._id_re.search(self.url)
+                if m and m.group('id'):
+                    log.debug('ID: {0}'.format(m.group('id')))
+                    res = self.session.http.get(self._iframe_url.format(m.group('id')))
+
         for script in itertags(res.text, 'script'):
             if script.attributes.get('type') == 'text/javascript' and 'RTVJson' in script.text:
                 data = self._data_schema.validate(script.text)


Test patch:
diff --git a/tests/plugins/test_reuters.py b/tests/plugins/test_reuters.py
index bdde76a6..b9608c88 100644
--- a/tests/plugins/test_reuters.py
+++ b/tests/plugins/test_reuters.py
@@ -6,6 +6,9 @@ from streamlink.plugins.reuters import Reuters
 class TestPluginReuters(unittest.TestCase):
     def test_can_handle_url(self):
         should_match = [
+            'https://uk.reuters.com/video/watch/east-africa-battles-locust-invasion-idOVC2J9BHJ?chan=92jv7sln',
+            'https://www.reuters.com/livevideo?id=Pdeb',
+            'https://www.reuters.com/video/watch/baby-yoda-toy-makes-its-big-debut-idOVC1KAO9Z?chan=8adtq7aq',
             'https://www.reuters.tv/l/PFJx/2019/04/19/way-of-the-cross-ritual-around-notre-dame-cathedral',
             'https://www.reuters.tv/l/PFcO/2019/04/10/first-ever-black-hole-image-released-astrophysics-milestone',
             'https://www.reuters.tv/p/WoRwM1a00y8',