From ca5cce5b07d51efe7310b449cdefeca8d873e9df Mon Sep 17 00:00:00 2001 From: sepro Date: Tue, 1 Jul 2025 21:17:11 +0200 Subject: [PATCH 01/21] [cleanup] Bump ruff to 0.12.x (#13596) Authored by: seproDev --- pyproject.toml | 4 +++- yt_dlp/aes.py | 2 +- yt_dlp/extractor/nhk.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3775251e10..41d5ec3b0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,7 @@ dev = [ ] static-analysis = [ "autopep8~=2.0", - "ruff~=0.11.0", + "ruff~=0.12.0", ] test = [ "pytest~=8.1", @@ -210,10 +210,12 @@ ignore = [ "TD001", # invalid-todo-tag "TD002", # missing-todo-author "TD003", # missing-todo-link + "PLC0415", # import-outside-top-level "PLE0604", # invalid-all-object (false positives) "PLE0643", # potential-index-error (false positives) "PLW0603", # global-statement "PLW1510", # subprocess-run-without-check + "PLW1641", # eq-without-hash "PLW2901", # redefined-loop-name "RUF001", # ambiguous-unicode-character-string "RUF012", # mutable-class-default diff --git a/yt_dlp/aes.py b/yt_dlp/aes.py index 065901d68d..600cb12a89 100644 --- a/yt_dlp/aes.py +++ b/yt_dlp/aes.py @@ -435,7 +435,7 @@ def sub_bytes_inv(data): def rotate(data): - return data[1:] + [data[0]] + return [*data[1:], data[0]] def key_schedule_core(data, rcon_iteration): diff --git a/yt_dlp/extractor/nhk.py b/yt_dlp/extractor/nhk.py index 0bd6edfcba..0d5e5b0e7e 100644 --- a/yt_dlp/extractor/nhk.py +++ b/yt_dlp/extractor/nhk.py @@ -495,7 +495,7 @@ def _real_extract(self, url): chapters = None if chapter_durations and chapter_titles and len(chapter_durations) == len(chapter_titles): start_time = chapter_durations - end_time = chapter_durations[1:] + [duration] + end_time = [*chapter_durations[1:], duration] chapters = [{ 'start_time': s, 'end_time': e, From c2ff2dbaec7929015373fe002e9bd4849931a4ce Mon Sep 17 00:00:00 2001 From: Simon Sawicki Date: Wed, 2 Jul 2025 00:12:43 +0200 Subject: [PATCH 02/21] [rh:requests] Work around partial read dropping data (#13599) Authored by: Grub4K --- test/test_networking.py | 17 ++++++++++++----- yt_dlp/networking/_requests.py | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/test/test_networking.py b/test/test_networking.py index 2f441fced2..afdd0c7aa7 100644 --- a/test/test_networking.py +++ b/test/test_networking.py @@ -22,7 +22,6 @@ import tempfile import threading import time -import urllib.error import urllib.request import warnings import zlib @@ -223,10 +222,7 @@ def do_GET(self): if encoding == 'br' and brotli: payload = brotli.compress(payload) elif encoding == 'gzip': - buf = io.BytesIO() - with gzip.GzipFile(fileobj=buf, mode='wb') as f: - f.write(payload) - payload = buf.getvalue() + payload = gzip.compress(payload, mtime=0) elif encoding == 'deflate': payload = zlib.compress(payload) elif encoding == 'unsupported': @@ -729,6 +725,17 @@ def test_keep_header_casing(self, handler): assert 'X-test-heaDer: test' in res + def test_partial_read_then_full_read(self, handler): + with handler() as rh: + for encoding in ('', 'gzip', 'deflate'): + res = validate_and_send(rh, Request( + f'http://127.0.0.1:{self.http_port}/content-encoding', + headers={'ytdl-encoding': encoding})) + assert res.headers.get('Content-Encoding') == encoding + assert res.read(6) == b'' + assert res.read(0) == b'' + assert res.read() == b'