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.

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