Repository: streamlink/streamlink
Pull request #1889 (2018-06-30 22:42:17)

Add tvtoya plugin
Support for the live stream on http://tvtoya.pl/live. 

Most of the work done by @remek30.


Patch:
diff --git a/docs/plugin_matrix.rst b/docs/plugin_matrix.rst
index edf47b74..b2b81939 100644
--- a/docs/plugin_matrix.rst
+++ b/docs/plugin_matrix.rst
@@ -239,6 +239,7 @@ tvp                     tvpstream.vod.tvp.pl Yes   No    Streams may be geo-rest
 tvplayer                tvplayer.com         Yes   No    Streams may be geo-restricted to Great Britain. Premium streams are not supported.
 tvrby                   tvr.by               Yes   No    Streams may be geo-restricted to Belarus.
 tvrplus                 tvrplus.ro           Yes   No    Streams may be geo-restricted to Romania.
+tvtoya                  tvtoya.pl            Yes   --
 twitch                  twitch.tv            Yes   Yes   Possible to authenticate for access to
                                                          subscription streams.
 ustreamtv               ustream.tv           Yes   Yes
diff --git a/src/streamlink/plugins/tvtoya.py b/src/streamlink/plugins/tvtoya.py
new file mode 100644
index 00000000..a5b04583
--- /dev/null
+++ b/src/streamlink/plugins/tvtoya.py
@@ -0,0 +1,35 @@
+import logging
+import re
+
+from streamlink.plugin import Plugin
+from streamlink.plugin.api import http, useragents
+from streamlink.stream import HLSStream
+from streamlink.utils import update_scheme
+
+log = logging.getLogger(__name__)
+
+
+class TVToya(Plugin):
+    _url_re = re.compile(r"https?://tvtoya.pl/live")
+    _playlist_re = re.compile(r'data-stream="([^"]+)"')
+
+    @classmethod
+    def can_handle_url(cls, url):
+        return cls._url_re.match(url) is not None
+
+    def _get_streams(self):
+        self.session.set_option('hls-live-edge', 10)
+        res = http.get(self.url)
+        playlist_m = self._playlist_re.search(res.text)
+
+        if playlist_m:
+            return HLSStream.parse_variant_playlist(
+                self.session,
+                update_scheme(self.url, playlist_m.group(1)),
+                headers={'Referer': self.url, 'User-Agent': useragents.ANDROID}
+            )
+        else:
+            log.debug("Could not find stream data")
+
+
+__plugin__ = TVToya
\ No newline at end of file


Test patch:
diff --git a/tests/plugins/test_tvtoya.py b/tests/plugins/test_tvtoya.py
new file mode 100644
index 00000000..e55bc11c
--- /dev/null
+++ b/tests/plugins/test_tvtoya.py
@@ -0,0 +1,16 @@
+import unittest
+
+from streamlink.plugins.tvtoya import TVToya
+
+
+class TestPluginTVRPlus(unittest.TestCase):
+    def test_can_handle_url(self):
+        self.assertTrue(TVToya.can_handle_url("https://tvtoya.pl/live"))
+        self.assertTrue(TVToya.can_handle_url("http://tvtoya.pl/live"))
+
+    def test_can_handle_url_negative(self):
+        self.assertFalse(TVToya.can_handle_url("https://tvtoya.pl"))
+        self.assertFalse(TVToya.can_handle_url("http://tvtoya.pl"))
+        self.assertFalse(TVToya.can_handle_url("http://tvtoya.pl/other-page"))
+        self.assertFalse(TVToya.can_handle_url("http://tvtoya.pl/"))
+        self.assertFalse(TVToya.can_handle_url("https://tvtoya.pl/"))