rbmaradio.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. clean_html,
  5. int_or_none,
  6. unified_timestamp,
  7. update_url_query,
  8. )
  9. class RBMARadioIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?(?:rbmaradio|redbullradio)\.com/shows/(?P<show_id>[^/]+)/episodes/(?P<id>[^/?#&]+)'
  11. _TEST = {
  12. 'url': 'https://www.rbmaradio.com/shows/main-stage/episodes/ford-lopatin-live-at-primavera-sound-2011',
  13. 'md5': '6bc6f9bcb18994b4c983bc3bf4384d95',
  14. 'info_dict': {
  15. 'id': 'ford-lopatin-live-at-primavera-sound-2011',
  16. 'ext': 'mp3',
  17. 'title': 'Main Stage - Ford & Lopatin at Primavera Sound',
  18. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  19. 'thumbnail': r're:^https?://.*\.jpg',
  20. 'duration': 2452,
  21. 'timestamp': 1307103164,
  22. 'upload_date': '20110603',
  23. },
  24. }
  25. def _real_extract(self, url):
  26. mobj = self._match_valid_url(url)
  27. show_id = mobj.group('show_id')
  28. episode_id = mobj.group('id')
  29. webpage = self._download_webpage(url, episode_id)
  30. episode = self._parse_json(
  31. self._search_regex(
  32. r'__INITIAL_STATE__\s*=\s*({.+?})\s*</script>',
  33. webpage, 'json data'),
  34. episode_id)['episodes'][show_id][episode_id]
  35. title = episode['title']
  36. show_title = episode.get('showTitle')
  37. if show_title:
  38. title = '%s - %s' % (show_title, title)
  39. formats = [{
  40. 'url': update_url_query(episode['audioURL'], query={'cbr': abr}),
  41. 'format_id': compat_str(abr),
  42. 'abr': abr,
  43. 'vcodec': 'none',
  44. } for abr in (96, 128, 192, 256)]
  45. self._check_formats(formats, episode_id)
  46. description = clean_html(episode.get('longTeaser'))
  47. thumbnail = self._proto_relative_url(episode.get('imageURL', {}).get('landscape'))
  48. duration = int_or_none(episode.get('duration'))
  49. timestamp = unified_timestamp(episode.get('publishedAt'))
  50. return {
  51. 'id': episode_id,
  52. 'title': title,
  53. 'description': description,
  54. 'thumbnail': thumbnail,
  55. 'duration': duration,
  56. 'timestamp': timestamp,
  57. 'formats': formats,
  58. }