dhm.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. _VALID_URL = r'http://www\.dhm\.de/filmarchiv/(?P<id>.*?)'
  9. _TEST = {
  10. 'url': 'http://www.dhm.de/filmarchiv/die-filme/the-marshallplan-at-work-in-west-germany/',
  11. 'md5': '11c475f670209bf6acca0b2b7ef51827',
  12. 'info_dict': {
  13. 'id': 'marshallwg',
  14. 'ext': 'flv',
  15. 'title': 'MARSHALL PLAN AT WORK IN WESTERN GERMANY, THE',
  16. 'thumbnail': 'http://www.dhm.de/filmarchiv/video/mpworkwg.jpg',
  17. }
  18. }
  19. def _real_extract(self, url):
  20. video_id = ''
  21. webpage = self._download_webpage(url, video_id)
  22. title = self._html_search_regex(
  23. r'dc:title=\"(.*?)\"', webpage, 'title')
  24. playlist_url = self._html_search_regex(
  25. r'file: \'(.*?)\'', webpage, 'playlist URL')
  26. xml_file = urllib2.urlopen(playlist_url)
  27. data = xml_file.read()
  28. xml_file.close()
  29. root = ET.fromstring(data)
  30. video_url = root[0][0][0].text
  31. thumbnail = root[0][0][2].text
  32. m = re.search('video/(.+?).flv', video_url)
  33. if m:
  34. video_id = m.group(1)
  35. return {
  36. 'id': video_id,
  37. 'title': title,
  38. 'url': video_url,
  39. 'thumbnail': thumbnail,
  40. }