hollywoodreporter.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import functools
  2. import re
  3. from .common import InfoExtractor
  4. from .jwplatform import JWPlatformIE
  5. from ..utils import (
  6. ExtractorError,
  7. OnDemandPagedList,
  8. extract_attributes,
  9. get_element_by_class,
  10. get_element_html_by_class,
  11. )
  12. class HollywoodReporterIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?hollywoodreporter\.com/video/(?P<id>[\w-]+)'
  14. _TESTS = [{
  15. 'url': 'https://www.hollywoodreporter.com/video/chris-pine-michelle-rodriguez-dungeons-dragons-cast-directors-on-what-it-took-to-make-film-sxsw-2023/',
  16. 'info_dict': {
  17. 'id': 'zH4jZaR5',
  18. 'ext': 'mp4',
  19. 'title': 'md5:a9a1c073770a32f178955997712c4bd9',
  20. 'description': 'The cast and directors of \'Dungeons & Dragons: Honor Among Thieves\' talk about their new film.',
  21. 'thumbnail': 'https://cdn.jwplayer.com/v2/media/zH4jZaR5/poster.jpg?width=720',
  22. 'upload_date': '20230312',
  23. 'timestamp': 1678586423,
  24. 'duration': 242.0,
  25. },
  26. 'params': {'skip_download': 'm3u8'},
  27. }]
  28. def _real_extract(self, url):
  29. display_id = self._match_id(url)
  30. webpage = self._download_webpage(url, display_id)
  31. data = extract_attributes(get_element_html_by_class('vlanding-video-card__link', webpage) or '')
  32. video_id = data['data-video-showcase-trigger']
  33. showcase_type = data['data-video-showcase-type']
  34. if showcase_type == 'jwplayer':
  35. return self.url_result(f'jwplatform:{video_id}', JWPlatformIE)
  36. elif showcase_type == 'youtube':
  37. return self.url_result(video_id, 'Youtube')
  38. else:
  39. raise ExtractorError(f'Unsupported showcase type "{showcase_type}"')
  40. class HollywoodReporterPlaylistIE(InfoExtractor):
  41. _VALID_URL = r'https?://(?:www\.)?hollywoodreporter\.com/vcategory/(?P<slug>[\w-]+)-(?P<id>\d+)'
  42. _TESTS = [{
  43. 'url': 'https://www.hollywoodreporter.com/vcategory/heat-vision-breakdown-57822/',
  44. 'playlist_mincount': 109,
  45. 'info_dict': {
  46. 'id': '57822',
  47. 'title': 'heat-vision-breakdown',
  48. },
  49. }]
  50. def _fetch_page(self, slug, pl_id, page):
  51. page += 1
  52. webpage = self._download_webpage(
  53. f'https://www.hollywoodreporter.com/vcategory/{slug}-{pl_id}/page/{page}/',
  54. pl_id, note=f'Downloading playlist page {page}')
  55. section = get_element_by_class('video-playlist-river', webpage) or ''
  56. for url in re.findall(r'<a[^>]+href="([^"]+)"[^>]+class="c-title__link', section):
  57. yield self.url_result(url, HollywoodReporterIE)
  58. def _real_extract(self, url):
  59. slug, pl_id = self._match_valid_url(url).group('slug', 'id')
  60. return self.playlist_result(
  61. OnDemandPagedList(functools.partial(self._fetch_page, slug, pl_id), 15), pl_id, slug)