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.

98 lines
3.6 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. parse_iso8601,
  10. OnDemandPagedList,
  11. )
  12. class ACastIE(InfoExtractor):
  13. IE_NAME = 'acast'
  14. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)'
  15. _TESTS = [{
  16. # test with one bling
  17. 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan',
  18. 'md5': 'ada3de5a1e3a2a381327d749854788bb',
  19. 'info_dict': {
  20. 'id': '57de3baa-4bb0-487e-9418-2692c1277a34',
  21. 'ext': 'mp3',
  22. 'title': '"Where Are You?": Taipei 101, Taiwan',
  23. 'timestamp': 1196172000,
  24. 'upload_date': '20071127',
  25. 'description': 'md5:a0b4ef3634e63866b542e5b1199a1a0e',
  26. 'duration': 211,
  27. }
  28. }, {
  29. # test with multiple blings
  30. 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
  31. 'md5': '55c0097badd7095f494c99a172f86501',
  32. 'info_dict': {
  33. 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
  34. 'ext': 'mp3',
  35. 'title': '2. Raggarmordet - Röster ur det förflutna',
  36. 'timestamp': 1477346700,
  37. 'upload_date': '20161024',
  38. 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4',
  39. 'duration': 2797,
  40. }
  41. }]
  42. def _real_extract(self, url):
  43. channel, display_id = re.match(self._VALID_URL, url).groups()
  44. cast_data = self._download_json(
  45. 'https://embed.acast.com/api/acasts/%s/%s' % (channel, display_id), display_id)
  46. return {
  47. 'id': compat_str(cast_data['id']),
  48. 'display_id': display_id,
  49. 'url': [b['audio'] for b in cast_data['blings'] if b['type'] == 'BlingAudio'][0],
  50. 'title': cast_data['name'],
  51. 'description': cast_data.get('description'),
  52. 'thumbnail': cast_data.get('image'),
  53. 'timestamp': parse_iso8601(cast_data.get('publishingDate')),
  54. 'duration': int_or_none(cast_data.get('duration')),
  55. }
  56. class ACastChannelIE(InfoExtractor):
  57. IE_NAME = 'acast:channel'
  58. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)'
  59. _TEST = {
  60. 'url': 'https://www.acast.com/condenasttraveler',
  61. 'info_dict': {
  62. 'id': '50544219-29bb-499e-a083-6087f4cb7797',
  63. 'title': 'Condé Nast Traveler Podcast',
  64. 'description': 'md5:98646dee22a5b386626ae31866638fbd',
  65. },
  66. 'playlist_mincount': 20,
  67. }
  68. _API_BASE_URL = 'https://www.acast.com/api/'
  69. _PAGE_SIZE = 10
  70. @classmethod
  71. def suitable(cls, url):
  72. return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
  73. def _fetch_page(self, channel_slug, page):
  74. casts = self._download_json(
  75. self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
  76. channel_slug, note='Download page %d of channel data' % page)
  77. for cast in casts:
  78. yield self.url_result(
  79. 'https://www.acast.com/%s/%s' % (channel_slug, cast['url']),
  80. 'ACast', cast['id'])
  81. def _real_extract(self, url):
  82. channel_slug = self._match_id(url)
  83. channel_data = self._download_json(
  84. self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
  85. entries = OnDemandPagedList(functools.partial(
  86. self._fetch_page, channel_slug), self._PAGE_SIZE)
  87. return self.playlist_result(entries, compat_str(
  88. channel_data['id']), channel_data['name'], channel_data.get('description'))