From e8aca87278f43ddd577d57b6955eaa609aa5760e Mon Sep 17 00:00:00 2001 From: dirkf Date: Fri, 22 Jul 2022 15:48:26 +0100 Subject: [PATCH] Improve fallback --- youtube_dl/extractor/megacartoons.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/megacartoons.py b/youtube_dl/extractor/megacartoons.py index ea6161b7b..672bccbdd 100644 --- a/youtube_dl/extractor/megacartoons.py +++ b/youtube_dl/extractor/megacartoons.py @@ -1,7 +1,6 @@ # coding: utf-8 from __future__ import unicode_literals -import json import re from ..utils import ( @@ -10,8 +9,10 @@ from ..utils import ( merge_dicts, NO_DEFAULT, RegexNotFoundError, + try_get, url_or_none, ) +from ..compat import compat_str from .common import InfoExtractor @@ -82,9 +83,9 @@ class MegaCartoonsIE(InfoExtractor): if 'url' not in info or 'thumbnail' not in info: # Video data is stored in a json -> extract it from the raw html - url_json = json.loads(self._html_search_regex(r'{.*})["/\'].*>', webpage, 'videourls')) + url_json = self._parse_json(self._html_search_regex(r''']+\bdata-item\s*=\s*(["'])(?P\{.*})\1''', webpage, 'videourls', group='videourls', default='{}'), video_id, fatal=False)) or {} - video_url = url_or_none(url_json.get('sources')[0].get('src') or self._og_search_video_url(webpage)) # Get the video url + video_url = url_or_none(try_get(url_json, lambda x: x['sources'][0]['src'], compat_str) or self._og_search_video_url(webpage)) # Get the video url video_thumbnail = url_or_none(url_json.get('splash') or self._og_search_thumbnail(webpage)) # Get the thumbnail info = merge_dicts(info, { 'url': video_url,