1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-16 21:35:51 +00:00

code review fixes

This commit is contained in:
Yuval Hager 2021-02-13 15:52:37 -08:00
parent e6c7b3c154
commit c0fd80c113

View file

@ -32,31 +32,33 @@ class KanBaseIE(InfoExtractor):
def extract_item(self, video_id, webpage): def extract_item(self, video_id, webpage):
data = self._parse_json( data = self._parse_json(
self._search_regex( self._search_regex(
r'<script id="kan_app_search_data" type="application/json">([^<]+)</script>', r'<script[^>]+id="kan_app_search_data"[^>]*>([^<]+)</script>',
webpage, webpage,
'data', 'data',
), ),
video_id, video_id,
) )
title = data.get('title') or self._og_search_title(webpage) title = data.get('title') or self._og_search_title(webpage)
m3u8_url = try_get(data, lambda x: x['content']['src'], compat_str)
formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
if not formats:
raise ExtractorError('Unable to extract video formats')
description = data.get('summary') or \ description = data.get('summary') or \
self._og_search_description(webpage, fatal=False) self._og_search_description(webpage, fatal=False)
creator = try_get(data, lambda x: x['author']['name'], str) or \ creator = try_get(data, lambda x: x['author']['name'], compat_str) or \
self._og_search_property('site_name', webpage, fatal=False) self._og_search_property('site_name', webpage, fatal=False)
thumbnail = get_thumbnail(data) thumbnail = get_thumbnail(data)
m3u8_url = try_get(data, lambda x: x['content']['src'], str)
if not m3u8_url:
raise ExtractorError('Unable to extract m3u8 url')
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'formats': self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4'), 'formats': formats,
'description': description, 'description': description,
'creator': creator, 'creator': creator,
'release_date': unified_strdate(data.get('published')), 'release_date': unified_strdate(data.get('published')),
'duration': parse_duration(data.get('extensions', {}).get('duration')), 'duration': parse_duration(
try_get(data, lambda x: x['extensions']['duration']))
} }
@ -100,10 +102,10 @@ class KanPlaylistIE(KanBaseIE):
video_ids = re.findall(r'onclick="playVideo\(.*,\'([0-9]+)\'\)', webpage) video_ids = re.findall(r'onclick="playVideo\(.*,\'([0-9]+)\'\)', webpage)
entries = [] entries = []
for video_id in video_ids: for video_id in video_ids:
url = 'https://www.kan.org.il/Item/?itemId=%s' % video_id video_url = 'https://www.kan.org.il/Item/?itemId=%s' % video_id
entries.append(self.extract_item( entries.append(self.extract_item(
video_id, video_id,
self.download_webpage(url, video_id)) self.download_webpage(video_url, video_id))
) )
if not entries: if not entries:
raise ExtractorError('Unable to extract playlist entries') raise ExtractorError('Unable to extract playlist entries')