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.

119 lines
4.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. float_or_none,
  9. int_or_none,
  10. try_get,
  11. unified_timestamp,
  12. OnDemandPagedList,
  13. )
  14. class ACastIE(InfoExtractor):
  15. IE_NAME = 'acast'
  16. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)'
  17. _TESTS = [{
  18. # test with one bling
  19. 'url': 'https://www.acast.com/condenasttraveler/-where-are-you-taipei-101-taiwan',
  20. 'md5': 'ada3de5a1e3a2a381327d749854788bb',
  21. 'info_dict': {
  22. 'id': '57de3baa-4bb0-487e-9418-2692c1277a34',
  23. 'ext': 'mp3',
  24. 'title': '"Where Are You?": Taipei 101, Taiwan',
  25. 'description': 'md5:a0b4ef3634e63866b542e5b1199a1a0e',
  26. 'timestamp': 1196172000,
  27. 'upload_date': '20071127',
  28. 'duration': 211,
  29. 'creator': 'Concierge',
  30. 'series': 'Condé Nast Traveler Podcast',
  31. 'episode': '"Where Are You?": Taipei 101, Taiwan',
  32. }
  33. }, {
  34. # test with multiple blings
  35. 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
  36. 'md5': 'a02393c74f3bdb1801c3ec2695577ce0',
  37. 'info_dict': {
  38. 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
  39. 'ext': 'mp3',
  40. 'title': '2. Raggarmordet - Röster ur det förflutna',
  41. 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4',
  42. 'timestamp': 1477346700,
  43. 'upload_date': '20161024',
  44. 'duration': 2766.602563,
  45. 'creator': 'Anton Berg & Martin Johnson',
  46. 'series': 'Spår',
  47. 'episode': '2. Raggarmordet - Röster ur det förflutna',
  48. }
  49. }]
  50. def _real_extract(self, url):
  51. channel, display_id = re.match(self._VALID_URL, url).groups()
  52. s = self._download_json(
  53. 'https://play-api.acast.com/stitch/%s/%s' % (channel, display_id),
  54. display_id)['result']
  55. media_url = s['url']
  56. cast_data = self._download_json(
  57. 'https://play-api.acast.com/splash/%s/%s' % (channel, display_id),
  58. display_id)['result']
  59. e = cast_data['episode']
  60. title = e['name']
  61. return {
  62. 'id': compat_str(e['id']),
  63. 'display_id': display_id,
  64. 'url': media_url,
  65. 'title': title,
  66. 'description': e.get('description') or e.get('summary'),
  67. 'thumbnail': e.get('image'),
  68. 'timestamp': unified_timestamp(e.get('publishingDate')),
  69. 'duration': float_or_none(s.get('duration') or e.get('duration')),
  70. 'filesize': int_or_none(e.get('contentLength')),
  71. 'creator': try_get(cast_data, lambda x: x['show']['author'], compat_str),
  72. 'series': try_get(cast_data, lambda x: x['show']['name'], compat_str),
  73. 'season_number': int_or_none(e.get('seasonNumber')),
  74. 'episode': title,
  75. 'episode_number': int_or_none(e.get('episodeNumber')),
  76. }
  77. class ACastChannelIE(InfoExtractor):
  78. IE_NAME = 'acast:channel'
  79. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)'
  80. _TEST = {
  81. 'url': 'https://www.acast.com/condenasttraveler',
  82. 'info_dict': {
  83. 'id': '50544219-29bb-499e-a083-6087f4cb7797',
  84. 'title': 'Condé Nast Traveler Podcast',
  85. 'description': 'md5:98646dee22a5b386626ae31866638fbd',
  86. },
  87. 'playlist_mincount': 20,
  88. }
  89. _API_BASE_URL = 'https://www.acast.com/api/'
  90. _PAGE_SIZE = 10
  91. @classmethod
  92. def suitable(cls, url):
  93. return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
  94. def _fetch_page(self, channel_slug, page):
  95. casts = self._download_json(
  96. self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
  97. channel_slug, note='Download page %d of channel data' % page)
  98. for cast in casts:
  99. yield self.url_result(
  100. 'https://www.acast.com/%s/%s' % (channel_slug, cast['url']),
  101. 'ACast', cast['id'])
  102. def _real_extract(self, url):
  103. channel_slug = self._match_id(url)
  104. channel_data = self._download_json(
  105. self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
  106. entries = OnDemandPagedList(functools.partial(
  107. self._fetch_page, channel_slug), self._PAGE_SIZE)
  108. return self.playlist_result(entries, compat_str(
  109. channel_data['id']), channel_data['name'], channel_data.get('description'))