mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-17 00:22:34 +01:00
Refactored swearnet extractor to extend Vidyard extractor
This commit is contained in:
parent
0b7a359272
commit
fd00a4e7f6
@ -1,13 +1,14 @@
|
|||||||
from .common import InfoExtractor
|
from .vidyard import VidyardBaseIE
|
||||||
from ..utils import ExtractorError, int_or_none, traverse_obj
|
from ..utils import ExtractorError, int_or_none
|
||||||
|
|
||||||
|
|
||||||
class SwearnetEpisodeIE(InfoExtractor):
|
class SwearnetEpisodeIE(VidyardBaseIE):
|
||||||
_VALID_URL = r'https?://www\.swearnet\.com/shows/(?P<id>[\w-]+)/seasons/(?P<season_num>\d+)/episodes/(?P<episode_num>\d+)'
|
_VALID_URL = r'https?://www\.swearnet\.com/shows/(?P<id>[\w-]+)/seasons/(?P<season_num>\d+)/episodes/(?P<episode_num>\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1',
|
'url': 'https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '232819',
|
'id': 'APKGwroXAeCmGxc0mg3sWQ',
|
||||||
|
'display_id': '232819',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'episode_number': 1,
|
'episode_number': 1,
|
||||||
'episode': 'Episode 1',
|
'episode': 'Episode 1',
|
||||||
@ -16,37 +17,10 @@ class SwearnetEpisodeIE(InfoExtractor):
|
|||||||
'season': 'Season 1',
|
'season': 'Season 1',
|
||||||
'title': 'Episode 1 - Grilled Cheese Sammich',
|
'title': 'Episode 1 - Grilled Cheese Sammich',
|
||||||
'season_number': 1,
|
'season_number': 1,
|
||||||
'thumbnail': 'https://cdn.vidyard.com/thumbnails/232819/_RX04IKIq60a2V6rIRqq_Q_small.jpg',
|
'thumbnail': 'https://cdn.vidyard.com/thumbnails/custom/0dd74f9b-388a-452e-b570-b407fb64435b_small.jpg',
|
||||||
},
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _get_formats_and_subtitle(self, video_source, video_id):
|
|
||||||
video_source = video_source or {}
|
|
||||||
formats, subtitles = [], {}
|
|
||||||
for key, value in video_source.items():
|
|
||||||
if key == 'hls':
|
|
||||||
for video_hls in value:
|
|
||||||
fmts, subs = self._extract_m3u8_formats_and_subtitles(video_hls.get('url'), video_id)
|
|
||||||
formats.extend(fmts)
|
|
||||||
self._merge_subtitles(subs, target=subtitles)
|
|
||||||
else:
|
|
||||||
formats.extend({
|
|
||||||
'url': video_mp4.get('url'),
|
|
||||||
'ext': 'mp4',
|
|
||||||
} for video_mp4 in value)
|
|
||||||
|
|
||||||
return formats, subtitles
|
|
||||||
|
|
||||||
def _get_direct_subtitle(self, caption_json):
|
|
||||||
subs = {}
|
|
||||||
for caption in caption_json:
|
|
||||||
subs.setdefault(caption.get('language') or 'und', []).append({
|
|
||||||
'url': caption.get('vttUrl'),
|
|
||||||
'name': caption.get('name'),
|
|
||||||
})
|
|
||||||
|
|
||||||
return subs
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
|
display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
|
||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
@ -58,22 +32,17 @@ def _real_extract(self, url):
|
|||||||
self.raise_login_required()
|
self.raise_login_required()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
json_data = self._download_json(
|
video_json = self._fetch_video_json(external_id, display_id)
|
||||||
f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0]
|
video_info = {
|
||||||
|
**self._process_video_json(video_json['chapters'][0], display_id),
|
||||||
formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id)
|
|
||||||
self._merge_subtitles(self._get_direct_subtitle(json_data.get('captions')), target=subtitles)
|
|
||||||
|
|
||||||
return {
|
|
||||||
'id': str(json_data['videoId']),
|
|
||||||
'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
|
|
||||||
'description': (json_data.get('description')
|
|
||||||
or self._html_search_meta(['og:description', 'twitter:description'], webpage)),
|
|
||||||
'duration': int_or_none(json_data.get('seconds')),
|
|
||||||
'formats': formats,
|
|
||||||
'subtitles': subtitles,
|
|
||||||
'season_number': int_or_none(season_number),
|
'season_number': int_or_none(season_number),
|
||||||
'episode_number': int_or_none(episode_number),
|
'episode_number': int_or_none(episode_number),
|
||||||
'thumbnails': [{'url': thumbnail_url}
|
|
||||||
for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if video_info['title'] is None:
|
||||||
|
video_info['title'] = self._html_search_meta(['og:title', 'twitter:title'], webpage)
|
||||||
|
|
||||||
|
if video_info['description'] is None:
|
||||||
|
video_info['description'] = self._html_search_meta(['og:description', 'twitter:description'], webpage)
|
||||||
|
|
||||||
|
return video_info
|
||||||
|
Loading…
Reference in New Issue
Block a user