Repository: streamlink/streamlink
Pull request #1373 (2017-12-12 00:45:09)

Updates and improvements to tigerdile.com plugin
I noticed that this plugin would fail if you missed the trailing slash. Since it works with or without it, I just make the final slash optional in the regex.

zootboy: Example to test:

`streamlink https://www.tigerdile.com/stream/overlordfox`
> error: No plugin can handle URL: https://www.tigerdile.com/stream/overlordfox

`streamlink https://www.tigerdile.com/stream/overlordfox/`
> [cli][info] Found matching plugin tigerdile for URL https://www.tigerdile.com/stream/overlordfox/
> Available streams: live (worst, best)
codecov[bot]: # [Codecov](https://codecov.io/gh/streamlink/streamlink/pull/1373?src=pr&el=h1) Report
> Merging [#1373](https://codecov.io/gh/streamlink/streamlink/pull/1373?src=pr&el=desc) into [master](https://codecov.io/gh/streamlink/streamlink/commit/64c6ccfc013bd54d83940806e8c0afea4c9bf5cb?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.


```diff
@@           Coverage Diff           @@
##           master    #1373   +/-   ##
=======================================
  Coverage   47.07%   47.07%           
=======================================
  Files         100      100           
  Lines        7218     7218           
=======================================
  Hits         3398     3398           
  Misses       3820     3820
```


Patch:
diff --git a/src/streamlink/plugins/tigerdile.py b/src/streamlink/plugins/tigerdile.py
index 6c3c967c..59f33fc6 100644
--- a/src/streamlink/plugins/tigerdile.py
+++ b/src/streamlink/plugins/tigerdile.py
@@ -1,16 +1,20 @@
 import re
+import json
 
 from streamlink.plugin import Plugin
 from streamlink.plugin.api import http, validate
 from streamlink.stream import RTMPStream
+from streamlink.stream import HLSStream
 
 PAGE_URL = "https://www.tigerdile.com/stream/"
 ROOT_URL = "rtmp://stream.tigerdile.com/live/{0}"
+API_URL = "https://api.tigerdile.com/video?key={channel}"
+HLS_URL = "https://outbound.tigerdile.com/{channel}/index.m3u8"
 STREAM_TYPES = ["rtmp"]
 
 _url_re = re.compile(r"""
     https?://(?:www|sfw)\.tigerdile\.com
-    \/stream\/(.*)\/""", re.VERBOSE)
+    \/stream\/(.+)\/?""", re.VERBOSE)
 
 
 class Tigerdile(Plugin):
@@ -21,6 +25,18 @@ class Tigerdile(Plugin):
     def _get_streams(self):
         res = self.url
         streamname = _url_re.search(res).group(1)
+
+        ci = http.get(API_URL.format(channel=streamname))
+        api_json = json.loads(ci.text)
+
+        if not api_json or len(api_json) == 0:
+            self.logger.error("The channel {0} does not exist or is marked private".format(streamname))
+            return
+
+        if api_json[0]["online"] == False:
+            self.logger.error("The channel {0} is not online".format(streamname))
+            return
+
         streams = {}
         stream = RTMPStream(self.session, {
             "rtmp": ROOT_URL.format(streamname),
@@ -33,6 +49,9 @@ class Tigerdile(Plugin):
         })
         streams["live"] = stream
 
+        stream_hls = HLSStream(self.session, HLS_URL.format(channel=streamname))
+        streams["live_hls"] = stream_hls
+
         return streams
 
 


Test patch:
diff --git a/tests/test_plugin_tigerdile.py b/tests/test_plugin_tigerdile.py
new file mode 100644
index 00000000..5d95d5db
--- /dev/null
+++ b/tests/test_plugin_tigerdile.py
@@ -0,0 +1,22 @@
+import unittest
+
+from streamlink.plugins.tigerdile import Tigerdile
+
+
+class TestPluginTigerdile(unittest.TestCase):
+    def test_can_handle_url(self):
+        # should match
+        self.assertTrue(Tigerdile.can_handle_url("https://www.tigerdile.com/stream/example_streamer"))
+        self.assertTrue(Tigerdile.can_handle_url("http://www.tigerdile.com/stream/example_streamer"))
+        self.assertTrue(Tigerdile.can_handle_url("https://www.tigerdile.com/stream/example_streamer/"))
+        self.assertTrue(Tigerdile.can_handle_url("http://www.tigerdile.com/stream/example_streamer/"))
+        self.assertTrue(Tigerdile.can_handle_url("https://sfw.tigerdile.com/stream/example_streamer"))
+        self.assertTrue(Tigerdile.can_handle_url("http://sfw.tigerdile.com/stream/example_streamer"))
+        self.assertTrue(Tigerdile.can_handle_url("https://sfw.tigerdile.com/stream/example_streamer/"))
+        self.assertTrue(Tigerdile.can_handle_url("http://sfw.tigerdile.com/stream/example_streamer/"))
+
+        # shouldn't match
+        self.assertFalse(Tigerdile.can_handle_url("http://www.tigerdile.com/"))
+        self.assertFalse(Tigerdile.can_handle_url("http://www.tigerdile.com/stream"))
+        self.assertFalse(Tigerdile.can_handle_url("http://www.tigerdile.com/stream/"))
+        self.assertFalse(Tigerdile.can_handle_url("http://www.youtube.com/"))