From 8d66143c90c4b86e8ec8dfed67753bef2abf2114 Mon Sep 17 00:00:00 2001 From: Astounds Date: Sun, 3 May 2026 12:32:55 -0500 Subject: fix: update innertube clients and fix HLS/DASH quality switching - Update innertube client versions to match yt-dlp (android 21.02.35, ios 21.02.3, web 2.20260114.08.00, android_vr 1.65.10) - Remove obsolete clients (android-test-suite, ios_vr) - Replace tv_embedded with TVHTML5_SIMPLY (cn 75) - Add new clients: web_embedded, mweb, tv - Fix HLS freeze on quality switch: use nextLevel instead of currentLevel, handle bufferStalledError, stream proxy segments instead of buffering in memory - Populate DASH quality selector with actual sources (no Auto) - Render quality-select empty in template, let JS populate per mode --- tests/test_watch_formats.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/test_watch_formats.py (limited to 'tests') diff --git a/tests/test_watch_formats.py b/tests/test_watch_formats.py new file mode 100644 index 0000000..85a103b --- /dev/null +++ b/tests/test_watch_formats.py @@ -0,0 +1,72 @@ +import pytest +from youtube import watch_formats + + +class TestCodecName: + def test_avc_returns_h264(self): + assert watch_formats.codec_name('avc1.64001F') == 'h264' + + def test_av01_returns_av1(self): + assert watch_formats.codec_name('av01.0.05M.08') == 'av1' + + def test_vp9_returns_vp(self): + assert watch_formats.codec_name('vp9') == 'vp' + + def test_unknown_returns_unknown(self): + assert watch_formats.codec_name('unknown_codec') == 'unknown' + + +class TestVideoQualityString: + def test_with_vcodec(self): + fmt = {'vcodec': 'avc1', 'width': 1920, 'height': 1080, 'fps': 30} + assert watch_formats.video_quality_string(fmt) == '1920x1080 30fps' + + def test_with_vcodec_no_fps(self): + fmt = {'vcodec': 'avc1', 'width': 1280, 'height': 720} + assert watch_formats.video_quality_string(fmt) == '1280x720' + + def test_with_acodec_only(self): + fmt = {'acodec': 'mp4a.40.2'} + assert watch_formats.video_quality_string(fmt) == 'audio only' + + def test_empty(self): + fmt = {} + assert watch_formats.video_quality_string(fmt) == '?' + + +class TestShortVideoQualityString: + def test_with_fps(self): + fmt = {'quality': 1080, 'fps': 60, 'vcodec': 'av01.0.05M.08'} + assert watch_formats.short_video_quality_string(fmt) == '1080p60 AV1' + + def test_h264(self): + fmt = {'quality': 720, 'fps': 30, 'vcodec': 'avc1.64001E'} + assert watch_formats.short_video_quality_string(fmt) == '720p30 h264' + + +class TestAudioQualityString: + def test_with_bitrate(self): + fmt = {'acodec': 'mp4a.40.2', 'audio_bitrate': 128} + assert watch_formats.audio_quality_string(fmt) == '128k' + + def test_with_sample_rate(self): + fmt = {'acodec': 'mp4a.40.2', 'audio_bitrate': 128, 'audio_sample_rate': 44100} + assert watch_formats.audio_quality_string(fmt) == '128k 44.1kHz' + + def test_video_only(self): + fmt = {'vcodec': 'avc1'} + assert watch_formats.audio_quality_string(fmt) == 'video only' + + +class TestFormatBytes: + def test_none(self): + assert watch_formats.format_bytes(None) == 'N/A' + + def test_bytes(self): + assert watch_formats.format_bytes(512) == '512.00B' + + def test_kibibytes(self): + assert watch_formats.format_bytes(1024) == '1.00KiB' + + def test_mebibytes(self): + assert watch_formats.format_bytes(1048576) == '1.00MiB' \ No newline at end of file -- cgit v1.2.3