mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-22 16:44:32 +01:00
_find_jwplayer_data() returns dict or None
This simplifies code for callers of `_find_jwplayer_data()` which no longer have to run `_parse_json()` on the return value. It also makes sure that `_find_jwplayer_data()` returns either a `dict` or `None` and nothing else.
This commit is contained in:
parent
03486dbb01
commit
c73e330e7a
@ -2161,18 +2161,24 @@ class InfoExtractor(object):
|
|||||||
})
|
})
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
@staticmethod
|
def _find_jwplayer_data(self, webpage, video_id=None, transform_source=js_to_json):
|
||||||
def _find_jwplayer_data(webpage):
|
|
||||||
mobj = re.search(
|
mobj = re.search(
|
||||||
r'jwplayer\((?P<quote>[\'"])[^\'" ]+(?P=quote)\)\.setup\s*\((?P<options>[^)]+)\)',
|
r'jwplayer\((?P<quote>[\'"])[^\'" ]+(?P=quote)\)\.setup\s*\((?P<options>[^)]+)\)',
|
||||||
webpage)
|
webpage)
|
||||||
if mobj:
|
if mobj:
|
||||||
return mobj.group('options')
|
try:
|
||||||
|
jwplayer_data = self._parse_json(mobj.group('options'),
|
||||||
|
video_id=video_id,
|
||||||
|
transform_source=transform_source)
|
||||||
|
except ExtractorError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if isinstance(jwplayer_data, dict):
|
||||||
|
return jwplayer_data
|
||||||
|
|
||||||
def _extract_jwplayer_data(self, webpage, video_id, *args, **kwargs):
|
def _extract_jwplayer_data(self, webpage, video_id, *args, **kwargs):
|
||||||
jwplayer_data = self._parse_json(
|
jwplayer_data = self._find_jwplayer_data(
|
||||||
self._find_jwplayer_data(webpage), video_id,
|
webpage, video_id, transform_source=js_to_json)
|
||||||
transform_source=js_to_json)
|
|
||||||
return self._parse_jwplayer_data(
|
return self._parse_jwplayer_data(
|
||||||
jwplayer_data, video_id, *args, **kwargs)
|
jwplayer_data, video_id, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -2518,14 +2518,10 @@ class GenericIE(InfoExtractor):
|
|||||||
self._sort_formats(entry['formats'])
|
self._sort_formats(entry['formats'])
|
||||||
return self.playlist_result(entries)
|
return self.playlist_result(entries)
|
||||||
|
|
||||||
jwplayer_data_str = self._find_jwplayer_data(webpage)
|
jwplayer_data = self._find_jwplayer_data(
|
||||||
if jwplayer_data_str:
|
webpage, video_id, transform_source=js_to_json)
|
||||||
try:
|
if jwplayer_data:
|
||||||
jwplayer_data = self._parse_json(
|
return self._parse_jwplayer_data(jwplayer_data, video_id)
|
||||||
jwplayer_data_str, video_id, transform_source=js_to_json)
|
|
||||||
return self._parse_jwplayer_data(jwplayer_data, video_id)
|
|
||||||
except ExtractorError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def check_video(vurl):
|
def check_video(vurl):
|
||||||
if YoutubeIE.suitable(vurl):
|
if YoutubeIE.suitable(vurl):
|
||||||
|
@ -31,9 +31,8 @@ class TVNoeIE(InfoExtractor):
|
|||||||
r'<iframe[^>]+src="([^"]+)"', webpage, 'iframe URL')
|
r'<iframe[^>]+src="([^"]+)"', webpage, 'iframe URL')
|
||||||
|
|
||||||
ifs_page = self._download_webpage(iframe_url, video_id)
|
ifs_page = self._download_webpage(iframe_url, video_id)
|
||||||
jwplayer_data = self._parse_json(
|
jwplayer_data = self._find_jwplayer_data(
|
||||||
self._find_jwplayer_data(ifs_page),
|
ifs_page, video_id, transform_source=js_to_json)
|
||||||
video_id, transform_source=js_to_json)
|
|
||||||
info_dict = self._parse_jwplayer_data(
|
info_dict = self._parse_jwplayer_data(
|
||||||
jwplayer_data, video_id, require_title=False, base_url=iframe_url)
|
jwplayer_data, video_id, require_title=False, base_url=iframe_url)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user