movingimage.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. parse_duration,
  4. unescapeHTML,
  5. )
  6. class MovingImageIE(InfoExtractor):
  7. _VALID_URL = r'https?://movingimage\.nls\.uk/film/(?P<id>\d+)'
  8. _TEST = {
  9. 'url': 'http://movingimage.nls.uk/film/3561',
  10. 'md5': '4caa05c2b38453e6f862197571a7be2f',
  11. 'info_dict': {
  12. 'id': '3561',
  13. 'ext': 'mp4',
  14. 'title': 'SHETLAND WOOL',
  15. 'description': 'md5:c5afca6871ad59b4271e7704fe50ab04',
  16. 'duration': 900,
  17. 'thumbnail': r're:^https?://.*\.jpg$',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(url, video_id)
  23. formats = self._extract_m3u8_formats(
  24. self._html_search_regex(r'file\s*:\s*"([^"]+)"', webpage, 'm3u8 manifest URL'),
  25. video_id, ext='mp4', entry_protocol='m3u8_native')
  26. def search_field(field_name, fatal=False):
  27. return self._search_regex(
  28. rf'<span\s+class="field_title">{field_name}:</span>\s*<span\s+class="field_content">([^<]+)</span>',
  29. webpage, 'title', fatal=fatal)
  30. title = unescapeHTML(search_field('Title', fatal=True)).strip('()[]')
  31. description = unescapeHTML(search_field('Description'))
  32. duration = parse_duration(search_field('Running time'))
  33. thumbnail = self._search_regex(
  34. r"image\s*:\s*'([^']+)'", webpage, 'thumbnail', fatal=False)
  35. return {
  36. 'id': video_id,
  37. 'formats': formats,
  38. 'title': title,
  39. 'description': description,
  40. 'duration': duration,
  41. 'thumbnail': thumbnail,
  42. }