]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | clean_html, | |
4 | float_or_none, | |
5 | int_or_none, | |
6 | str_or_none, | |
7 | traverse_obj, | |
8 | unified_timestamp, | |
9 | ) | |
10 | ||
11 | ||
12 | class AnchorFMEpisodeIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://anchor\.fm/(?P<channel_name>\w+)/(?:embed/)?episodes/[\w-]+-(?P<episode_id>\w+)' | |
14 | _EMBED_REGEX = [rf'<iframe[^>]+\bsrc=[\'"](?P<url>{_VALID_URL})'] | |
15 | _TESTS = [{ | |
16 | 'url': 'https://anchor.fm/lovelyti/episodes/Chrisean-Rock-takes-to-twitter-to-announce-shes-pregnant--Blueface-denies-he-is-the-father-e1tpt3d', | |
17 | 'info_dict': { | |
18 | 'id': 'e1tpt3d', | |
19 | 'ext': 'mp3', | |
20 | 'title': ' Chrisean Rock takes to twitter to announce she\'s pregnant, Blueface denies he is the father!', | |
21 | 'description': 'md5:207d167de3e28ceb4ddc1ebf5a30044c', | |
22 | 'thumbnail': 'https://s3-us-west-2.amazonaws.com/anchor-generated-image-bank/production/podcast_uploaded_nologo/1034827/1034827-1658438968460-5f3bfdf3601e8.jpg', | |
23 | 'duration': 624.718, | |
24 | 'uploader': 'Lovelyti ', | |
25 | 'uploader_id': '991541', | |
26 | 'channel': 'lovelyti', | |
27 | 'modified_date': '20230121', | |
28 | 'modified_timestamp': 1674285178, | |
29 | 'release_date': '20230121', | |
30 | 'release_timestamp': 1674285179, | |
31 | 'episode_id': 'e1tpt3d', | |
32 | }, | |
33 | }, { | |
34 | # embed url | |
35 | 'url': 'https://anchor.fm/apakatatempo/embed/episodes/S2E75-Perang-Bintang-di-Balik-Kasus-Ferdy-Sambo-dan-Ismail-Bolong-e1shjqd', | |
36 | 'info_dict': { | |
37 | 'id': 'e1shjqd', | |
38 | 'ext': 'mp3', | |
39 | 'title': 'S2E75 Perang Bintang di Balik Kasus Ferdy Sambo dan Ismail Bolong', | |
40 | 'description': 'md5:9e95ad9293bf00178bf8d33e9cb92c41', | |
41 | 'duration': 1042.008, | |
42 | 'thumbnail': 'https://s3-us-west-2.amazonaws.com/anchor-generated-image-bank/production/podcast_uploaded_episode400/2627805/2627805-1671590688729-4db3882ac9e4b.jpg', | |
43 | 'release_date': '20221221', | |
44 | 'release_timestamp': 1671595916, | |
45 | 'modified_date': '20221221', | |
46 | 'modified_timestamp': 1671590834, | |
47 | 'channel': 'apakatatempo', | |
48 | 'uploader': 'Podcast Tempo', | |
49 | 'uploader_id': '2585461', | |
50 | 'season': 'Season 2', | |
51 | 'season_number': 2, | |
52 | 'episode_id': 'e1shjqd', | |
53 | }, | |
54 | }] | |
55 | ||
56 | _WEBPAGE_TESTS = [{ | |
57 | 'url': 'https://podcast.tempo.co/podcast/192/perang-bintang-di-balik-kasus-ferdy-sambo-dan-ismail-bolong', | |
58 | 'info_dict': { | |
59 | 'id': 'e1shjqd', | |
60 | 'ext': 'mp3', | |
61 | 'release_date': '20221221', | |
62 | 'duration': 1042.008, | |
63 | 'season': 'Season 2', | |
64 | 'modified_timestamp': 1671590834, | |
65 | 'uploader_id': '2585461', | |
66 | 'modified_date': '20221221', | |
67 | 'description': 'md5:9e95ad9293bf00178bf8d33e9cb92c41', | |
68 | 'season_number': 2, | |
69 | 'title': 'S2E75 Perang Bintang di Balik Kasus Ferdy Sambo dan Ismail Bolong', | |
70 | 'release_timestamp': 1671595916, | |
71 | 'episode_id': 'e1shjqd', | |
72 | 'thumbnail': 'https://s3-us-west-2.amazonaws.com/anchor-generated-image-bank/production/podcast_uploaded_episode400/2627805/2627805-1671590688729-4db3882ac9e4b.jpg', | |
73 | 'uploader': 'Podcast Tempo', | |
74 | 'channel': 'apakatatempo', | |
75 | }, | |
76 | }] | |
77 | ||
78 | def _real_extract(self, url): | |
79 | channel_name, episode_id = self._match_valid_url(url).group('channel_name', 'episode_id') | |
80 | api_data = self._download_json(f'https://anchor.fm/api/v3/episodes/{episode_id}', episode_id) | |
81 | ||
82 | return { | |
83 | 'id': episode_id, | |
84 | 'title': traverse_obj(api_data, ('episode', 'title')), | |
85 | 'url': traverse_obj(api_data, ('episode', 'episodeEnclosureUrl'), ('episodeAudios', 0, 'url')), | |
86 | 'ext': 'mp3', | |
87 | 'vcodec': 'none', | |
88 | 'thumbnail': traverse_obj(api_data, ('episode', 'episodeImage')), | |
89 | 'description': clean_html(traverse_obj(api_data, ('episode', ('description', 'descriptionPreview')), get_all=False)), | |
90 | 'duration': float_or_none(traverse_obj(api_data, ('episode', 'duration')), 1000), | |
91 | 'modified_timestamp': unified_timestamp(traverse_obj(api_data, ('episode', 'modified'))), | |
92 | 'release_timestamp': int_or_none(traverse_obj(api_data, ('episode', 'publishOnUnixTimestamp'))), | |
93 | 'episode_id': episode_id, | |
94 | 'uploader': traverse_obj(api_data, ('creator', 'name')), | |
95 | 'uploader_id': str_or_none(traverse_obj(api_data, ('creator', 'userId'))), | |
96 | 'season_number': int_or_none(traverse_obj(api_data, ('episode', 'podcastSeasonNumber'))), | |
97 | 'channel': channel_name or traverse_obj(api_data, ('creator', 'vanitySlug')), | |
98 | } |