mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-12 05:18:00 +09:00
[doodstream] use try_get and add helper function try_doodExe
This commit is contained in:
parent
671e6022be
commit
cc5a2e533e
@ -9,6 +9,7 @@ from .common import InfoExtractor
|
|||||||
from ..utils import (
|
from ..utils import (
|
||||||
js_to_json,
|
js_to_json,
|
||||||
urljoin,
|
urljoin,
|
||||||
|
try_get,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -29,6 +30,15 @@ def doodExe(crp, crs):
|
|||||||
return result
|
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):
|
class DoodStreamIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?(?:doodstream\.com|dood\.(?:cx|so|to|watch))/[de]/(?P<id>[^/?#]+)'
|
_VALID_URL = r'https?://(?:www\.)?(?:doodstream\.com|dood\.(?:cx|so|to|watch))/[de]/(?P<id>[^/?#]+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
@ -58,20 +68,6 @@ class DoodStreamIE(InfoExtractor):
|
|||||||
metadata_url = urljoin(url, metadata_url)
|
metadata_url = urljoin(url, metadata_url)
|
||||||
metadata = self._download_json(metadata_url, video_id, headers=referer)
|
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')
|
token = self._html_search_regex(r"[?&]token=([a-z0-9]+)[&']", webpage, 'token')
|
||||||
auth_url = self._html_search_regex(r"('/pass_md5.*?')", webpage,
|
auth_url = self._html_search_regex(r"('/pass_md5.*?')", webpage,
|
||||||
'pass_md5')
|
'pass_md5')
|
||||||
@ -84,11 +80,11 @@ class DoodStreamIE(InfoExtractor):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': title,
|
'title': try_doodExe(metadata, 'ttl') or video_id,
|
||||||
'url': final_url,
|
'url': final_url,
|
||||||
'http_headers': referer,
|
'http_headers': referer,
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'thumbnail': thumb,
|
'thumbnail': self._og_search_thumbnail(webpage),
|
||||||
'filesize': filesize,
|
'filesize': try_get(try_doodExe(metadata, 'siz'), lambda x: int(x, 10)),
|
||||||
'duration': duration,
|
'duration': try_get(try_doodExe(metadata, 'len'), lambda x: int(x, 10)),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user