dhm.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. import urllib2
  5. import xml.etree.ElementTree as ET
  6. import re
  7. class DHMIE(InfoExtractor):
  8. IE_DESC = 'Deutsches Historisches Museum'
  9. _VALID_URL = r'http://www\.dhm\.de/filmarchiv/(?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': 'marshallwg',
  15. 'ext': 'flv',
  16. 'title': 'MARSHALL PLAN AT WORK IN WESTERN GERMANY, THE',
  17. 'thumbnail': 'http://www.dhm.de/filmarchiv/video/mpworkwg.jpg',
  18. }
  19. }
  20. def _real_extract(self, url):
  21. video_id = ''
  22. webpage = self._download_webpage(url, video_id)
  23. title = self._html_search_regex(
  24. r'dc:title=\"(.*?)\"', webpage, 'title')
  25. playlist_url = self._html_search_regex(
  26. r'file: \'(.*?)\'', webpage, 'playlist URL')
  27. xml_file = urllib2.urlopen(playlist_url)
  28. data = xml_file.read()
  29. xml_file.close()
  30. root = ET.fromstring(data)
  31. video_url = root[0][0][0].text
  32. thumbnail = root[0][0][2].text
  33. m = re.search('video/(.+?).flv', video_url)
  34. if m:
  35. video_id = m.group(1)
  36. return {
  37. 'id': video_id,
  38. 'title': title,
  39. 'url': video_url,
  40. 'thumbnail': thumbnail,
  41. }