]>
Commit | Line | Data |
---|---|---|
049565df H |
1 | from .common import InfoExtractor |
2 | from ..utils import int_or_none, traverse_obj | |
3 | ||
4 | ||
5 | class SwearnetEpisodeIE(InfoExtractor): | |
6 | _VALID_URL = r'https?://www\.swearnet\.com/shows/(?P<id>[\w-]+)/seasons/(?P<season_num>\d+)/episodes/(?P<episode_num>\d+)' | |
7 | _TESTS = [{ | |
8 | 'url': 'https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1', | |
9 | 'info_dict': { | |
10 | 'id': '232819', | |
11 | 'ext': 'mp4', | |
12 | 'episode_number': 1, | |
13 | 'episode': 'Episode 1', | |
14 | 'duration': 719, | |
15 | 'description': 'md5:c48ef71440ce466284c07085cd7bd761', | |
16 | 'season': 'Season 1', | |
17 | 'title': 'Episode 1 - Grilled Cheese Sammich', | |
18 | 'season_number': 1, | |
19 | 'thumbnail': 'https://cdn.vidyard.com/thumbnails/232819/_RX04IKIq60a2V6rIRqq_Q_small.jpg', | |
20 | } | |
21 | }] | |
22 | ||
23 | def _get_formats_and_subtitle(self, video_source, video_id): | |
24 | video_source = video_source or {} | |
25 | formats, subtitles = [], {} | |
26 | for key, value in video_source.items(): | |
27 | if key == 'hls': | |
28 | for video_hls in value: | |
29 | fmts, subs = self._extract_m3u8_formats_and_subtitles(video_hls.get('url'), video_id) | |
30 | formats.extend(fmts) | |
31 | self._merge_subtitles(subs, target=subtitles) | |
32 | else: | |
33 | formats.extend({ | |
34 | 'url': video_mp4.get('url'), | |
35 | 'ext': 'mp4' | |
36 | } for video_mp4 in value) | |
37 | ||
38 | return formats, subtitles | |
39 | ||
40 | def _get_direct_subtitle(self, caption_json): | |
41 | subs = {} | |
42 | for caption in caption_json: | |
43 | subs.setdefault(caption.get('language') or 'und', []).append({ | |
44 | 'url': caption.get('vttUrl'), | |
45 | 'name': caption.get('name') | |
46 | }) | |
47 | ||
48 | return subs | |
49 | ||
50 | def _real_extract(self, url): | |
51 | display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num') | |
52 | webpage = self._download_webpage(url, display_id) | |
53 | ||
54 | external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid') | |
55 | json_data = self._download_json( | |
56 | f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0] | |
57 | ||
58 | formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id) | |
59 | self._merge_subtitles(self._get_direct_subtitle(json_data.get('captions')), target=subtitles) | |
60 | ||
61 | return { | |
62 | 'id': str(json_data['videoId']), | |
63 | 'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage), | |
64 | 'description': (json_data.get('description') | |
ddf1e22d | 65 | or self._html_search_meta(['og:description', 'twitter:description'], webpage)), |
049565df H |
66 | 'duration': int_or_none(json_data.get('seconds')), |
67 | 'formats': formats, | |
68 | 'subtitles': subtitles, | |
69 | 'season_number': int_or_none(season_number), | |
70 | 'episode_number': int_or_none(episode_number), | |
71 | 'thumbnails': [{'url': thumbnail_url} | |
72 | for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))] | |
73 | } |