[ie/soundcloud] Various fixes (#11820)
[yt-dlp.git] / yt_dlp / extractor / swearnet.py
blob2d6fb3eb476099f8c3329c66e3868647cdec7ec4
1 from .vidyard import VidyardBaseIE
2 from ..utils import ExtractorError, int_or_none, make_archive_id
5 class SwearnetEpisodeIE(VidyardBaseIE):
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': 'wicK2EOzjOdxkUXGDIgcPw',
11 'display_id': '232819',
12 'ext': 'mp4',
13 'episode_number': 1,
14 'episode': 'Episode 1',
15 'duration': 719,
16 'description': r're:Are you drunk and high and craving a grilled cheese sandwich.+',
17 'season': 'Season 1',
18 'title': 'Episode 1 - Grilled Cheese Sammich',
19 'season_number': 1,
20 'thumbnail': 'https://cdn.vidyard.com/thumbnails/custom/0dd74f9b-388a-452e-b570-b407fb64435b_small.jpg',
21 'tags': ['Getting Learnt with Ricky', 'drunk', 'grilled cheese', 'high'],
22 '_old_archive_ids': ['swearnetepisode 232819'],
26 def _real_extract(self, url):
27 slug, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
28 webpage = self._download_webpage(url, slug)
30 try:
31 external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid')
32 except ExtractorError:
33 if 'Upgrade Now' in webpage:
34 self.raise_login_required()
35 raise
37 info = self._process_video_json(self._fetch_video_json(external_id)['chapters'][0], external_id)
38 if info.get('display_id'):
39 info['_old_archive_ids'] = [make_archive_id(self, info['display_id'])]
41 return {
42 **info,
43 'season_number': int_or_none(season_number),
44 'episode_number': int_or_none(episode_number),