removed the conditional
Browse files- pytube/request.py +2 -1
- pytube/streams.py +1 -4
- tests/test_request.py +2 -2
- tests/test_streams.py +7 -7
pytube/request.py
CHANGED
@@ -22,7 +22,8 @@ def get(
|
|
22 |
if streaming:
|
23 |
return stream_response(response, chunk_size)
|
24 |
elif headers:
|
25 |
-
|
|
|
26 |
return (
|
27 |
response
|
28 |
.read()
|
|
|
22 |
if streaming:
|
23 |
return stream_response(response, chunk_size)
|
24 |
elif headers:
|
25 |
+
# https://github.com/nficano/pytube/issues/160
|
26 |
+
return {k.lower(): v for k, v in response.info().items()}
|
27 |
return (
|
28 |
response
|
29 |
.read()
|
pytube/streams.py
CHANGED
@@ -135,10 +135,7 @@ class Stream(object):
|
|
135 |
def filesize(self):
|
136 |
"""File size of the media stream in bytes."""
|
137 |
headers = request.get(self.url, headers=True)
|
138 |
-
|
139 |
-
if 'content-length' in headers:
|
140 |
-
return int(headers['content-length'])
|
141 |
-
return int(headers['Content-Length'])
|
142 |
|
143 |
@property
|
144 |
def default_filename(self):
|
|
|
135 |
def filesize(self):
|
136 |
"""File size of the media stream in bytes."""
|
137 |
headers = request.get(self.url, headers=True)
|
138 |
+
return int(headers['content-length'])
|
|
|
|
|
|
|
139 |
|
140 |
@property
|
141 |
def default_filename(self):
|
tests/test_request.py
CHANGED
@@ -27,10 +27,10 @@ def test_get_streaming(mock_urlopen):
|
|
27 |
@mock.patch('pytube.request.urlopen')
|
28 |
def test_get_headers(mock_urlopen):
|
29 |
response = mock.Mock()
|
30 |
-
response.info.return_value = {'
|
31 |
mock_urlopen.return_value = response
|
32 |
response = request.get('fakeassurl.gov', headers=True)
|
33 |
-
assert response == {'
|
34 |
|
35 |
|
36 |
@mock.patch('pytube.request.urlopen')
|
|
|
27 |
@mock.patch('pytube.request.urlopen')
|
28 |
def test_get_headers(mock_urlopen):
|
29 |
response = mock.Mock()
|
30 |
+
response.info.return_value = {'content-length': '16384'}
|
31 |
mock_urlopen.return_value = response
|
32 |
response = request.get('fakeassurl.gov', headers=True)
|
33 |
+
assert response == {'content-length': '16384'}
|
34 |
|
35 |
|
36 |
@mock.patch('pytube.request.urlopen')
|
tests/test_streams.py
CHANGED
@@ -9,7 +9,7 @@ from pytube import Stream
|
|
9 |
|
10 |
def test_filesize(cipher_signature, mocker):
|
11 |
mocker.patch.object(request, 'get')
|
12 |
-
request.get.return_value = {'
|
13 |
assert cipher_signature.streams.first().filesize == 6796391
|
14 |
|
15 |
|
@@ -22,8 +22,8 @@ def test_default_filename(cipher_signature):
|
|
22 |
def test_download(cipher_signature, mocker):
|
23 |
mocker.patch.object(request, 'get')
|
24 |
request.get.side_effect = [
|
25 |
-
{'
|
26 |
-
{'
|
27 |
iter([str(random.getrandbits(8 * 1024))]),
|
28 |
]
|
29 |
with mock.patch('pytube.streams.open', mock.mock_open(), create=True):
|
@@ -47,8 +47,8 @@ def test_on_progress_hook(cipher_signature, mocker):
|
|
47 |
|
48 |
mocker.patch.object(request, 'get')
|
49 |
request.get.side_effect = [
|
50 |
-
{'
|
51 |
-
{'
|
52 |
iter([str(random.getrandbits(8 * 1024))]),
|
53 |
]
|
54 |
with mock.patch('pytube.streams.open', mock.mock_open(), create=True):
|
@@ -67,8 +67,8 @@ def test_on_complete_hook(cipher_signature, mocker):
|
|
67 |
|
68 |
mocker.patch.object(request, 'get')
|
69 |
request.get.side_effect = [
|
70 |
-
{'
|
71 |
-
{'
|
72 |
iter([str(random.getrandbits(8 * 1024))]),
|
73 |
]
|
74 |
with mock.patch('pytube.streams.open', mock.mock_open(), create=True):
|
|
|
9 |
|
10 |
def test_filesize(cipher_signature, mocker):
|
11 |
mocker.patch.object(request, 'get')
|
12 |
+
request.get.return_value = {'content-length': '6796391'}
|
13 |
assert cipher_signature.streams.first().filesize == 6796391
|
14 |
|
15 |
|
|
|
22 |
def test_download(cipher_signature, mocker):
|
23 |
mocker.patch.object(request, 'get')
|
24 |
request.get.side_effect = [
|
25 |
+
{'content-length': '16384'},
|
26 |
+
{'content-length': '16384'},
|
27 |
iter([str(random.getrandbits(8 * 1024))]),
|
28 |
]
|
29 |
with mock.patch('pytube.streams.open', mock.mock_open(), create=True):
|
|
|
47 |
|
48 |
mocker.patch.object(request, 'get')
|
49 |
request.get.side_effect = [
|
50 |
+
{'content-length': '16384'},
|
51 |
+
{'content-length': '16384'},
|
52 |
iter([str(random.getrandbits(8 * 1024))]),
|
53 |
]
|
54 |
with mock.patch('pytube.streams.open', mock.mock_open(), create=True):
|
|
|
67 |
|
68 |
mocker.patch.object(request, 'get')
|
69 |
request.get.side_effect = [
|
70 |
+
{'content-length': '16384'},
|
71 |
+
{'content-length': '16384'},
|
72 |
iter([str(random.getrandbits(8 * 1024))]),
|
73 |
]
|
74 |
with mock.patch('pytube.streams.open', mock.mock_open(), create=True):
|