logo

youtube-dl

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

googlepodcasts.py (3412B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. clean_podcast_url,
  8. int_or_none,
  9. try_get,
  10. urlencode_postdata,
  11. )
  12. class GooglePodcastsBaseIE(InfoExtractor):
  13. _VALID_URL_BASE = r'https?://podcasts\.google\.com/feed/'
  14. def _batch_execute(self, func_id, video_id, params):
  15. return json.loads(self._download_json(
  16. 'https://podcasts.google.com/_/PodcastsUi/data/batchexecute',
  17. video_id, data=urlencode_postdata({
  18. 'f.req': json.dumps([[[func_id, json.dumps(params), None, '1']]]),
  19. }), transform_source=lambda x: self._search_regex(r'(?s)(\[.+\])', x, 'data'))[0][2])
  20. def _extract_episode(self, episode):
  21. return {
  22. 'id': episode[4][3],
  23. 'title': episode[8],
  24. 'url': clean_podcast_url(episode[13]),
  25. 'thumbnail': episode[2],
  26. 'description': episode[9],
  27. 'creator': try_get(episode, lambda x: x[14]),
  28. 'timestamp': int_or_none(episode[11]),
  29. 'duration': int_or_none(episode[12]),
  30. 'series': episode[1],
  31. }
  32. class GooglePodcastsIE(GooglePodcastsBaseIE):
  33. IE_NAME = 'google:podcasts'
  34. _VALID_URL = GooglePodcastsBaseIE._VALID_URL_BASE + r'(?P<feed_url>[^/]+)/episode/(?P<id>[^/?&#]+)'
  35. _TEST = {
  36. 'url': 'https://podcasts.google.com/feed/aHR0cHM6Ly9mZWVkcy5ucHIub3JnLzM0NDA5ODUzOS9wb2RjYXN0LnhtbA/episode/MzBlNWRlN2UtOWE4Yy00ODcwLTk2M2MtM2JlMmUyNmViOTRh',
  37. 'md5': 'fa56b2ee8bd0703e27e42d4b104c4766',
  38. 'info_dict': {
  39. 'id': '30e5de7e-9a8c-4870-963c-3be2e26eb94a',
  40. 'ext': 'mp3',
  41. 'title': 'WWDTM New Year 2021',
  42. 'description': 'We say goodbye to 2020 with Christine Baranksi, Doug Jones, Jonna Mendez, and Kellee Edwards.',
  43. 'upload_date': '20210102',
  44. 'timestamp': 1609606800,
  45. 'duration': 2901,
  46. 'series': "Wait Wait... Don't Tell Me!",
  47. }
  48. }
  49. def _real_extract(self, url):
  50. b64_feed_url, b64_guid = re.match(self._VALID_URL, url).groups()
  51. episode = self._batch_execute(
  52. 'oNjqVe', b64_guid, [b64_feed_url, b64_guid])[1]
  53. return self._extract_episode(episode)
  54. class GooglePodcastsFeedIE(GooglePodcastsBaseIE):
  55. IE_NAME = 'google:podcasts:feed'
  56. _VALID_URL = GooglePodcastsBaseIE._VALID_URL_BASE + r'(?P<id>[^/?&#]+)/?(?:[?#&]|$)'
  57. _TEST = {
  58. 'url': 'https://podcasts.google.com/feed/aHR0cHM6Ly9mZWVkcy5ucHIub3JnLzM0NDA5ODUzOS9wb2RjYXN0LnhtbA',
  59. 'info_dict': {
  60. 'title': "Wait Wait... Don't Tell Me!",
  61. 'description': "NPR's weekly current events quiz. Have a laugh and test your news knowledge while figuring out what's real and what we've made up.",
  62. },
  63. 'playlist_mincount': 20,
  64. }
  65. def _real_extract(self, url):
  66. b64_feed_url = self._match_id(url)
  67. data = self._batch_execute('ncqJEe', b64_feed_url, [b64_feed_url])
  68. entries = []
  69. for episode in (try_get(data, lambda x: x[1][0]) or []):
  70. entries.append(self._extract_episode(episode))
  71. feed = try_get(data, lambda x: x[3]) or []
  72. return self.playlist_result(
  73. entries, playlist_title=try_get(feed, lambda x: x[0]),
  74. playlist_description=try_get(feed, lambda x: x[2]))