Repository: streamlink/streamlink
Pull request #861 (2017-04-28 20:04:27)

plugin.pcyourfreetv: update for new page layout
http://pc-yourfreetv.com layout has been updated. This PR will update the corresponding plugin to support such changes.


Patch:
diff --git a/appveyor.yml b/appveyor.yml
index a99e2df0..ed6353e1 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -8,12 +8,14 @@ environment:
     - PYTHON: "C:\\Python36"
     - PYTHON: "C:\\Python27-x64"
     - PYTHON: "C:\\Python33-x64"
+      DISTUTILS_USE_SDK: "1"
     - PYTHON: "C:\\Python34-x64"
+      DISTUTILS_USE_SDK: "1"
     - PYTHON: "C:\\Python35-x64"
     - PYTHON: "C:\\Python36-x64"
 
 install:
-  # If there is a newer build queued for the same PR, cancel this one.
+    # If there is a newer build queued for the same PR, cancel this one.
   # The AppVeyor 'rollout builds' option is supposed to serve the same
   # purpose but it is problematic because it tends to cancel builds pushed
   # directly to master instead of just PR builds (or the converse).
@@ -38,7 +40,7 @@ install:
 
   # Upgrade to the latest version of pip to avoid it displaying warnings
   # about it being out of date.
-  - "pip install --disable-pip-version-check --user --upgrade pip setuptools"
+  - "pip install --disable-pip-version-check --user --upgrade pip"
 
   # install dev requirements, for testing, etc.
   - "pip install -r dev-requirements.txt"
diff --git a/src/streamlink/plugins/pcyourfreetv.py b/src/streamlink/plugins/pcyourfreetv.py
index 15dde489..968ac7d3 100644
--- a/src/streamlink/plugins/pcyourfreetv.py
+++ b/src/streamlink/plugins/pcyourfreetv.py
@@ -1,16 +1,18 @@
 import re
 
+from streamlink.compat import parse_qsl, unquote
 from streamlink.plugin import Plugin, PluginOptions
 from streamlink.plugin.api import http
 from streamlink.stream import HLSStream
 
 
 class PCYourFreeTV(Plugin):
-    LIVE_TV_URL = 'http://pc-yourfreetv.com/index_livetv.php?page_id=1'
+    LIVE_TV_URL = 'http://pc-yourfreetv.com/indexlivetv.php?page_id=1'
 
     _login_url = 'http://pc-yourfreetv.com/home.php'
-    _url_re = re.compile(r'http://pc-yourfreetv\.com/index_player\.php\?channel=.+?&page_id=\d+')
-    _token_re = re.compile(r'\b(?P<token_key>auth_[0-9a-f]+)=(?P<token_value>[0-9a-f]+)\b')
+    _url_re = re.compile(r'http://pc-yourfreetv\.com/indexplayer\.php\?channel=.+?&page_id=\d+')
+    _token_re = re.compile(r'\bsrc="indexplayer\.php\?channel=.+?&(?P<tokens>.+?)"')
+    _player_re = re.compile(r"<script language=JavaScript>m='(?P<player>.+?)'", re.DOTALL)
     _video_url_re = re.compile(r"jwplayer\('.+?'\)\.setup\({.+?file: \"(?P<video_url>[^\"]+?)\".+?}\);", re.DOTALL)
 
     options = PluginOptions({
@@ -51,14 +53,21 @@ class PCYourFreeTV(Plugin):
         match = self._token_re.search(res.text)
         if match is None:
             return
-        token_key = match.group('token_key')
-        token_value = match.group('token_value')
 
         # Retrieve URL page and search for stream data
-        res = http.get(self.url, params={token_key: token_value})
-        match = self._video_url_re.search(res.text)
+        res = http.get(self.url, params=parse_qsl(match.group('tokens')))
+        match = self._player_re.search(res.text)
         if match is None:
             return
+
+        while match is not None:
+            player = unquote(match.group('player'))
+            match = self._player_re.search(player)
+
+        match = self._video_url_re.search(player)
+        if match is None:
+            return
+
         video_url = match.group('video_url')
         if '.m3u8' in video_url:
             streams = HLSStream.parse_variant_playlist(self.session, video_url)


Test patch:
diff --git a/tests/test_plugin_pcyourfreetv.py b/tests/test_plugin_pcyourfreetv.py
index d1ee96dc..f5664754 100644
--- a/tests/test_plugin_pcyourfreetv.py
+++ b/tests/test_plugin_pcyourfreetv.py
@@ -6,13 +6,13 @@ from streamlink.plugins.pcyourfreetv import PCYourFreeTV
 class TestPluginPCYourFreeTV(unittest.TestCase):
     def test_can_handle_url(self):
         # should match
-        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/index_player.php?channel=das%20erste&page_id=41"))
-        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/index_player.php?channel=srf%20eins&page_id=41"))
-        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/index_player.php?channel=bbc%20one&page_id=41"))
-        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/index_player.php?channel=tf1&page_id=41"))
+        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/indexplayer.php?channel=das%20erste&page_id=41"))
+        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/indexplayer.php?channel=srf%20eins&page_id=41"))
+        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/indexplayer.php?channel=bbc%20one&page_id=41"))
+        self.assertTrue(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/indexplayer.php?channel=tf1&page_id=41"))
 
         # shouldn't match
         self.assertFalse(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/home.php"))
-        self.assertFalse(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/index_livetv.php?page_id=1"))
+        self.assertFalse(PCYourFreeTV.can_handle_url("http://pc-yourfreetv.com/indexlivetv.php?page_id=1"))
         self.assertFalse(PCYourFreeTV.can_handle_url("http://tvcatchup.com/"))
         self.assertFalse(PCYourFreeTV.can_handle_url("http://youtube.com/"))