nficano commited on
Commit
a2b56cd
·
1 Parent(s): 6462b67

removed the conditional

Browse files
pytube/request.py CHANGED
@@ -22,7 +22,8 @@ def get(
22
  if streaming:
23
  return stream_response(response, chunk_size)
24
  elif headers:
25
- return dict(response.info().items())
 
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
- # https://github.com/nficano/pytube/issues/160
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 = {'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')
 
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 = {'Content-Length': '6796391'}
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
- {'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,8 +47,8 @@ def test_on_progress_hook(cipher_signature, mocker):
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,8 +67,8 @@ def test_on_complete_hook(cipher_signature, mocker):
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):
 
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):