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.

82 lines
3.0 KiB

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