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.

66 lines
2.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import int_or_none
  7. class ACastBaseIE(InfoExtractor):
  8. _API_BASE_URL = 'https://www.acast.com/api/'
  9. class ACastIE(ACastBaseIE):
  10. IE_NAME = 'acast'
  11. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<channel>[^/]+)/(?P<id>[^/#?]+)'
  12. _TEST = {
  13. 'url': 'https://www.acast.com/gardenersquestiontime/liverpool',
  14. 'md5': '9e9cd59c3a8a7d8d5407605f51093050',
  15. 'info_dict': {
  16. 'id': '43da2262-ade7-420c-8564-f6367da7c010',
  17. 'ext': 'mp3',
  18. 'title': 'Liverpool',
  19. 'timestamp': 1446163200000,
  20. 'description': 'md5:170432c9956eec0670d7080a75000d5b',
  21. 'duration': 2520,
  22. }
  23. }
  24. def _real_extract(self, url):
  25. channel, display_id = re.match(self._VALID_URL, url).groups()
  26. cast_data = self._download_json(self._API_BASE_URL + 'channels/%s/acasts/%s/playback' % (channel, display_id), display_id)
  27. return {
  28. 'id': compat_str(cast_data['id']),
  29. 'display_id': display_id,
  30. 'url': cast_data['blings'][0]['audio'],
  31. 'title': cast_data['name'],
  32. 'description': cast_data.get('description'),
  33. 'thumbnail': cast_data.get('image'),
  34. 'timestamp': int_or_none(cast_data.get('publishingDate')),
  35. 'duration': int_or_none(cast_data.get('duration')),
  36. }
  37. class ACastChannelIE(ACastBaseIE):
  38. IE_NAME = 'acast:channel'
  39. _VALID_URL = r'https?://(?:www\.)?acast\.com/(?P<id>[^/#?]+)'
  40. _TEST = {
  41. 'url': 'https://www.acast.com/gardenersquestiontime',
  42. 'info_dict': {
  43. 'id': '9d8f6f73-6b9d-4d16-9399-52bf88f8f611',
  44. 'title': 'Gardeners\' Question Time',
  45. 'description': 'md5:c7ef18049da6a52b63d371b3edccce90',
  46. },
  47. 'playlist_mincount': 5,
  48. }
  49. def _real_extract(self, url):
  50. display_id = self._match_id(url)
  51. channel_data = self._download_json(self._API_BASE_URL + 'channels/%s' % display_id, display_id)
  52. casts = self._download_json(self._API_BASE_URL + 'channels/%s/acasts' % display_id, display_id)
  53. entries = [self.url_result('https://www.acast.com/%s/%s' % (display_id, cast['url']), 'ACast') for cast in casts]
  54. return self.playlist_result(entries, compat_str(channel_data['id']), channel_data['name'], channel_data.get('description'))