File size: 2,957 Bytes
49627f0 1776b2f efe24a6 79befd6 efe24a6 a0ca1c2 ee0deb6 a0ca1c2 d68bda8 a0ca1c2 d68bda8 a0ca1c2 06ecde8 4f06190 8f9dd79 06ecde8 9c92997 06ecde8 49627f0 ee0deb6 49627f0 9c92997 24c3a19 328e22b ee0deb6 79befd6 ee0deb6 328e22b 79befd6 328e22b 82321d6 328e22b 7f9dcc9 67e6144 1776b2f 67e6144 efe24a6 ee0deb6 efe24a6 e707f93 57b3c57 e0b8c49 d68bda8 e0d67e2 8ff1168 e0d67e2 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
"""Unit tests for the :module:`extract <extract>` module."""
from datetime import datetime
import pytest
import re
from pytube import extract
from pytube.exceptions import RegexMatchError
def test_extract_video_id():
url = "https://www.youtube.com/watch?v=2lAe1cqCOXo"
video_id = extract.video_id(url)
assert video_id == "2lAe1cqCOXo"
def test_info_url(age_restricted):
video_info_url = extract.video_info_url_age_restricted(
video_id="QRS8MkLhQmM", embed_html=age_restricted["embed_html"],
)
assert video_info_url.startswith('https://www.youtube.com/get_video_info')
assert 'video_id=QRS8MkLhQmM' in video_info_url
def test_info_url_age_restricted(cipher_signature):
video_info_url = extract.video_info_url(
video_id=cipher_signature.video_id,
watch_url=cipher_signature.watch_url,
)
assert video_info_url.startswith('https://www.youtube.com/get_video_info')
assert 'video_id=2lAe1cqCOXo' in video_info_url
def test_js_url(cipher_signature):
expected = (
r"https://youtube.com/s/player/([\w\d]+)/player_ias.vflset/en_US/base.js"
)
result = extract.js_url(cipher_signature.watch_html)
match = re.search(expected, result)
assert match is not None
def test_age_restricted(age_restricted):
assert extract.is_age_restricted(age_restricted["watch_html"])
def test_non_age_restricted(cipher_signature):
assert not extract.is_age_restricted(cipher_signature.watch_html)
def test_is_private(private):
assert extract.is_private(private['watch_html'])
def test_not_is_private(cipher_signature):
assert not extract.is_private(cipher_signature.watch_html)
def test_recording_available(cipher_signature):
assert extract.recording_available(cipher_signature.watch_html)
def test_publish_date(cipher_signature):
expected = datetime(2019, 12, 5)
assert cipher_signature.publish_date == expected
assert extract.publish_date('') is None
def test_not_recording_available(missing_recording):
assert not extract.recording_available(missing_recording['watch_html'])
def test_mime_type_codec():
mime_type, mime_subtype = extract.mime_type_codec(
'audio/webm; codecs="opus"'
)
assert mime_type == "audio/webm"
assert mime_subtype == ["opus"]
def test_mime_type_codec_with_no_match_should_error():
with pytest.raises(RegexMatchError):
extract.mime_type_codec("audio/webm")
def test_get_ytplayer_config_with_no_match_should_error():
with pytest.raises(RegexMatchError):
extract.get_ytplayer_config("")
def test_get_ytplayer_js_with_no_match_should_error():
with pytest.raises(RegexMatchError):
extract.get_ytplayer_js("")
def test_initial_data_missing():
with pytest.raises(RegexMatchError):
extract.initial_data('')
def test_initial_data(stream_dict):
initial_data = extract.initial_data(stream_dict)
assert 'contents' in initial_data
|