aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_watch_formats.py
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-05-03 12:32:55 -0500
committerAstounds <kirito@disroot.org>2026-05-03 12:32:55 -0500
commit8d66143c90c4b86e8ec8dfed67753bef2abf2114 (patch)
treef7d73591c228cf52c7a4abd15c855d7d06e80ff8 /tests/test_watch_formats.py
parent50ad959a8051fec95f26b573f9fe067bdf3fdf6a (diff)
downloadyt-local-8d66143c90c4b86e8ec8dfed67753bef2abf2114.tar.lz
yt-local-8d66143c90c4b86e8ec8dfed67753bef2abf2114.tar.xz
yt-local-8d66143c90c4b86e8ec8dfed67753bef2abf2114.zip
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
Diffstat (limited to 'tests/test_watch_formats.py')
-rw-r--r--tests/test_watch_formats.py72
1 files changed, 72 insertions, 0 deletions
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