From fe6f30295986120b60295f9238f232df4d17d89e Mon Sep 17 00:00:00 2001 From: Mohammed Yaseen Mowzer Date: Tue, 21 Mar 2017 12:38:51 +0200 Subject: [PATCH] Raise exception if jwplayer doesn't have "sources" YoutubeDL uses a regexp in common.py::_find_jwplayer_data to find the jwplayer options. However the options are found in a javascript function. For example the regexp might match this jwplayer('some_string').setup({ /** Other attributes */ sources: { file: "", label: "", type: "mp4" } }); Since this a valid javascript function, some websites write the options as var src = { file: "<url of video>", label: "<title of video>", type: "mp4" } jwplayer('some_string').setup({ /** Other attributes */ sources: src }); In this case YoutubeDL won't be able to retrieve sources.file, since the regexp only matches the ".setup(...)" and ignores the "var src = ..." assignment. This commit makes YoutubeDL raise an ExtractorError in the above case. YoutubeDL will then try alternative methods to retrieve the URL of the video. --- youtube_dl/extractor/common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 0852b8e8c..96edbdfb3 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -2243,7 +2243,12 @@ class InfoExtractor(object): m3u8_id=None, mpd_id=None, rtmp_params=None, base_url=None): formats = [] for source in jwplayer_sources_data: - source_url = self._proto_relative_url(source['file']) + try: + source_file = source['file'] + except Exception as e: + raise ExtractorError("Could not retreive 'file' from 'source'", + expected=True, cause=e, video_id=video_id) + source_url = self._proto_relative_url(source_file) if base_url: source_url = compat_urlparse.urljoin(base_url, source_url) source_type = source.get('type') or ''