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: "<url of video>",
             label: "<title of video>",
             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.
This commit is contained in:
Mohammed Yaseen Mowzer 2017-03-21 12:38:51 +02:00
parent 8a8cc339b6
commit fe6f302959

View File

@ -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 ''