Taylor Fox Dahlin commited on
Fix/#845 (#856)
Browse files- pytube/extract.py +4 -2
- pytube/parser.py +4 -1
pytube/extract.py
CHANGED
|
@@ -302,7 +302,9 @@ def get_ytplayer_config(html: str) -> Any:
|
|
| 302 |
# Try each pattern consecutively if they don't find a match
|
| 303 |
try:
|
| 304 |
return parse_for_object(html, pattern)
|
| 305 |
-
except HTMLParseError:
|
|
|
|
|
|
|
| 306 |
continue
|
| 307 |
|
| 308 |
# setConfig() needs to be handled a little differently.
|
|
@@ -398,7 +400,7 @@ def apply_descrambler(stream_data: Dict, key: str) -> None:
|
|
| 398 |
if isinstance(stream_data["player_response"], str):
|
| 399 |
streaming_data = json.loads(stream_data["player_response"])["streamingData"]
|
| 400 |
else:
|
| 401 |
-
streaming_data = stream_data["player_response"]
|
| 402 |
formats = []
|
| 403 |
if 'formats' in streaming_data.keys():
|
| 404 |
formats.extend(streaming_data['formats'])
|
|
|
|
| 302 |
# Try each pattern consecutively if they don't find a match
|
| 303 |
try:
|
| 304 |
return parse_for_object(html, pattern)
|
| 305 |
+
except HTMLParseError as e:
|
| 306 |
+
logger.debug(f'Pattern failed: {pattern}')
|
| 307 |
+
logger.debug(e)
|
| 308 |
continue
|
| 309 |
|
| 310 |
# setConfig() needs to be handled a little differently.
|
|
|
|
| 400 |
if isinstance(stream_data["player_response"], str):
|
| 401 |
streaming_data = json.loads(stream_data["player_response"])["streamingData"]
|
| 402 |
else:
|
| 403 |
+
streaming_data = stream_data["player_response"]["streamingData"]
|
| 404 |
formats = []
|
| 405 |
if 'formats' in streaming_data.keys():
|
| 406 |
formats.extend(streaming_data['formats'])
|
pytube/parser.py
CHANGED
|
@@ -80,4 +80,7 @@ def parse_for_object_from_startpoint(html, start_point):
|
|
| 80 |
try:
|
| 81 |
return json.loads(full_obj)
|
| 82 |
except json.decoder.JSONDecodeError:
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
try:
|
| 81 |
return json.loads(full_obj)
|
| 82 |
except json.decoder.JSONDecodeError:
|
| 83 |
+
try:
|
| 84 |
+
return ast.literal_eval(full_obj)
|
| 85 |
+
except ValueError:
|
| 86 |
+
raise HTMLParseError('Could not parse object.')
|