From cc5a2e533e19ad003940ce20eb979fda81ae76b5 Mon Sep 17 00:00:00 2001 From: schnusch Date: Mon, 31 May 2021 18:45:21 +0200 Subject: [PATCH] [doodstream] use try_get and add helper function try_doodExe --- youtube_dl/extractor/doodstream.py | 32 +++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/youtube_dl/extractor/doodstream.py b/youtube_dl/extractor/doodstream.py index c1f94c856..5143187f7 100644 --- a/youtube_dl/extractor/doodstream.py +++ b/youtube_dl/extractor/doodstream.py @@ -9,6 +9,7 @@ from .common import InfoExtractor from ..utils import ( js_to_json, urljoin, + try_get, ) @@ -29,6 +30,15 @@ def doodExe(crp, crs): return result +def try_doodExe(metadata, key): + try: + x = metadata[key] + # everything that can go wrong in this call raises a TypeError + return doodExe(**x) + except (KeyError, TypeError): + return None + + class DoodStreamIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?(?:doodstream\.com|dood\.(?:cx|so|to|watch))/[de]/(?P[^/?#]+)' _TESTS = [{ @@ -58,20 +68,6 @@ class DoodStreamIE(InfoExtractor): metadata_url = urljoin(url, metadata_url) metadata = self._download_json(metadata_url, video_id, headers=referer) - thumb = self._og_search_thumbnail(webpage) - try: - filesize = int(doodExe(**metadata['siz']), 10) - except (KeyError, ValueError): - filesize = None - try: - duration = int(doodExe(**metadata['len']), 10) - except (KeyError, ValueError): - duration = None - try: - title = doodExe(**metadata['ttl']) - except KeyError: - title = video_id - token = self._html_search_regex(r"[?&]token=([a-z0-9]+)[&']", webpage, 'token') auth_url = self._html_search_regex(r"('/pass_md5.*?')", webpage, 'pass_md5') @@ -84,11 +80,11 @@ class DoodStreamIE(InfoExtractor): return { 'id': video_id, - 'title': title, + 'title': try_doodExe(metadata, 'ttl') or video_id, 'url': final_url, 'http_headers': referer, 'ext': 'mp4', - 'thumbnail': thumb, - 'filesize': filesize, - 'duration': duration, + 'thumbnail': self._og_search_thumbnail(webpage), + 'filesize': try_get(try_doodExe(metadata, 'siz'), lambda x: int(x, 10)), + 'duration': try_get(try_doodExe(metadata, 'len'), lambda x: int(x, 10)), }