dhm.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. xpath_text,
  5. parse_duration,
  6. )
  7. class DHMIE(InfoExtractor):
  8. IE_DESC = 'Filmarchiv - Deutsches Historisches Museum'
  9. _VALID_URL = r'http://www\.dhm\.de/filmarchiv/die-filme/(?P<id>[^/]+)'
  10. _TEST = {
  11. 'url': 'http://www.dhm.de/filmarchiv/die-filme/the-marshallplan-at-work-in-west-germany/',
  12. 'md5': '11c475f670209bf6acca0b2b7ef51827',
  13. 'info_dict': {
  14. 'id': 'the-marshallplan-at-work-in-west-germany',
  15. 'ext': 'flv',
  16. 'title': 'MARSHALL PLAN AT WORK IN WESTERN GERMANY, THE',
  17. 'description': 'md5:1fabd480c153f97b07add61c44407c82',
  18. 'duration': 660,
  19. 'thumbnail': 're:^https?://.*\.jpg$',
  20. }
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. playlist_url = self._search_regex(
  26. r"file\s*:\s*'([^']+)'", webpage, 'playlist url')
  27. playlist = self._download_xml(playlist_url, video_id)
  28. track = playlist.find(
  29. './{http://xspf.org/ns/0/}trackList/{http://xspf.org/ns/0/}track')
  30. video_url = xpath_text(
  31. track, './{http://xspf.org/ns/0/}location',
  32. 'video url', fatal=True)
  33. thumbnail = xpath_text(
  34. track, './{http://xspf.org/ns/0/}image',
  35. 'thumbnail')
  36. title = self._search_regex(
  37. [r'dc:title="([^"]+)"', r'<title> &raquo;([^<]+)</title>'],
  38. webpage, 'title').strip()
  39. description = self._html_search_regex(
  40. r'<p><strong>Description:</strong>(.+?)</p>',
  41. webpage, 'description', fatal=False)
  42. duration = parse_duration(self._search_regex(
  43. r'<em>Length\s*</em>\s*:\s*</strong>([^<]+)',
  44. webpage, 'duration', fatal=False))
  45. return {
  46. 'id': video_id,
  47. 'url': video_url,
  48. 'title': title,
  49. 'description': description,
  50. 'duration': duration,
  51. 'thumbnail': thumbnail,
  52. }