From 3fde270c23b78712bf99d5eba52ea9d9453f4ddc Mon Sep 17 00:00:00 2001 From: Mike Gering Date: Tue, 19 May 2020 09:51:22 -0400 Subject: [PATCH] Fix for issue #25311, redtube json error --- youtube_dl/extractor/redtube.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/redtube.py b/youtube_dl/extractor/redtube.py index b1bde1e81..ae63de70b 100644 --- a/youtube_dl/extractor/redtube.py +++ b/youtube_dl/extractor/redtube.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import json import re from .common import InfoExtractor @@ -75,10 +76,15 @@ class RedTubeIE(InfoExtractor): 'format_id': format_id, 'height': int_or_none(format_id), }) + # find the mediaDefinitions string that is json-parsable + mobj = re.search(r'mediaDefinition\s*:\s*(\[.+?\])', webpage) + doc1 = webpage[mobj.start(1):] + try: + x = json.loads(doc1) + except json.JSONDecodeError as exc: + doc1 = doc1[0:exc.pos] medias = self._parse_json( - self._search_regex( - r'mediaDefinition\s*:\s*(\[.+?\])', webpage, - 'media definitions', default='{}'), + doc1, video_id, fatal=False) if medias and isinstance(medias, list): for media in medias: