Repository: streamlink/streamlink
Pull request #815 (2017-04-19 21:58:06)

Add support for Telefe (VOD)
As issued in https://github.com/streamlink/streamlink/issues/805


Patch:
diff --git a/docs/plugin_matrix.rst b/docs/plugin_matrix.rst
index 2e7fc52b..229f5aa6 100644
--- a/docs/plugin_matrix.rst
+++ b/docs/plugin_matrix.rst
@@ -176,6 +176,7 @@ svtplay             - svtplay.se         Yes   Yes   Streams may be geo-restrict
                     - oppetarkiv.se
 swisstxt            - srf.ch             Yes   No    Streams are geo-restricted to Switzerland.
                     - rsi.ch
+telefe              telefe.com           No    Yes   Streams are geo-restricted to Argentina.
 tf1                 - tf1.fr             Yes   No    Streams may be geo-restricted to France.
                     - lci.fr
 tga                 - star.plu.cn        Yes   No
diff --git a/src/streamlink/plugins/telefe.py b/src/streamlink/plugins/telefe.py
new file mode 100644
index 00000000..fd19b63a
--- /dev/null
+++ b/src/streamlink/plugins/telefe.py
@@ -0,0 +1,48 @@
+import re
+
+from streamlink.plugin import Plugin
+from streamlink.plugin.api import http, useragents, validate
+from streamlink.stream import HLSStream, HTTPStream
+from streamlink.utils import parse_json
+
+
+class Telefe(Plugin):
+    _url_re = re.compile(r'https?://telefe.com/.+')
+
+    @classmethod
+    def can_handle_url(cls, url):
+        return cls._url_re.match(url)
+
+    def _get_streams(self):
+        res = http.get(self.url, headers={'User-Agent': useragents.CHROME})
+        video_search = res.text
+        video_search = video_search[video_search.index('{"top":{"view":"PlayerContainer","model":{'):]
+        video_search = video_search[: video_search.index('}]}}') +4] + "}"
+
+        video_url_found_hls  = ""
+        video_url_found_http = ""
+
+        json_video_search = parse_json(video_search)
+        json_video_search_sources = json_video_search["top"]["model"]["videos"][0]["sources"]
+        self.logger.debug('Video ID found: {0}', json_video_search["top"]["model"]["id"])
+        for current_video_source in json_video_search_sources:
+            if "HLS" in current_video_source["type"]:
+                video_url_found_hls = "http://telefe.com" + current_video_source["url"]
+                self.logger.debug("HLS content available")
+            if "HTTP" in current_video_source["type"]:
+                video_url_found_http = "http://telefe.com" + current_video_source["url"]
+                self.logger.debug("HTTP content available")
+
+        http.headers = {'Referer': self.url,
+            'User-Agent': useragents.CHROME,
+            'X-Requested-With': 'ShockwaveFlash/25.0.0.148'}
+
+        if video_url_found_hls:
+            hls_streams = HLSStream.parse_variant_playlist(self.session, video_url_found_hls)
+            for s in hls_streams.items():
+                yield s
+
+        if video_url_found_http:
+            yield "http", HTTPStream(self.session, video_url_found_http)
+
+__plugin__ = Telefe
\ No newline at end of file


Test patch:
diff --git a/tests/test_plugin_telefe.py b/tests/test_plugin_telefe.py
new file mode 100644
index 00000000..d8ae58dc
--- /dev/null
+++ b/tests/test_plugin_telefe.py
@@ -0,0 +1,16 @@
+import unittest
+
+from streamlink.plugins.telefe import Telefe
+
+
+class TestPluginTelefe(unittest.TestCase):
+    def test_can_handle_url(self):
+        # should match
+        self.assertTrue(Telefe.can_handle_url("http://telefe.com/pone-a-francella/temporada-1/programa-01/"))
+        self.assertTrue(Telefe.can_handle_url("http://telefe.com/los-simuladores/temporada-1/capitulo-01/"))
+        self.assertTrue(Telefe.can_handle_url("http://telefe.com/dulce-amor/capitulos/capitulo-01/"))
+
+        # shouldn't match
+        self.assertFalse(Telefe.can_handle_url("http://telefe.com/"))
+        self.assertFalse(Telefe.can_handle_url("http://www.telefeinternacional.com.ar/"))
+        self.assertFalse(Telefe.can_handle_url("http://marketing.telefe.com/"))
\ No newline at end of file