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.

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