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.

70 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import int_or_none
  7. class ACastBaseIE(InfoExtractor):
  8. _API_BASE_URL = 'https://www.acast.com/api/'
  9. class ACastIE(ACastBaseIE):
  10. IE_NAME = 'acast'
  11. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)'
  12. _TEST = {
  13. 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan',
  14. 'md5': 'ada3de5a1e3a2a381327d749854788bb',
  15. 'info_dict': {
  16. 'id': '57de3baa-4bb0-487e-9418-2692c1277a34',
  17. 'ext': 'mp3',
  18. 'title': '"Where Are You?": Taipei 101, Taiwan',
  19. 'timestamp': 1196172000000,
  20. 'description': 'md5:0c5d8201dfea2b93218ea986c91eee6e',
  21. 'duration': 211,
  22. }
  23. }
  24. def _real_extract(self, url):
  25. channel, display_id = re.match(self._VALID_URL, url).groups()
  26. cast_data = self._download_json(self._API_BASE_URL + 'channels/%s/acasts/%s/playback' % (channel, display_id), display_id)
  27. return {
  28. 'id': compat_str(cast_data['id']),
  29. 'display_id': display_id,
  30. 'url': cast_data['blings'][0]['audio'],
  31. 'title': cast_data['name'],
  32. 'description': cast_data.get('description'),
  33. 'thumbnail': cast_data.get('image'),
  34. 'timestamp': int_or_none(cast_data.get('publishingDate')),
  35. 'duration': int_or_none(cast_data.get('duration')),
  36. }
  37. class ACastChannelIE(ACastBaseIE):
  38. IE_NAME = 'acast:channel'
  39. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)'
  40. _TEST = {
  41. 'url': 'https://www.acast.com/condenasttraveler',
  42. 'info_dict': {
  43. 'id': '50544219-29bb-499e-a083-6087f4cb7797',
  44. 'title': 'Condé Nast Traveler Podcast',
  45. 'description': 'md5:98646dee22a5b386626ae31866638fbd',
  46. },
  47. 'playlist_mincount': 20,
  48. }
  49. @classmethod
  50. def suitable(cls, url):
  51. return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
  52. def _real_extract(self, url):
  53. display_id = self._match_id(url)
  54. channel_data = self._download_json(self._API_BASE_URL + 'channels/%s' % display_id, display_id)
  55. casts = self._download_json(self._API_BASE_URL + 'channels/%s/acasts' % display_id, display_id)
  56. entries = [self.url_result('https://www.acast.com/%s/%s' % (display_id, cast['url']), 'ACast') for cast in casts]
  57. return self.playlist_result(entries, compat_str(channel_data['id']), channel_data['name'], channel_data.get('description'))