camfm.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. clean_html,
  5. get_element_by_class,
  6. get_elements_by_class,
  7. join_nonempty,
  8. traverse_obj,
  9. unified_timestamp,
  10. urljoin,
  11. )
  12. class CamFMShowIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?camfm\.co\.uk/shows/(?P<id>[^/]+)'
  14. _TESTS = [{
  15. 'playlist_mincount': 5,
  16. 'url': 'https://camfm.co.uk/shows/soul-mining/',
  17. 'info_dict': {
  18. 'id': 'soul-mining',
  19. 'thumbnail': 'md5:6a873091f92c936f23bdcce80f75e66a',
  20. 'title': 'Soul Mining',
  21. 'description': 'Telling the stories of jazz, funk and soul from all corners of the world.',
  22. },
  23. }]
  24. def _real_extract(self, url):
  25. show_id = self._match_id(url)
  26. page = self._download_webpage(url, show_id)
  27. return {
  28. '_type': 'playlist',
  29. 'id': show_id,
  30. 'entries': [self.url_result(urljoin('https://camfm.co.uk', i), CamFMEpisodeIE)
  31. for i in re.findall(r"javascript:popup\('(/player/[^']+)', 'listen'", page)],
  32. 'thumbnail': urljoin('https://camfm.co.uk', self._search_regex(
  33. r'<img[^>]+class="thumb-expand"[^>]+src="([^"]+)"', page, 'thumbnail', fatal=False)),
  34. 'title': self._html_search_regex('<h1>([^<]+)</h1>', page, 'title', fatal=False),
  35. 'description': clean_html(get_element_by_class('small-12 medium-8 cell', page)),
  36. }
  37. class CamFMEpisodeIE(InfoExtractor):
  38. _VALID_URL = r'https?://(?:www\.)?camfm\.co\.uk/player/(?P<id>[^/]+)'
  39. _TESTS = [{
  40. 'url': 'https://camfm.co.uk/player/43336',
  41. 'skip': 'Episode will expire - don\'t actually know when, but it will go eventually',
  42. 'info_dict': {
  43. 'id': '43336',
  44. 'title': 'AITAA: Am I the Agony Aunt? - 19:00 Tue 16/05/2023',
  45. 'ext': 'mp3',
  46. 'upload_date': '20230516',
  47. 'description': 'md5:f165144f94927c0f1bfa2ee6e6ab7bbf',
  48. 'timestamp': 1684263600,
  49. 'series': 'AITAA: Am I the Agony Aunt?',
  50. 'thumbnail': 'md5:5980a831360d0744c3764551be3d09c1',
  51. 'categories': ['Entertainment'],
  52. },
  53. }]
  54. def _real_extract(self, url):
  55. episode_id = self._match_id(url)
  56. page = self._download_webpage(url, episode_id)
  57. audios = self._parse_html5_media_entries('https://audio.camfm.co.uk', page, episode_id)
  58. caption = get_element_by_class('caption', page)
  59. series = clean_html(re.sub(r'<span[^<]+<[^<]+>', '', caption))
  60. card_section = get_element_by_class('card-section', page)
  61. date = self._html_search_regex('>Aired at ([^<]+)<', card_section, 'air date', fatal=False)
  62. return {
  63. 'id': episode_id,
  64. 'title': join_nonempty(series, date, delim=' - '),
  65. 'formats': traverse_obj(audios, (..., 'formats', ...)),
  66. 'timestamp': unified_timestamp(date), # XXX: Does not account for UK's daylight savings
  67. 'series': series,
  68. 'description': clean_html(re.sub(r'<b>[^<]+</b><br[^>]+/>', '', card_section)),
  69. 'thumbnail': urljoin('https://camfm.co.uk', self._search_regex(
  70. r'<div[^>]+class="cover-art"[^>]+style="[^"]+url\(\'([^\']+)',
  71. page, 'thumbnail', fatal=False)),
  72. 'categories': get_elements_by_class('label', caption),
  73. 'was_live': True,
  74. }