Skip to content

plugins.atpchallenger: new plugin #4700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 3, 2022

Conversation

yxiao1996
Copy link
Contributor

@yxiao1996 yxiao1996 commented Aug 2, 2022

Hi team,

This change implements one of the plugin I proposed in this issue: #4693. This plugin enables streamlink to scrap livestream from https://www.atptour.com/en/atp-challenger-tour/challenger-tv.

For testing, I locally run the tests described here: https://streamlink.github.io/latest/developing.html#validating-changes
Thanks,
Yu

@mkbloke mkbloke changed the title Plugin atp challenger plugins.atpchallenger: new plugin Aug 2, 2022
Copy link
Member

@bastimeyer bastimeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Streamlink already implements the livestream.com plugin (which even got rewritten recently), so the current plugin implementation is pretty much unnecessary and also wrong/incomplete, so I'm not going to comment on the code after the first HTTP request.

Due to the embedding of 3rd party streaming sites on atptour.com, the plugin needs to be turned into a wrapper plugin which just calls return self.session.streams(url).

Adding new plugins which are only wrappers however is always questionable, and it depends on whether the user can get the actual streaming URL from their web browser which could then alternatively be used as Streamlink's input URL. Adding wrapper plugins for external sites overloads Streamlink with useless plugins that (currently) slow down the session initialization, so we want to avoid this. It's also problematic from the perspective of plugin maintenance.

Since there doesn't seem to be a way though to get the actual stream URL from livestream.com via the ATPtour website, I guess adding a wrapper plugin in this case is okay.


The following diff should be enough for a wrapper plugin and it also fixes some other issues:

diff --git a/src/streamlink/plugins/atpchallenger.py b/src/streamlink/plugins/atpchallenger.py
index 39312a9f..b0dccde8 100644
--- a/src/streamlink/plugins/atpchallenger.py
+++ b/src/streamlink/plugins/atpchallenger.py
@@ -1,6 +1,6 @@
 """
-$description Professional tennis tournaments.
-$url www.atptour.com/en/atp-challenger-tour/challenger-tv
+$description Tennis tournaments organized by the Association of Tennis Professionals.
+$url atptour.com/en/atp-challenger-tour/challenger-tv
 $type live, vod
 """
 
@@ -9,55 +9,22 @@ import re
 
 from streamlink.plugin import Plugin, pluginmatcher
 from streamlink.plugin.api import validate
-from streamlink.stream.hls import HLSStream
 
 log = logging.getLogger(__name__)
 
 
 @pluginmatcher(re.compile(
-    r"https?://(?:www\.)?atptour.com/en/atp-challenger-tour/challenger-tv"
+    r"https?://(?:www\.)?atptour\.com/(?:en|es)/atp-challenger-tour/challenger-tv"
 ))
 class AtpChallengerTour(Plugin):
-    _re_window_config = re.compile(r""".*window.config\s*=\s*(?P<json>{.*?});""", re.DOTALL)
-
     def _get_streams(self):
         iframe_url = self.session.http.get(self.url, schema=validate.Schema(
             validate.parse_html(),
-            validate.xml_xpath_string("normalize-space(.//iframe[contains(@src,'livestream.com')]/@src)")
-        ))
-        if not iframe_url:
-            return None
-
-        stream_data = self.session.http.get(iframe_url, schema=validate.Schema(
-            validate.transform(self._re_window_config.search),
-            validate.any(None, validate.all(
-                validate.get("json"),
-                validate.parse_json(),
-                {
-                    "event": {
-                        "full_name": str,
-                        "feed": {
-                            "data": list
-                        }
-                    }
-                },
-                validate.get("event")
-            ))
+            validate.xml_xpath_string(".//iframe[starts-with(@id,'vimeoPlayer_')][@src][1]/@src"),
+            validate.any(None, validate.url()),
         ))
-        if not stream_data:
-            return None
-        if len(stream_data['feed']['data']) < 1:
-            return None
-        if 'data' not in stream_data['feed']['data'][0]:
-            return None
-        if 'secure_m3u8_url' not in stream_data['feed']['data'][0]['data']:
-            return None
-        self.title = stream_data['full_name'].replace(" ", "")
-        self.category = "atp-challenger"
-        self.author = "ATP"
-        stream_url = stream_data['feed']['data'][0]['data']['secure_m3u8_url']
-
-        yield from HLSStream.parse_variant_playlist(self.session, stream_url).items()
+        if iframe_url:
+            return self.session.streams(iframe_url)
 
 
 __plugin__ = AtpChallengerTour
diff --git a/tests/plugins/test_atpchallenger.py b/tests/plugins/test_atpchallenger.py
index 2748b5de..fc35816c 100644
--- a/tests/plugins/test_atpchallenger.py
+++ b/tests/plugins/test_atpchallenger.py
@@ -6,7 +6,8 @@ class TestPluginCanHandleUrlAtpChallenger(PluginCanHandleUrl):
     __plugin__ = AtpChallengerTour
 
     should_match = [
-        'https://www.atptour.com/en/atp-challenger-tour/challenger-tv/challenger-tv-search-results/'
-        + '2022-2785-ms005-zug-alexander-ritschard-vs-dominic-stricker/2022/2785/all',
-        'https://www.atptour.com/en/atp-challenger-tour/challenger-tv'
+        "https://www.atptour.com/en/atp-challenger-tour/challenger-tv",
+        "https://www.atptour.com/es/atp-challenger-tour/challenger-tv",
+        "https://www.atptour.com/en/atp-challenger-tour/challenger-tv/challenger-tv-search-results/"
+        + "2022-2785-ms005-zug-alexander-ritschard-vs-dominic-stricker/2022/2785/all",
     ]

Featured stream

$ streamlink 'https://www.atptour.com/en/atp-challenger-tour/challenger-tv'
[cli][info] Found matching plugin atpchallenger for URL https://www.atptour.com/en/atp-challenger-tour/challenger-tv
Available streams: 288p (worst), 360p (best)

Specific stream

$ streamlink 'https://www.atptour.com/en/atp-challenger-tour/challenger-tv/challenger-tv-search-results/2022-586-ms016-lexington-roman-safiullin-vs-alafia-ayeni/2022/586/all'
[cli][info] Found matching plugin atpchallenger for URL https://www.atptour.com/en/atp-challenger-tour/challenger-tv/challenger-tv-search-results/2022-586-ms016-lexington-roman-safiullin-vs-alafia-ayeni/2022/586/all
Available streams: 288p_alt2 (worst), 288p, 360p_alt2, 360p (best)

Unavailable stream

$ streamlink 'https://www.atptour.com/en/atp-challenger-tour/challenger-tv/challenger-tv-search-results/2022-586-qs018-lexington-gage-brymer-vs-divij-sharan/2022/586/all'
[cli][info] Found matching plugin atpchallenger for URL https://www.atptour.com/en/atp-challenger-tour/challenger-tv/challenger-tv-search-results/2022-586-qs018-lexington-gage-brymer-vs-divij-sharan/2022/586/all
error: Unable to open URL: https://api.new.livestream.com/accounts/5057055/events/10567785 (404 Client Error: Not Found for url: https://api.new.livestream.com/accounts/5057055/events/10567785)

Co-authored-by: Sebastian Meyer <mail@bastimeyer.de>
@yxiao1996 yxiao1996 marked this pull request as draft August 2, 2022 23:19
@yxiao1996 yxiao1996 marked this pull request as ready for review August 2, 2022 23:47
@yxiao1996 yxiao1996 marked this pull request as draft August 2, 2022 23:48
@yxiao1996 yxiao1996 marked this pull request as ready for review August 2, 2022 23:51
@yxiao1996 yxiao1996 requested a review from bastimeyer August 2, 2022 23:51
@yxiao1996 yxiao1996 marked this pull request as draft August 3, 2022 00:42
@yxiao1996 yxiao1996 marked this pull request as ready for review August 3, 2022 00:45
@yxiao1996 yxiao1996 requested a review from bastimeyer August 3, 2022 00:45
@bastimeyer bastimeyer merged commit 377c356 into streamlink:master Aug 3, 2022
Billy2011 pushed a commit to Billy2011/streamlink-27 that referenced this pull request Aug 3, 2022
Co-authored-by: bastimeyer <mail@bastimeyer.de>
light4 pushed a commit to light4/streamlink that referenced this pull request Dec 9, 2022
Co-authored-by: bastimeyer <mail@bastimeyer.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants