rinsefm.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. MEDIA_EXTENSIONS,
  4. determine_ext,
  5. parse_iso8601,
  6. traverse_obj,
  7. url_or_none,
  8. )
  9. class RinseFMBaseIE(InfoExtractor):
  10. @staticmethod
  11. def _parse_entry(entry):
  12. return {
  13. **traverse_obj(entry, {
  14. 'id': ('id', {str}),
  15. 'title': ('title', {str}),
  16. 'url': ('fileUrl', {url_or_none}),
  17. 'release_timestamp': ('episodeDate', {parse_iso8601}),
  18. 'thumbnail': ('featuredImage', 0, 'filename', {str},
  19. {lambda x: x and f'https://rinse.imgix.net/media/{x}'}),
  20. 'webpage_url': ('slug', {str},
  21. {lambda x: x and f'https://rinse.fm/episodes/{x}'}),
  22. }),
  23. 'vcodec': 'none',
  24. 'extractor_key': RinseFMIE.ie_key(),
  25. 'extractor': RinseFMIE.IE_NAME,
  26. }
  27. class RinseFMIE(RinseFMBaseIE):
  28. _VALID_URL = r'https?://(?:www\.)?rinse\.fm/episodes/(?P<id>[^/?#]+)'
  29. _TESTS = [{
  30. 'url': 'https://rinse.fm/episodes/club-glow-15-12-2023-2000/',
  31. 'md5': '76ee0b719315617df42e15e710f46c7b',
  32. 'info_dict': {
  33. 'id': '1536535',
  34. 'ext': 'mp3',
  35. 'title': 'Club Glow - 15/12/2023 - 20:00',
  36. 'thumbnail': r're:^https://.+\.(?:jpg|JPG)$',
  37. 'release_timestamp': 1702598400,
  38. 'release_date': '20231215',
  39. },
  40. }]
  41. def _real_extract(self, url):
  42. display_id = self._match_id(url)
  43. webpage = self._download_webpage(url, display_id)
  44. entry = self._search_nextjs_data(webpage, display_id)['props']['pageProps']['entry']
  45. return self._parse_entry(entry)
  46. class RinseFMArtistPlaylistIE(RinseFMBaseIE):
  47. _VALID_URL = r'https?://(?:www\.)?rinse\.fm/shows/(?P<id>[^/?#]+)'
  48. _TESTS = [{
  49. 'url': 'https://rinse.fm/shows/resources/',
  50. 'info_dict': {
  51. 'id': 'resources',
  52. 'title': '[re]sources',
  53. 'description': '[re]sources est un label parisien piloté par le DJ et producteur Tommy Kid.',
  54. },
  55. 'playlist_mincount': 40,
  56. }, {
  57. 'url': 'https://rinse.fm/shows/ivy/',
  58. 'info_dict': {
  59. 'id': 'ivy',
  60. 'title': '[IVY]',
  61. 'description': 'A dedicated space for DNB/Turbo House and 4x4.',
  62. },
  63. 'playlist_mincount': 7,
  64. }]
  65. def _entries(self, data):
  66. for episode in traverse_obj(data, (
  67. 'props', 'pageProps', 'episodes', lambda _, v: determine_ext(v['fileUrl']) in MEDIA_EXTENSIONS.audio),
  68. ):
  69. yield self._parse_entry(episode)
  70. def _real_extract(self, url):
  71. playlist_id = self._match_id(url)
  72. webpage = self._download_webpage(url, playlist_id)
  73. title = self._og_search_title(webpage) or self._html_search_meta('title', webpage)
  74. description = self._og_search_description(webpage) or self._html_search_meta(
  75. 'description', webpage)
  76. data = self._search_nextjs_data(webpage, playlist_id)
  77. return self.playlist_result(
  78. self._entries(data), playlist_id, title, description=description)