You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

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