Repository: streamlink/streamlink

Issue:
plugins.atresplayer: Error -3 while decompressing data: incorrect header check
### Checklist

- [X] This is a [plugin issue](https://streamlink.github.io/plugins.html) and not [a different kind of issue](https://github.com/streamlink/streamlink/issues/new/choose)
- [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

streamlink 6.4.2

### Description

Possible change in link decoding.

### Debug log

```text
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.11.6
[cli][debug] OpenSSL:    OpenSSL 3.0.11 19 Sep 2023
[cli][debug] Streamlink: 6.4.2
[cli][debug] Dependencies:
[cli][debug]  certifi: 2023.11.17
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.3
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.19.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.31.0
[cli][debug]  trio: 0.23.1
[cli][debug]  trio-websocket: 0.11.1
[cli][debug]  typing-extensions: 4.8.0
[cli][debug]  urllib3: 2.1.0
[cli][debug]  websocket-client: 1.6.4
[cli][debug] Arguments:
[cli][debug]  url=https://www.atresplayer.com/directos/antena3/
[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/antena3/
[plugins.atresplayer][debug] Player API URL: https://api.atresplayer.com/player/v1/live/5a6a165a7ed1a834493ebf6a
[plugins.atresplayer][debug] Stream source: https://directo.atresmedia.com/49aa0979c14a4113668984aa8f6f7a43dd3a624a_1701338572/antena3/master.m3u8 (application/vnd.apple.mpegurl)
[utils.l10n][debug] Language code: es_ES
error: Unable to open URL: https://directo.atresmedia.com/49aa0979c14a4113668984aa8f6f7a43dd3a624a_1701338572/antena3/master.m3u8 (('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check')))
```



Discussion:
This looks like a server issue/misconfiguration where they send garbage data to the client after it has requested the response to be compressed using `gzip, deflate`. It's possible that this is a temporary issue on their end.

Please apply the following diff and see if it works. The site is geo-blocked and they detect all VPNs I have access to, so I can't test it myself. This change disables compressed HTTP responses (`Accept-Encoding: identity`), but it's possible that their servers ignore this request header as well.

```diff
diff --git a/src/streamlink/plugins/atresplayer.py b/src/streamlink/plugins/atresplayer.py
index 375cc6eb..70b40349 100644
--- a/src/streamlink/plugins/atresplayer.py
+++ b/src/streamlink/plugins/atresplayer.py
@@ -70,17 +70,18 @@ class AtresPlayer(Plugin):
             log.error(f"Player API error: {sources['error']} - {sources['error_description']}")
             return
 
+        headers = {"Accept-Encoding": "identity"}
         for streamtype, streamsrc in sources.get("sources"):
             log.debug(f"Stream source: {streamsrc} ({streamtype or 'n/a'})")
 
             if streamtype == "application/vnd.apple.mpegurl":
-                streams = HLSStream.parse_variant_playlist(self.session, streamsrc)
+                streams = HLSStream.parse_variant_playlist(self.session, streamsrc, headers=headers)
                 if not streams:
-                    yield "live", HLSStream(self.session, streamsrc)
+                    yield "live", HLSStream(self.session, streamsrc, headers=headers)
                 else:
                     yield from streams.items()
             elif streamtype == "application/dash+xml":
-                yield from DASHStream.parse_manifest(self.session, streamsrc).items()
+                yield from DASHStream.parse_manifest(self.session, streamsrc, headers=headers).items()
 
 
 __plugin__ = AtresPlayer
```

Alternatively, if you don't know how to apply the diff, here's the full plugin file for you to [sideload](https://streamlink.github.io/cli/plugin-sideloading.html):
https://raw.githubusercontent.com/bastimeyer/streamlink/18f8b966622382504e670100a262adf55bb3da45/src/streamlink/plugins/atresplayer.py
Changed the plugin file.

I think there is something else.

```
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.11.6
[cli][debug] OpenSSL:    OpenSSL 3.0.11 19 Sep 2023
[cli][debug] Streamlink: 6.4.2
[cli][debug] Dependencies:
[cli][debug]  certifi: 2023.11.17
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.3
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.19.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.31.0
[cli][debug]  trio: 0.23.1
[cli][debug]  trio-websocket: 0.11.1
[cli][debug]  typing-extensions: 4.8.0
[cli][debug]  urllib3: 2.1.0
[cli][debug]  websocket-client: 1.6.4
[cli][debug] Arguments:
[cli][debug]  url=https://www.atresplayer.com/directos/antena3/
[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/antena3/
[plugins.atresplayer][debug] Player API URL: https://api.atresplayer.com/player/v1/live/5a6a165a7ed1a834493ebf6a
[plugins.atresplayer][debug] Stream source: https://directo.atresmedia.com/0883d6c329e97c8f19dd5a1a9580fff6885726bb_1701341548/antena3/master.m3u8 (application/vnd.apple.mpegurl)
[utils.l10n][debug] Language code: es_ES
error: Unable to open URL: https://directo.atresmedia.com/0883d6c329e97c8f19dd5a1a9580fff6885726bb_1701341548/antena3/master.m3u8 (404 Client Error: Not Found for url: https://directo.atresmedia.com/0883d6c329e97c8f19dd5a1a9580fff6885726bb_1701341548/antena3/master.m3u8)
``` 
> 404 Client Error

That doesn't seem right. Just to be sure that you didn't mess up the plugin changes via the diff, please instead sideload the plugin file I've linked. If done correctly, there should be a debug log message at the top.

However, in case they indeed return 404 with the `Accept-Encoding: identity` header being set, then my only other idea would be installing the `brotli` and/or `zstandard` packages in Streamlink's Python environment, so `urllib3` can pick these other compression algorithms up automatically. Since you appear to be using Streamlink's Windows builds though, you'll either have to install Streamlink in a local Python environment on your own, so you can use pip and install the dependencies, or you'll have to wait for me until tomorrow, so I can add them to Streamlink's Windows builds (which is a good idea anyway).
I can confirm the 404 Client Error with the plugin change and/or header.
In fact it's the exact same situation we talked one year ago there: https://github.com/streamlink/streamlink/issues/4895
https://github.com/streamlink/streamlink/issues/4895#issuecomment-1288053745

> The old m3u8 that was down these last days started to work again today. Let's be attentive and see if it's temporary or find a solution. On the website it still load the new url.

----

If you want this to get fixed, so the plugin uses the same stream URLs as their website, then please open a pull request with the necessary changes. Nobody with access to the API has shown interest to fix this yet. However, there was a recent plugin change in August via #5477.
Hi, there is an issue with this plugin. Hope you'll be able to fix it soon.
Hello,
Can you please test this? I think this modification works.
[atresplayer_dec2023.zip](https://github.com/streamlink/streamlink/files/13692572/atresplayer_dec2023.zip)
Best regards.

----

edit (added diff for transparency reasons)

```diff
diff --git a/src/streamlink/plugins/atresplayer.py b/tmp/.psub.DMeopkXmHb
index 375cc6e..a0ca632 100644
--- a/src/streamlink/plugins/atresplayer.py
+++ b/tmp/.psub.DMeopkXmHb
@@ -23,7 +23,7 @@ log = logging.getLogger(__name__)
 ))
 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}"
+    _player_api_url = "https://api.atresplayer.com/player/v1/live/{channel_id}?NODRM=true"
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -54,7 +54,7 @@ class AtresPlayer(Plugin):
                     "error_description": str,
                 },
                 {
-                    "sources": [
+                    "sourcesLive": [
                         validate.all(
                             {
                                 "src": validate.url(),
@@ -70,7 +70,7 @@ class AtresPlayer(Plugin):
             log.error(f"Player API error: {sources['error']} - {sources['error_description']}")
             return
 
-        for streamtype, streamsrc in sources.get("sources"):
+        for streamtype, streamsrc in sources.get("sourcesLive"):
             log.debug(f"Stream source: {streamsrc} ({streamtype or 'n/a'})")
 
             if streamtype == "application/vnd.apple.mpegurl":
```
After replace atresplayer.py it does not work, sorry.


This the log . (Sorry, i do not know, how to format correctly)

Dec 19 17:42:42 ubuntu tvheadend[65096]: spawn: Executing "/home/hts/.local/bin/streamlink"
Dec 19 17:42:44 ubuntu tvheadend[65096]: spawn: [cli][info] Found matching plugin atresplayer for URL https://www.atresplayer.com/directos/antena3/
Dec 19 17:42:44 ubuntu tvheadend[65096]: spawn: [cli][info] Available streams: 360p (worst), 480p, 720p, 1080p (best)
Dec 19 17:42:44 ubuntu tvheadend[65096]: spawn: [cli][info] Opening stream: 1080p (hls)
Dec 19 17:42:47 ubuntu tvheadend[65096]: spawn: [stream.hls][error] Failed to fetch segment 170121195: Unable to open URL: https://directo.atresmedia.com/147a6ebb30b6857da59de163cee5aff8cfbbc6a7_1703032964/geoantena3/2/br4/230619065411/94511/br4_170121195.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/147a6ebb30b6857da59de163cee5aff8cfbbc6a7_1703032964/geoantena3/2/br4/230619065411/94511/br4_170121195.ts)
Dec 19 17:42:49 ubuntu tvheadend[65096]: spawn: [stream.hls][error] Failed to fetch segment 170121196: Unable to open URL: https://directo.atresmedia.com/147a6ebb30b6857da59de163cee5aff8cfbbc6a7_1703032964/geoantena3/2/br4/230619065411/94511/br4_170121196.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/147a6ebb30b6857da59de163cee5aff8cfbbc6a7_1703032964/geoantena3/2/br4/230619065411/94511/br4_170121196.ts)
Dec 19 17:42:51 ubuntu tvheadend[65096]: spawn: [stream.hls][error] Failed to fetch segment 170121197: Unable to open URL: https://directo.atresmedia.com/147a6ebb30b6857da59de163cee5aff8cfbbc6a7_1703032964/geoantena3/2/br4/230619065411/94511/br4_170121197.ts (404 Client Error: Not Found for url: https://directo.atresmedia.com/147a6ebb30b6857da59de163cee5aff8cfbbc6a7_1703032964/geoantena3/2/br4/230619065411/94511/br4_170121197.ts)

Don't know if you're testing in Spain or abroad. I'm using streamlink 6.4.2-1 on Windows and the modification I proposed works like a charm!

streamlink atresplayer.com/directos/neox best
[cli][info] Found matching plugin atresplayer for URL atresplayer.com/directos/neox
[cli][info] Available streams: 360p (worst), 480p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls-multi)
[cli][info] Starting player: C:\Program Files\VideoLAN\VLC\vlc.exe
[utils.named_pipe][info] Creating pipe streamlinkpipe-17936-1-4814
[utils.named_pipe][info] Creating pipe streamlinkpipe-17936-2-6528
If you're sure that your changes do indeed fix the plugin, then please submit a pull request with a full debug log running Streamlink from your PR branch, so we can verify that it's working. Ideally with debug logs from multiple channels. Thanks.
I confirm that this changes work on 6.5.0 on Linux.
Works great, even though have delay in some channels.
Works fine for me

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
@@ -23,7 +23,7 @@
 ))
 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}"
+    _player_api_url = "https://api.atresplayer.com/player/v1/live/{channel_id}?NODRM=true"
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -54,7 +54,7 @@ def _get_streams(self):
                     "error_description": str,
                 },
                 {
-                    "sources": [
+                    "sourcesLive": [
                         validate.all(
                             {
                                 "src": validate.url(),
@@ -70,7 +70,7 @@ def _get_streams(self):
             log.error(f"Player API error: {sources['error']} - {sources['error_description']}")
             return
 
-        for streamtype, streamsrc in sources.get("sources"):
+        for streamtype, streamsrc in sources.get("sourcesLive"):
             log.debug(f"Stream source: {streamsrc} ({streamtype or 'n/a'})")
 
             if streamtype == "application/vnd.apple.mpegurl":


Test patch: