File size: 2,863 Bytes
a0ca1c2 49627f0 efe24a6 a0ca1c2 82321d6 a0ca1c2 82321d6 a0ca1c2 06ecde8 4f06190 8f9dd79 06ecde8 49627f0 8f9dd79 49627f0 82321d6 49627f0 24c3a19 328e22b 17564d0 328e22b 24c3a19 328e22b 82321d6 328e22b 7f9dcc9 17564d0 45402b8 efe24a6 e707f93 57b3c57 |
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 |
# -*- coding: utf-8 -*-
"""Unit tests for the :module:`extract <extract>` module."""
import pytest
from pytube.exceptions import RegexMatchError
from pytube import extract
def test_extract_video_id():
url = "https://www.youtube.com/watch?v=9bZkp7q19f0"
video_id = extract.video_id(url)
assert video_id == "9bZkp7q19f0"
def test_info_url(age_restricted):
video_info_url = extract.video_info_url_age_restricted(
video_id="QRS8MkLhQmM", embed_html=age_restricted["embed_html"],
)
expected = (
"https://youtube.com/get_video_info?video_id=QRS8MkLhQmM&eurl"
"=https%3A%2F%2Fyoutube.googleapis.com%2Fv%2FQRS8MkLhQmM&sts="
)
assert video_info_url == expected
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
)
expected = (
"https://youtube.com/get_video_info?video_id=9bZkp7q19f0&el=%24el"
"&ps=default&eurl=https%253A%2F%2Fyoutube.com%2Fwatch%253Fv%"
"253D9bZkp7q19f0&hl=en_US"
)
assert video_info_url == expected
def test_js_url(cipher_signature):
expected = "https://youtube.com/yts/jsbin/player_ias-vflWQEEag/en_US/base.js"
result = extract.js_url(cipher_signature.watch_html)
assert expected == result
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_get_vid_desc(cipher_signature):
expected = (
"PSY - ‘I LUV IT’ M/V @ https://youtu.be/Xvjnoagk6GU\n"
"PSY - ‘New Face’ M/V @https://youtu.be/OwJPPaEyqhI\n"
"PSY - 8TH ALBUM '4X2=8' on iTunes @\n"
"https://smarturl.it/PSY_8thAlbum\n"
"PSY - GANGNAM STYLE(강남스타일) on iTunes @ http://smarturl.it/PsyGangnam\n"
"#PSY #싸이 #GANGNAMSTYLE #강남스타일\n"
"More about PSY@\nhttp://www.youtube.com/officialpsy\n"
"http://www.facebook.com/officialpsy\n"
"http://twitter.com/psy_oppa\n"
"https://www.instagram.com/42psy42\n"
"http://iTunes.com/PSY\n"
"http://sptfy.com/PSY\n"
"http://weibo.com/psyoppa"
)
assert extract._get_vid_descr(cipher_signature.watch_html) == expected
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("")
|