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.

135 lines
5.1 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. clean_html,
  9. float_or_none,
  10. int_or_none,
  11. try_get,
  12. unified_timestamp,
  13. OnDemandPagedList,
  14. )
  15. class ACastIE(InfoExtractor):
  16. IE_NAME = 'acast'
  17. _VALID_URL = r'''(?x)
  18. https?://
  19. (?:
  20. (?:(?:embed|www)\.)?acast\.com/|
  21. play\.acast\.com/s/
  22. )
  23. (?P<channel>[^/]+)/(?P<id>[^/#?]+)
  24. '''
  25. _TESTS = [{
  26. 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
  27. 'md5': '16d936099ec5ca2d5869e3a813ee8dc4',
  28. 'info_dict': {
  29. 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
  30. 'ext': 'mp3',
  31. 'title': '2. Raggarmordet - Röster ur det förflutna',
  32. 'description': 'md5:4f81f6d8cf2e12ee21a321d8bca32db4',
  33. 'timestamp': 1477346700,
  34. 'upload_date': '20161024',
  35. 'duration': 2766.602563,
  36. 'creator': 'Anton Berg & Martin Johnson',
  37. 'series': 'Spår',
  38. 'episode': '2. Raggarmordet - Röster ur det förflutna',
  39. }
  40. }, {
  41. 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015',
  42. 'only_matching': True,
  43. }, {
  44. 'url': 'https://play.acast.com/s/rattegangspodden/s04e09-styckmordet-i-helenelund-del-22',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'https://play.acast.com/s/sparpodcast/2a92b283-1a75-4ad8-8396-499c641de0d9',
  48. 'only_matching': True,
  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://feeder.acast.com/api/v1/shows/%s/episodes/%s' % (channel, display_id),
  54. display_id)
  55. media_url = s['url']
  56. if re.search(r'[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}', display_id):
  57. episode_url = s.get('episodeUrl')
  58. if episode_url:
  59. display_id = episode_url
  60. else:
  61. channel, display_id = re.match(self._VALID_URL, s['link']).groups()
  62. cast_data = self._download_json(
  63. 'https://play-api.acast.com/splash/%s/%s' % (channel, display_id),
  64. display_id)['result']
  65. e = cast_data['episode']
  66. title = e.get('name') or s['title']
  67. return {
  68. 'id': compat_str(e['id']),
  69. 'display_id': display_id,
  70. 'url': media_url,
  71. 'title': title,
  72. 'description': e.get('summary') or clean_html(e.get('description') or s.get('description')),
  73. 'thumbnail': e.get('image'),
  74. 'timestamp': unified_timestamp(e.get('publishingDate') or s.get('publishDate')),
  75. 'duration': float_or_none(e.get('duration') or s.get('duration')),
  76. 'filesize': int_or_none(e.get('contentLength')),
  77. 'creator': try_get(cast_data, lambda x: x['show']['author'], compat_str),
  78. 'series': try_get(cast_data, lambda x: x['show']['name'], compat_str),
  79. 'season_number': int_or_none(e.get('seasonNumber')),
  80. 'episode': title,
  81. 'episode_number': int_or_none(e.get('episodeNumber')),
  82. }
  83. class ACastChannelIE(InfoExtractor):
  84. IE_NAME = 'acast:channel'
  85. _VALID_URL = r'''(?x)
  86. https?://
  87. (?:
  88. (?:www\.)?acast\.com/|
  89. play\.acast\.com/s/
  90. )
  91. (?P<id>[^/#?]+)
  92. '''
  93. _TESTS = [{
  94. 'url': 'https://www.acast.com/todayinfocus',
  95. 'info_dict': {
  96. 'id': '4efc5294-5385-4847-98bd-519799ce5786',
  97. 'title': 'Today in Focus',
  98. 'description': 'md5:9ba5564de5ce897faeb12963f4537a64',
  99. },
  100. 'playlist_mincount': 35,
  101. }, {
  102. 'url': 'http://play.acast.com/s/ft-banking-weekly',
  103. 'only_matching': True,
  104. }]
  105. _API_BASE_URL = 'https://play.acast.com/api/'
  106. _PAGE_SIZE = 10
  107. @classmethod
  108. def suitable(cls, url):
  109. return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
  110. def _fetch_page(self, channel_slug, page):
  111. casts = self._download_json(
  112. self._API_BASE_URL + 'channels/%s/acasts?page=%s' % (channel_slug, page),
  113. channel_slug, note='Download page %d of channel data' % page)
  114. for cast in casts:
  115. yield self.url_result(
  116. 'https://play.acast.com/s/%s/%s' % (channel_slug, cast['url']),
  117. 'ACast', cast['id'])
  118. def _real_extract(self, url):
  119. channel_slug = self._match_id(url)
  120. channel_data = self._download_json(
  121. self._API_BASE_URL + 'channels/%s' % channel_slug, channel_slug)
  122. entries = OnDemandPagedList(functools.partial(
  123. self._fetch_page, channel_slug), self._PAGE_SIZE)
  124. return self.playlist_result(entries, compat_str(
  125. channel_data['id']), channel_data['name'], channel_data.get('description'))