]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/megaphone.py
0c150ef45c377dab2c68413c6861565649c5bef1
[yt-dlp.git] / yt_dlp / extractor / megaphone.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import js_to_json
5
6
7 class MegaphoneIE(InfoExtractor):
8 IE_NAME = 'megaphone.fm'
9 IE_DESC = 'megaphone.fm embedded players'
10 _VALID_URL = r'https://player\.megaphone\.fm/(?P<id>[A-Z0-9]+)'
11 _TEST = {
12 'url': 'https://player.megaphone.fm/GLT9749789991?"',
13 'md5': '4816a0de523eb3e972dc0dda2c191f96',
14 'info_dict': {
15 'id': 'GLT9749789991',
16 'ext': 'mp3',
17 'title': '#97 What Kind Of Idiot Gets Phished?',
18 'thumbnail': r're:^https://.*\.png.*$',
19 'duration': 1776.26375,
20 'author': 'Reply All',
21 },
22 }
23
24 def _real_extract(self, url):
25 video_id = self._match_id(url)
26 webpage = self._download_webpage(url, video_id)
27
28 title = self._og_search_property('audio:title', webpage)
29 author = self._og_search_property('audio:artist', webpage)
30 thumbnail = self._og_search_thumbnail(webpage)
31
32 episode_json = self._search_regex(r'(?s)var\s+episode\s*=\s*(\{.+?\});', webpage, 'episode JSON')
33 episode_data = self._parse_json(episode_json, video_id, js_to_json)
34 video_url = self._proto_relative_url(episode_data['mediaUrl'], 'https:')
35
36 formats = [{
37 'url': video_url,
38 }]
39
40 return {
41 'id': video_id,
42 'thumbnail': thumbnail,
43 'title': title,
44 'author': author,
45 'duration': episode_data['duration'],
46 'formats': formats,
47 }
48
49 @classmethod
50 def _extract_urls(cls, webpage):
51 return [m[0] for m in re.findall(
52 r'<iframe[^>]*?\ssrc=["\'](%s)' % cls._VALID_URL, webpage)]