Kavi
commited on
add logic to detect occurences of signatureCipher in stream_data formats (#631)
Browse files* add logic to detect occurrences of signatureCipher in stream_data formats
* add unit test to check signatureCipher key is correctly handled
- pytube/extract.py +5 -1
- tests/conftest.py +13 -0
- tests/mocks/yt-video-WXxV9g7lsFE.json.gz +0 -0
- tests/test_extract.py +5 -0
pytube/extract.py
CHANGED
@@ -315,7 +315,11 @@ def apply_descrambler(stream_data: Dict, key: str) -> None:
|
|
315 |
]
|
316 |
except KeyError:
|
317 |
cipher_url = [
|
318 |
-
parse_qs(
|
|
|
|
|
|
|
|
|
319 |
for i, data in enumerate(formats)
|
320 |
]
|
321 |
stream_data[key] = [
|
|
|
315 |
]
|
316 |
except KeyError:
|
317 |
cipher_url = [
|
318 |
+
parse_qs(
|
319 |
+
formats[i][
|
320 |
+
"cipher" if "cipher" in data.keys() else "signatureCipher"
|
321 |
+
]
|
322 |
+
)
|
323 |
for i, data in enumerate(formats)
|
324 |
]
|
325 |
stream_data[key] = [
|
tests/conftest.py
CHANGED
@@ -75,3 +75,16 @@ def playlist_long_html():
|
|
75 |
)
|
76 |
with gzip.open(file_path, "rb") as f:
|
77 |
return f.read().decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
)
|
76 |
with gzip.open(file_path, "rb") as f:
|
77 |
return f.read().decode("utf-8")
|
78 |
+
|
79 |
+
|
80 |
+
@pytest.fixture
|
81 |
+
def stream_dict():
|
82 |
+
"""Youtube instance initialized with video id WXxV9g7lsFE."""
|
83 |
+
file_path = os.path.join(
|
84 |
+
os.path.dirname(os.path.realpath(__file__)),
|
85 |
+
"mocks",
|
86 |
+
"yt-video-WXxV9g7lsFE.json.gz",
|
87 |
+
)
|
88 |
+
with gzip.open(file_path, "rb") as f:
|
89 |
+
content = f.read().decode("utf-8")
|
90 |
+
return json.loads(content)
|
tests/mocks/yt-video-WXxV9g7lsFE.json.gz
ADDED
Binary file (55.7 kB). View file
|
|
tests/test_extract.py
CHANGED
@@ -87,3 +87,8 @@ def test_mime_type_codec_with_no_match_should_error():
|
|
87 |
def test_get_ytplayer_config_with_no_match_should_error():
|
88 |
with pytest.raises(RegexMatchError):
|
89 |
extract.get_ytplayer_config("")
|
|
|
|
|
|
|
|
|
|
|
|
87 |
def test_get_ytplayer_config_with_no_match_should_error():
|
88 |
with pytest.raises(RegexMatchError):
|
89 |
extract.get_ytplayer_config("")
|
90 |
+
|
91 |
+
|
92 |
+
def test_signature_cipher_does_not_error(stream_dict):
|
93 |
+
extract.apply_descrambler(stream_dict, "url_encoded_fmt_stream_map")
|
94 |
+
assert "s" in stream_dict["url_encoded_fmt_stream_map"][0].keys()
|