tests + hotfix
Browse files- pytube/streams.py +3 -0
- tests/test_cipher.py +10 -0
- tests/test_exceptions.py +9 -0
pytube/streams.py
CHANGED
|
@@ -135,6 +135,9 @@ 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 |
return int(headers['Content-Length'])
|
| 139 |
|
| 140 |
@property
|
|
|
|
| 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
|
tests/test_cipher.py
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
from pytube import cipher
|
| 5 |
+
from pytube.exceptions import RegexMatchError
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_map_functions():
|
| 9 |
+
with pytest.raises(RegexMatchError):
|
| 10 |
+
cipher.map_functions('asdf')
|
tests/test_exceptions.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from pytube.exceptions import ExtractError
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def test_is_expected():
|
| 6 |
+
try:
|
| 7 |
+
raise ExtractError('ppfff', video_id='YLnZklYFe7E')
|
| 8 |
+
except ExtractError as e:
|
| 9 |
+
assert e.video_id == 'YLnZklYFe7E'
|