logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

applepodcasts.py (3261B)


  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_podcast_url,
  4. int_or_none,
  5. parse_iso8601,
  6. )
  7. from ..utils.traversal import traverse_obj
  8. class ApplePodcastsIE(InfoExtractor):
  9. _VALID_URL = r'https?://podcasts\.apple\.com/(?:[^/]+/)?podcast(?:/[^/]+){1,2}.*?\bi=(?P<id>\d+)'
  10. _TESTS = [{
  11. 'url': 'https://podcasts.apple.com/us/podcast/ferreck-dawn-to-the-break-of-dawn-117/id1625658232?i=1000665010654',
  12. 'md5': '82cc219b8cc1dcf8bfc5a5e99b23b172',
  13. 'info_dict': {
  14. 'id': '1000665010654',
  15. 'ext': 'mp3',
  16. 'title': 'Ferreck Dawn - To The Break of Dawn 117',
  17. 'episode': 'Ferreck Dawn - To The Break of Dawn 117',
  18. 'description': 'md5:1fc571102f79dbd0a77bfd71ffda23bc',
  19. 'upload_date': '20240812',
  20. 'timestamp': 1723449600,
  21. 'duration': 3596,
  22. 'series': 'Ferreck Dawn - To The Break of Dawn',
  23. 'thumbnail': 're:.+[.](png|jpe?g|webp)',
  24. },
  25. }, {
  26. 'url': 'https://podcasts.apple.com/us/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
  27. 'md5': 'baf8a6b8b8aa6062dbb4639ed73d0052',
  28. 'info_dict': {
  29. 'id': '1000482637777',
  30. 'ext': 'mp3',
  31. 'title': '207 - Whitney Webb Returns',
  32. 'episode': '207 - Whitney Webb Returns',
  33. 'episode_number': 207,
  34. 'description': 'md5:75ef4316031df7b41ced4e7b987f79c6',
  35. 'upload_date': '20200705',
  36. 'timestamp': 1593932400,
  37. 'duration': 5369,
  38. 'series': 'The Tim Dillon Show',
  39. 'thumbnail': 're:.+[.](png|jpe?g|webp)',
  40. },
  41. }, {
  42. 'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns/id1135137367?i=1000482637777',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'https://podcasts.apple.com/podcast/207-whitney-webb-returns?i=1000482637777',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'https://podcasts.apple.com/podcast/id1135137367?i=1000482637777',
  49. 'only_matching': True,
  50. }]
  51. def _real_extract(self, url):
  52. episode_id = self._match_id(url)
  53. webpage = self._download_webpage(url, episode_id)
  54. server_data = self._search_json(
  55. r'<script [^>]*\bid=["\']serialized-server-data["\'][^>]*>', webpage,
  56. 'server data', episode_id, contains_pattern=r'\[{(?s:.+)}\]')[0]['data']
  57. model_data = traverse_obj(server_data, (
  58. 'headerButtonItems', lambda _, v: v['$kind'] == 'bookmark' and v['modelType'] == 'EpisodeOffer',
  59. 'model', {dict}, any))
  60. return {
  61. 'id': episode_id,
  62. **self._json_ld(
  63. traverse_obj(server_data, ('seoData', 'schemaContent', {dict}))
  64. or self._yield_json_ld(webpage, episode_id, fatal=False), episode_id, fatal=False),
  65. **traverse_obj(model_data, {
  66. 'title': ('title', {str}),
  67. 'url': ('streamUrl', {clean_podcast_url}),
  68. 'timestamp': ('releaseDate', {parse_iso8601}),
  69. 'duration': ('duration', {int_or_none}),
  70. }),
  71. 'thumbnail': self._og_search_thumbnail(webpage),
  72. 'vcodec': 'none',
  73. }