aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_watch_formats.py
blob: 85a103ba5709e5e4d7d6d2f21423718b7beeb9d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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'