nfb.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none
  3. class NFBIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?nfb\.ca/film/(?P<id>[^/?#&]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.nfb.ca/film/trafficopter/',
  7. 'info_dict': {
  8. 'id': 'trafficopter',
  9. 'ext': 'mp4',
  10. 'title': 'Trafficopter',
  11. 'description': 'md5:060228455eb85cf88785c41656776bc0',
  12. 'thumbnail': r're:^https?://.*\.jpg$',
  13. 'uploader': 'Barrie Howells',
  14. 'release_year': 1972,
  15. },
  16. }]
  17. def _real_extract(self, url):
  18. video_id = self._match_id(url)
  19. webpage = self._download_webpage('https://www.nfb.ca/film/%s/' % video_id, video_id)
  20. iframe = self._html_search_regex(
  21. r'<[^>]+\bid=["\']player-iframe["\'][^>]*src=["\']([^"\']+)',
  22. webpage, 'iframe', default=None, fatal=True)
  23. if iframe.startswith('/'):
  24. iframe = f'https://www.nfb.ca{iframe}'
  25. player = self._download_webpage(iframe, video_id)
  26. source = self._html_search_regex(
  27. r'source:\s*\'([^\']+)',
  28. player, 'source', default=None, fatal=True)
  29. formats, subtitles = self._extract_m3u8_formats_and_subtitles(source, video_id, ext='mp4')
  30. return {
  31. 'id': video_id,
  32. 'title': self._html_search_regex(
  33. r'<[^>]+\bid=["\']titleHeader["\'][^>]*>\s*<h1[^>]*>\s*([^<]+?)\s*</h1>',
  34. webpage, 'title', default=None),
  35. 'description': self._html_search_regex(
  36. r'<[^>]+\bid=["\']tabSynopsis["\'][^>]*>\s*<p[^>]*>\s*([^<]+)',
  37. webpage, 'description', default=None),
  38. 'thumbnail': self._html_search_regex(
  39. r'poster:\s*\'([^\']+)',
  40. player, 'thumbnail', default=None),
  41. 'uploader': self._html_search_regex(
  42. r'<[^>]+\bitemprop=["\']name["\'][^>]*>([^<]+)',
  43. webpage, 'uploader', default=None),
  44. 'release_year': int_or_none(self._html_search_regex(
  45. r'<[^>]+\bitemprop=["\']datePublished["\'][^>]*>([^<]+)',
  46. webpage, 'release_year', default=None)),
  47. 'formats': formats,
  48. 'subtitles': subtitles,
  49. }