logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

acast.py (4493B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. clean_podcast_url,
  8. int_or_none,
  9. parse_iso8601,
  10. )
  11. class ACastBaseIE(InfoExtractor):
  12. def _extract_episode(self, episode, show_info):
  13. title = episode['title']
  14. info = {
  15. 'id': episode['id'],
  16. 'display_id': episode.get('episodeUrl'),
  17. 'url': clean_podcast_url(episode['url']),
  18. 'title': title,
  19. 'description': clean_html(episode.get('description') or episode.get('summary')),
  20. 'thumbnail': episode.get('image'),
  21. 'timestamp': parse_iso8601(episode.get('publishDate')),
  22. 'duration': int_or_none(episode.get('duration')),
  23. 'filesize': int_or_none(episode.get('contentLength')),
  24. 'season_number': int_or_none(episode.get('season')),
  25. 'episode': title,
  26. 'episode_number': int_or_none(episode.get('episode')),
  27. }
  28. info.update(show_info)
  29. return info
  30. def _extract_show_info(self, show):
  31. return {
  32. 'creator': show.get('author'),
  33. 'series': show.get('title'),
  34. }
  35. def _call_api(self, path, video_id, query=None):
  36. return self._download_json(
  37. 'https://feeder.acast.com/api/v1/shows/' + path, video_id, query=query)
  38. class ACastIE(ACastBaseIE):
  39. IE_NAME = 'acast'
  40. _VALID_URL = r'''(?x)
  41. https?://
  42. (?:
  43. (?:(?:embed|www)\.)?acast\.com/|
  44. play\.acast\.com/s/
  45. )
  46. (?P<channel>[^/]+)/(?P<id>[^/#?]+)
  47. '''
  48. _TESTS = [{
  49. 'url': 'https://www.acast.com/sparpodcast/2.raggarmordet-rosterurdetforflutna',
  50. 'md5': 'f5598f3ad1e4776fed12ec1407153e4b',
  51. 'info_dict': {
  52. 'id': '2a92b283-1a75-4ad8-8396-499c641de0d9',
  53. 'ext': 'mp3',
  54. 'title': '2. Raggarmordet - Röster ur det förflutna',
  55. 'description': 'md5:a992ae67f4d98f1c0141598f7bebbf67',
  56. 'timestamp': 1477346700,
  57. 'upload_date': '20161024',
  58. 'duration': 2766,
  59. 'creator': 'Anton Berg & Martin Johnson',
  60. 'series': 'Spår',
  61. 'episode': '2. Raggarmordet - Röster ur det förflutna',
  62. }
  63. }, {
  64. 'url': 'http://embed.acast.com/adambuxton/ep.12-adam-joeschristmaspodcast2015',
  65. 'only_matching': True,
  66. }, {
  67. 'url': 'https://play.acast.com/s/rattegangspodden/s04e09styckmordetihelenelund-del2-2',
  68. 'only_matching': True,
  69. }, {
  70. 'url': 'https://play.acast.com/s/sparpodcast/2a92b283-1a75-4ad8-8396-499c641de0d9',
  71. 'only_matching': True,
  72. }]
  73. def _real_extract(self, url):
  74. channel, display_id = re.match(self._VALID_URL, url).groups()
  75. episode = self._call_api(
  76. '%s/episodes/%s' % (channel, display_id),
  77. display_id, {'showInfo': 'true'})
  78. return self._extract_episode(
  79. episode, self._extract_show_info(episode.get('show') or {}))
  80. class ACastChannelIE(ACastBaseIE):
  81. IE_NAME = 'acast:channel'
  82. _VALID_URL = r'''(?x)
  83. https?://
  84. (?:
  85. (?:www\.)?acast\.com/|
  86. play\.acast\.com/s/
  87. )
  88. (?P<id>[^/#?]+)
  89. '''
  90. _TESTS = [{
  91. 'url': 'https://www.acast.com/todayinfocus',
  92. 'info_dict': {
  93. 'id': '4efc5294-5385-4847-98bd-519799ce5786',
  94. 'title': 'Today in Focus',
  95. 'description': 'md5:c09ce28c91002ce4ffce71d6504abaae',
  96. },
  97. 'playlist_mincount': 200,
  98. }, {
  99. 'url': 'http://play.acast.com/s/ft-banking-weekly',
  100. 'only_matching': True,
  101. }]
  102. @classmethod
  103. def suitable(cls, url):
  104. return False if ACastIE.suitable(url) else super(ACastChannelIE, cls).suitable(url)
  105. def _real_extract(self, url):
  106. show_slug = self._match_id(url)
  107. show = self._call_api(show_slug, show_slug)
  108. show_info = self._extract_show_info(show)
  109. entries = []
  110. for episode in (show.get('episodes') or []):
  111. entries.append(self._extract_episode(episode, show_info))
  112. return self.playlist_result(
  113. entries, show.get('id'), show.get('title'), show.get('description'))