add prefix test
Browse files- pytube/contrib/playlist.py +2 -2
- tests/test_streams.py +14 -1
pytube/contrib/playlist.py
CHANGED
@@ -107,7 +107,7 @@ class Playlist:
|
|
107 |
return self.video_urls
|
108 |
|
109 |
@deprecated("This function will be removed in the future.")
|
110 |
-
def _path_num_prefix_generator(self, reverse=False):
|
111 |
"""
|
112 |
This generator function generates number prefixes, for the items
|
113 |
in the playlist.
|
@@ -134,7 +134,7 @@ class Playlist:
|
|
134 |
prefix_number: bool = True,
|
135 |
reverse_numbering: bool = False,
|
136 |
resolution: str = "720p",
|
137 |
-
) -> None:
|
138 |
"""Download all the videos in the the playlist. Initially, download
|
139 |
resolution is 720p (or highest available), later more option
|
140 |
should be added to download resolution of choice
|
|
|
107 |
return self.video_urls
|
108 |
|
109 |
@deprecated("This function will be removed in the future.")
|
110 |
+
def _path_num_prefix_generator(self, reverse=False): # pragma: no cover
|
111 |
"""
|
112 |
This generator function generates number prefixes, for the items
|
113 |
in the playlist.
|
|
|
134 |
prefix_number: bool = True,
|
135 |
reverse_numbering: bool = False,
|
136 |
resolution: str = "720p",
|
137 |
+
) -> None: # pragma: no cover
|
138 |
"""Download all the videos in the the playlist. Initially, download
|
139 |
resolution is 720p (or highest available), later more option
|
140 |
should be added to download resolution of choice
|
tests/test_streams.py
CHANGED
@@ -2,9 +2,10 @@
|
|
2 |
import random
|
3 |
|
4 |
from unittest import mock
|
|
|
5 |
|
6 |
from pytube import request
|
7 |
-
from pytube import Stream
|
8 |
|
9 |
|
10 |
def test_filesize(cipher_signature, mocker):
|
@@ -45,6 +46,18 @@ def test_download(cipher_signature, mocker):
|
|
45 |
stream.download()
|
46 |
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def test_progressive_streams_return_includes_audio_track(cipher_signature):
|
49 |
stream = cipher_signature.streams.filter(progressive=True).first()
|
50 |
assert stream.includes_audio_track
|
|
|
2 |
import random
|
3 |
|
4 |
from unittest import mock
|
5 |
+
from unittest.mock import MagicMock
|
6 |
|
7 |
from pytube import request
|
8 |
+
from pytube import Stream, streams
|
9 |
|
10 |
|
11 |
def test_filesize(cipher_signature, mocker):
|
|
|
46 |
stream.download()
|
47 |
|
48 |
|
49 |
+
def test_download_with_prefix(cipher_signature, mocker):
|
50 |
+
mocker.patch.object(request, "headers")
|
51 |
+
request.headers.return_value = {"content-length": "16384"}
|
52 |
+
mocker.patch.object(request, "stream")
|
53 |
+
request.stream.return_value = iter([str(random.getrandbits(8 * 1024))])
|
54 |
+
streams.target_directory = MagicMock(return_value="/target")
|
55 |
+
with mock.patch("pytube.streams.open", mock.mock_open(), create=True):
|
56 |
+
stream = cipher_signature.streams.first()
|
57 |
+
file_path = stream.download(filename_prefix="prefix")
|
58 |
+
assert file_path == "/target/prefixPSY - GANGNAM STYLE(강남스타일) MV.mp4"
|
59 |
+
|
60 |
+
|
61 |
def test_progressive_streams_return_includes_audio_track(cipher_signature):
|
62 |
stream = cipher_signature.streams.filter(progressive=True).first()
|
63 |
assert stream.includes_audio_track
|