docstrings and linting
Browse files- .idea/dictionaries/haroldmartin.xml +1 -0
- pytube/cli.py +3 -1
- pytube/request.py +8 -3
- tests/test_streams.py +2 -0
.idea/dictionaries/haroldmartin.xml
CHANGED
@@ -28,6 +28,7 @@
|
|
28 |
<w>nosec</w>
|
29 |
<w>ntfs</w>
|
30 |
<w>prog</w>
|
|
|
31 |
<w>pytube</w>
|
32 |
<w>recompiles</w>
|
33 |
<w>samp</w>
|
|
|
28 |
<w>nosec</w>
|
29 |
<w>ntfs</w>
|
30 |
<w>prog</w>
|
31 |
+
<w>pylint</w>
|
32 |
<w>pytube</w>
|
33 |
<w>recompiles</w>
|
34 |
<w>samp</w>
|
pytube/cli.py
CHANGED
@@ -209,7 +209,9 @@ def display_progress_bar(
|
|
209 |
|
210 |
|
211 |
# noinspection PyUnusedLocal
|
212 |
-
def on_progress(
|
|
|
|
|
213 |
filesize = stream.filesize
|
214 |
bytes_received = filesize - bytes_remaining
|
215 |
display_progress_bar(bytes_received, filesize)
|
|
|
209 |
|
210 |
|
211 |
# noinspection PyUnusedLocal
|
212 |
+
def on_progress(
|
213 |
+
stream: Any, chunk: bytes, bytes_remaining: int
|
214 |
+
) -> None: # pylint: disable=W0613
|
215 |
filesize = stream.filesize
|
216 |
bytes_received = filesize - bytes_remaining
|
217 |
display_progress_bar(bytes_received, filesize)
|
pytube/request.py
CHANGED
@@ -46,18 +46,23 @@ def stream(
|
|
46 |
while downloaded < file_size:
|
47 |
stop_pos = min(downloaded + range_size, file_size) - 1
|
48 |
range_header = f"bytes={downloaded}-{stop_pos}"
|
49 |
-
|
50 |
while True:
|
51 |
-
chunk =
|
52 |
if not chunk:
|
53 |
break
|
54 |
downloaded += len(chunk)
|
55 |
yield chunk
|
56 |
-
return
|
57 |
|
58 |
|
59 |
@lru_cache(maxsize=None)
|
60 |
def filesize(url: str) -> int:
|
|
|
|
|
|
|
|
|
|
|
61 |
return int(head(url)["content-length"])
|
62 |
|
63 |
|
|
|
46 |
while downloaded < file_size:
|
47 |
stop_pos = min(downloaded + range_size, file_size) - 1
|
48 |
range_header = f"bytes={downloaded}-{stop_pos}"
|
49 |
+
response = _execute_request(url, method="GET", headers={"Range": range_header})
|
50 |
while True:
|
51 |
+
chunk = response.read(chunk_size)
|
52 |
if not chunk:
|
53 |
break
|
54 |
downloaded += len(chunk)
|
55 |
yield chunk
|
56 |
+
return # pylint: disable=R1711
|
57 |
|
58 |
|
59 |
@lru_cache(maxsize=None)
|
60 |
def filesize(url: str) -> int:
|
61 |
+
"""Fetch size in bytes of file at given URL
|
62 |
+
|
63 |
+
:param str url: The URL to get the size of
|
64 |
+
:returns: int: size in bytes of remote file
|
65 |
+
"""
|
66 |
return int(head(url)["content-length"])
|
67 |
|
68 |
|
tests/test_streams.py
CHANGED
@@ -15,6 +15,8 @@ def test_filesize(cipher_signature, mocker):
|
|
15 |
|
16 |
|
17 |
def test_filesize_approx(cipher_signature, mocker):
|
|
|
|
|
18 |
stream = cipher_signature.streams[0]
|
19 |
|
20 |
assert stream.filesize_approx == 22350604
|
|
|
15 |
|
16 |
|
17 |
def test_filesize_approx(cipher_signature, mocker):
|
18 |
+
mocker.patch.object(request, "head")
|
19 |
+
request.head.return_value = {"content-length": "6796391"}
|
20 |
stream = cipher_signature.streams[0]
|
21 |
|
22 |
assert stream.filesize_approx == 22350604
|