Repository: streamlink/streamlink

Issue:
plugins.atresplayer: no playable streams found
### Checklist

- [X] This is a plugin issue and not a different kind of issue
- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)
- [X] [I have checked the list of open and recently closed plugin issues](https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22plugin+issue%22)
- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)

### Streamlink version

Latest stable release

### Description

It only happens with this link (nova), not with others.

### Debug log

```text
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.11.1
[cli][debug] Streamlink: 5.2.1
[cli][debug] Dependencies:
[cli][debug]  certifi: 2022.12.7
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.2
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.16.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.28.2
[cli][debug]  urllib3: 1.26.14
[cli][debug]  websocket-client: 1.4.2
[cli][debug] Arguments:
[cli][debug]  url=https://www.atresplayer.com/directos/nova/
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --ffmpeg-ffmpeg=C:\Program Files\Streamlink\ffmpeg\ffmpeg.exe
[cli][info] Found matching plugin atresplayer for URL https://www.atresplayer.com/directos/nova/
[plugins.atresplayer][debug] API URL: https://api.atresplayer.com/client/v1/page/live/5a6a180b7ed1a834493ebf6e
[plugins.atresplayer][debug] Player API URL: https://api.atresplayer.com/player/v1/live/5a6a180b7ed1a834493ebf6e
[plugins.atresplayer][debug] Stream source: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/master.m3u8 (application/vnd.apple.mpegurl)
[utils.l10n][debug] Language code: es_ES
[cli][info] Available streams: 360p (worst), 480p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[cli][info] Starting player: "C:\Program Files\VideoLAN\VLC\vlc.exe"
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] First Sequence: 4166611075; Last Sequence: 4166611078
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 4166611076; End Sequence: None
[stream.hls][debug] Adding segment 4166611076 to queue
[stream.hls][debug] Adding segment 4166611077 to queue
[stream.hls][debug] Adding segment 4166611078 to queue
[stream.hls][error] Failed to fetch segment 4166611076: Unable to open URL: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/2/br4/220629065114/92561/br4_166611076.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/2/br4/220629065114/92561/br4_166611076.ts)
[stream.hls][error] Failed to fetch segment 4166611077: Unable to open URL: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/2/br4/220629065114/92561/br4_166611077.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/2/br4/220629065114/92561/br4_166611077.ts)
[stream.hls][error] Failed to fetch segment 4166611078: Unable to open URL: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/2/br4/220629065114/92561/br4_166611078.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/2/br4/220629065114/92561/br4_166611078.ts)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.segmented][debug] Closing writer thread
[cli][error] Try 1/1: Could not open stream <HLSStream ['hls', 'https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/bitrate_4.m3u8', 'https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/master.m3u8']> (Failed to read data from stream: Read timeout)
error: Could not open stream <HLSStream ['hls', 'https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/bitrate_4.m3u8', 'https://directo.atresmedia.com/d99c691686362f555c21feb4d596063ae356e2b4_1675105307/geonova/master.m3u8']>, tried 1 times, exiting
[cli][info] Closing currently open stream...
```



Discussion:
The issue now is on all atresplayer channels. You need to register for free (using a vpn it works). A plugin update entering a username and password should be working.
They have returned it. Everything continues as before ('nova' not works).
Any news for NOVA ?
Still Not Working on 5.3.1 version.
Still not working on 5.4.0

```text
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.11.3
[cli][debug] Streamlink: 5.4.0
[cli][debug] Dependencies:
[cli][debug]  certifi: 2022.12.7
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.2
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.17
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.28.2
[cli][debug]  urllib3: 1.26.15
[cli][debug]  websocket-client: 1.5.1
[cli][debug] Arguments:
[cli][debug]  url=https://www.atresplayer.com/directos/nova/
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --ffmpeg-ffmpeg=C:\Program Files\Streamlink\ffmpeg\ffmpeg.exe
[cli][info] Found matching plugin atresplayer for URL https://www.atresplayer.com/directos/nova/
[plugins.atresplayer][debug] API URL: https://api.atresplayer.com/client/v1/page/live/5a6a180b7ed1a834493ebf6e
[plugins.atresplayer][debug] Player API URL: https://api.atresplayer.com/player/v1/live/5a6a180b7ed1a834493ebf6e
[plugins.atresplayer][debug] Stream source: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/master.m3u8 (application/vnd.apple.mpegurl)
[utils.l10n][debug] Language code: es_ES
[cli][info] Available streams: 360p (worst), 480p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[cli][info] Starting player: "C:\Program Files\VideoLAN\VLC\vlc.exe"
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] First Sequence: 4166611075; Last Sequence: 4166611078
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 4166611076; End Sequence: None
[stream.hls][debug] Adding segment 4166611076 to queue
[stream.hls][debug] Adding segment 4166611077 to queue
[stream.hls][debug] Adding segment 4166611078 to queue
[stream.hls][error] Failed to fetch segment 4166611076: Unable to open URL: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/2/br4/220629065114/92561/br4_166611076.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/2/br4/220629065114/92561/br4_166611076.ts)
[stream.hls][error] Failed to fetch segment 4166611077: Unable to open URL: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/2/br4/220629065114/92561/br4_166611077.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/2/br4/220629065114/92561/br4_166611077.ts)
[stream.hls][error] Failed to fetch segment 4166611078: Unable to open URL: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/2/br4/220629065114/92561/br4_166611078.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/2/br4/220629065114/92561/br4_166611078.ts)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[stream.segmented][debug] Closing writer thread
[cli][error] Try 1/1: Could not open stream <HLSStream ['hls', 'https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/bitrate_4.m3u8', 'https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/master.m3u8']> (Failed to read data from stream: Read timeout)
error: Could not open stream <HLSStream ['hls', 'https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/bitrate_4.m3u8', 'https://directo.atresmedia.com/c5b7057f9fcd5dd72d53fd60876e42cd486b965d_1681784389/geonova/master.m3u8']>, tried 1 times, exiting
[cli][info] Closing currently open stream...
```
> Still not working on 5.4.0

Yes, because as you can clearly see in the changelog, nobody has submitted a pull request with a fix yet.

This site, as well as other Spanish TV streaming sites, is aggrssively blocking VPNs, which makes fixing this unnecessarily difficult. If you want this fixed, submit a PR yourself with the right changes. This is a free and open source software project, so you're not reliant on any maintainers fixing this for you.

Since the HLS playlist seems to get resolved correctly, but segment requests are failing, this suggests the following two things:
1. Either segment URLs require additional query string parameters or a URL translation of some kind (custom HLS logic)
2. or the HLS playlist URL requires certain query string parameters which are propagated to the segment URLs automatically

This plugin here has custom HLS logic which replaces segment URLs:
https://github.com/streamlink/streamlink/blob/5.4.0/src/streamlink/plugins/ltv_lsm_lv.py
you just need a spanish IP, no account needed for now : it's working fine once you're connected to a spain vpn server without any account to register.
they changed the links today :
https://www.atresplayer.com/directos/{channelnames with token: antena3, lasexta, neox, nova, mega, atreseries, canal-flooxer}
were pointing before to
https://directo.atresmedia.com/{token,etc.}
now they point to 
https://atres-live.atresmedia.com/{token,etc.}

They also added some FAST channels without token if you want to add them  in the atresplayer plugin :

https://www.atresplayer.com/directos/canal-kidz/
pointing to 
https://fast-channels.atresmedia.com/648c271d2bfab0e4177a0d61/648c271d2bfab0e4177a0d61.m3u8

https://www.atresplayer.com/directos/aqui-no-hay-quien-viva/
pointing to 
https://fast-channels.atresmedia.com/648ef3951756b0e425af83cc/648ef3951756b0e425af83cc.m3u8

https://www.atresplayer.com/directos/el-hormiguero/
pointing to
https://fast-channels.atresmedia.com/648ef5882bfab0e4627e0d61/648ef5882bfab0e4627e0d61.m3u8

https://www.atresplayer.com/directos/foq/
pointing to
https://fast-channels.atresmedia.com/648ef50a2bfab0e4607e0d61/648ef50a2bfab0e4607e0d61.m3u8

https://www.atresplayer.com/directos/equipo-de-investigacion/
pointing to
https://fast-channels.atresmedia.com/648ef5551756b0e429af83cc/648ef5551756b0e429af83cc.m3u8

https://www.atresplayer.com/directos/el-club-de-la-comedia/
pointing to
https://fast-channels.atresmedia.com/648f47f7a2ffb0e40aeff3ad/648f47f7a2ffb0e40aeff3ad.m3u8

https://www.atresplayer.com/directos/clasicos/
pointing to
https://fast-channels.atresmedia.com/648ef12c2bfab0e4507e0d61/648ef12c2bfab0e4507e0d61.m3u8

https://www.atresplayer.com/directos/multicine/
pointing to
https://fast-channels.atresmedia.com/648ef18c1756b0e41daf83cc/648ef18c1756b0e41daf83cc.m3u8

https://www.atresplayer.com/directos/comedia/
pointing to
https://fast-channels.atresmedia.com/648ef23d2bfab0e4557e0d61/648ef23d2bfab0e4557e0d61.m3u8

Resolving patch:
diff --git a/src/streamlink/plugins/atresplayer.py b/src/streamlink/plugins/atresplayer.py
--- a/src/streamlink/plugins/atresplayer.py
+++ b/src/streamlink/plugins/atresplayer.py
@@ -7,7 +7,6 @@
 
 import logging
 import re
-from urllib.parse import urlparse
 
 from streamlink.plugin import Plugin, pluginmatcher
 from streamlink.plugin.api import validate
@@ -20,35 +19,33 @@
 
 
 @pluginmatcher(re.compile(
-    r"https?://(?:www\.)?atresplayer\.com/",
+    r"https?://(?:www\.)?atresplayer\.com/directos/.+",
 ))
 class AtresPlayer(Plugin):
+    _channels_api_url = "https://api.atresplayer.com/client/v1/info/channels"
+    _player_api_url = "https://api.atresplayer.com/player/v1/live/{channel_id}"
+
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         self.url = update_scheme("https://", f"{self.url.rstrip('/')}/")
 
     def _get_streams(self):
-        path = urlparse(self.url).path
-        api_url = self.session.http.get(self.url, schema=validate.Schema(
-            re.compile(r"""window.__PRELOADED_STATE__\s*=\s*({.*?});""", re.DOTALL),
-            validate.none_or_all(
-                validate.get(1),
-                validate.parse_json(),
-                {"links": {path: {"href": validate.url()}}},
-                validate.get(("links", path, "href")),
-            ),
-        ))
-        if not api_url:
-            return
-        log.debug(f"API URL: {api_url}")
-
-        player_api_url = self.session.http.get(api_url, schema=validate.Schema(
+        channel_path = f"/{self.url.split('/')[-2]}/"
+        channel_data = self.session.http.get(self._channels_api_url, schema=validate.Schema(
             validate.parse_json(),
-            {"urlVideo": validate.url()},
-            validate.get("urlVideo"),
+            [{
+                "id": str,
+                "link": {"url": str},
+            }],
+            validate.filter(lambda item: item["link"]["url"] == channel_path),
         ))
+        if not channel_data:
+            return
+        channel_id = channel_data[0]["id"]
 
+        player_api_url = self._player_api_url.format(channel_id=channel_id)
         log.debug(f"Player API URL: {player_api_url}")
+
         sources = self.session.http.get(player_api_url, acceptable_status=(200, 403), schema=validate.Schema(
             validate.parse_json(),
             validate.any(


Test patch:
diff --git a/tests/plugins/test_atresplayer.py b/tests/plugins/test_atresplayer.py
--- a/tests/plugins/test_atresplayer.py
+++ b/tests/plugins/test_atresplayer.py
@@ -10,9 +10,12 @@ class TestPluginCanHandleUrlAtresPlayer(PluginCanHandleUrl):
     __plugin__ = AtresPlayer
 
     should_match = [
-        "http://www.atresplayer.com/directos/antena3/",
-        "http://www.atresplayer.com/directos/lasexta/",
         "https://www.atresplayer.com/directos/antena3/",
+        "https://www.atresplayer.com/directos/lasexta/",
+        "https://www.atresplayer.com/directos/antena3-internacional/",
+    ]
+
+    should_not_match = [
         "https://www.atresplayer.com/flooxer/programas/unas/temporada-1/dario-eme-hache-sindy-takanashi-entrevista_123/",
     ]