stream expiration property
Browse files- pytube/request.py +1 -2
- pytube/streams.py +7 -0
- tests/test_streams.py +5 -0
pytube/request.py
CHANGED
@@ -8,7 +8,6 @@ from typing import Iterable, Dict, Optional
|
|
8 |
from urllib.request import Request
|
9 |
from urllib.request import urlopen
|
10 |
|
11 |
-
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
|
@@ -54,7 +53,7 @@ def stream(
|
|
54 |
response = _execute_request(url, method="GET", headers={"Range": range_header})
|
55 |
if file_size == range_size:
|
56 |
try:
|
57 |
-
content_range = response.info()[
|
58 |
file_size = int(content_range.split("/")[1])
|
59 |
except (KeyError, IndexError, ValueError) as e:
|
60 |
logger.error(e)
|
|
|
8 |
from urllib.request import Request
|
9 |
from urllib.request import urlopen
|
10 |
|
|
|
11 |
logger = logging.getLogger(__name__)
|
12 |
|
13 |
|
|
|
53 |
response = _execute_request(url, method="GET", headers={"Range": range_header})
|
54 |
if file_size == range_size:
|
55 |
try:
|
56 |
+
content_range = response.info()["Content-Range"]
|
57 |
file_size = int(content_range.split("/")[1])
|
58 |
except (KeyError, IndexError, ValueError) as e:
|
59 |
logger.error(e)
|
pytube/streams.py
CHANGED
@@ -9,9 +9,11 @@ has been renamed to accommodate DASH (which serves the audio and video
|
|
9 |
separately).
|
10 |
"""
|
11 |
|
|
|
12 |
import logging
|
13 |
import os
|
14 |
from typing import Dict, Tuple, Optional, BinaryIO
|
|
|
15 |
|
16 |
from pytube import extract
|
17 |
from pytube import request
|
@@ -169,6 +171,11 @@ class Stream:
|
|
169 |
|
170 |
return self.filesize
|
171 |
|
|
|
|
|
|
|
|
|
|
|
172 |
@property
|
173 |
def default_filename(self) -> str:
|
174 |
"""Generate filename based on the video title.
|
|
|
9 |
separately).
|
10 |
"""
|
11 |
|
12 |
+
from datetime import datetime
|
13 |
import logging
|
14 |
import os
|
15 |
from typing import Dict, Tuple, Optional, BinaryIO
|
16 |
+
from urllib.parse import parse_qs
|
17 |
|
18 |
from pytube import extract
|
19 |
from pytube import request
|
|
|
171 |
|
172 |
return self.filesize
|
173 |
|
174 |
+
@property
|
175 |
+
def expiration(self) -> datetime:
|
176 |
+
expire = parse_qs(self.url.split("?")[1])["expire"][0]
|
177 |
+
return datetime.fromtimestamp(int(expire))
|
178 |
+
|
179 |
@property
|
180 |
def default_filename(self) -> str:
|
181 |
"""Generate filename based on the video title.
|
tests/test_streams.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
import os
|
3 |
import random
|
|
|
4 |
from unittest import mock
|
5 |
from unittest.mock import MagicMock
|
6 |
|
@@ -59,6 +60,10 @@ def test_title(cipher_signature):
|
|
59 |
assert cipher_signature.title == expected
|
60 |
|
61 |
|
|
|
|
|
|
|
|
|
62 |
def test_caption_tracks(presigned_video):
|
63 |
assert len(presigned_video.caption_tracks) == 13
|
64 |
|
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
import os
|
3 |
import random
|
4 |
+
from datetime import datetime
|
5 |
from unittest import mock
|
6 |
from unittest.mock import MagicMock
|
7 |
|
|
|
60 |
assert cipher_signature.title == expected
|
61 |
|
62 |
|
63 |
+
def test_expiration(cipher_signature):
|
64 |
+
assert cipher_signature.streams[0].expiration == datetime(2020, 1, 15, 21, 12, 5)
|
65 |
+
|
66 |
+
|
67 |
def test_caption_tracks(presigned_video):
|
68 |
assert len(presigned_video.caption_tracks) == 13
|
69 |
|