1 from .common
import InfoExtractor
2 from ..utils
import ExtractorError
, int_or_none
, traverse_obj
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+)'
8 'url': 'https://www.swearnet.com/shows/gettin-learnt-with-ricky/seasons/1/episodes/1',
13 'episode': 'Episode 1',
15 'description': 'md5:c48ef71440ce466284c07085cd7bd761',
17 'title': 'Episode 1 - Grilled Cheese Sammich',
19 'thumbnail': 'https://cdn.vidyard.com/thumbnails/232819/_RX04IKIq60a2V6rIRqq_Q_small.jpg',
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():
28 for video_hls
in value
:
29 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(video_hls
.get('url'), video_id
)
31 self
._merge
_subtitles
(subs
, target
=subtitles
)
34 'url': video_mp4
.get('url'),
36 } for video_mp4
in value
)
38 return formats
, subtitles
40 def _get_direct_subtitle(self
, caption_json
):
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')
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
)
55 external_id
= self
._search
_regex
(r
'externalid\s*=\s*"([^"]+)', webpage
, 'externalid')
56 except ExtractorError
:
57 if 'Upgrade Now' in webpage
:
58 self
.raise_login_required()
61 json_data
= self
._download
_json
(
62 f
'https://play.vidyard.com/player/{external_id}.json', display_id
)['payload']['chapters'][0]
64 formats
, subtitles
= self
._get
_formats
_and
_subtitle
(json_data
['sources'], display_id
)
65 self
._merge
_subtitles
(self
._get
_direct
_subtitle
(json_data
.get('captions')), target
=subtitles
)
68 'id': str(json_data
['videoId']),
69 'title': json_data
.get('name') or self
._html
_search
_meta
(['og:title', 'twitter:title'], webpage
),
70 'description': (json_data
.get('description')
71 or self
._html
_search
_meta
(['og:description', 'twitter:description'], webpage
)),
72 'duration': int_or_none(json_data
.get('seconds')),
74 'subtitles': subtitles
,
75 'season_number': int_or_none(season_number
),
76 'episode_number': int_or_none(episode_number
),
77 'thumbnails': [{'url': thumbnail_url
}
78 for thumbnail_url
in traverse_obj(json_data
, ('thumbnailUrls', ...))]