You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. js_to_json,
  7. determine_ext,
  8. )
  9. class BpbIE(InfoExtractor):
  10. IE_DESC = 'Bundeszentrale für politische Bildung'
  11. _VALID_URL = r'https?://www\.bpb\.de/mediathek/(?P<id>[0-9]+)/'
  12. _TEST = {
  13. 'url': 'http://www.bpb.de/mediathek/297/joachim-gauck-zu-1989-und-die-erinnerung-an-die-ddr',
  14. # md5 fails in Python 2.6 due to buggy server response and wrong handling of urllib2
  15. 'md5': 'c4f84c8a8044ca9ff68bb8441d300b3f',
  16. 'info_dict': {
  17. 'id': '297',
  18. 'ext': 'mp4',
  19. 'title': 'Joachim Gauck zu 1989 und die Erinnerung an die DDR',
  20. 'description': 'Joachim Gauck, erster Beauftragter für die Stasi-Unterlagen, spricht auf dem Geschichtsforum über die friedliche Revolution 1989 und eine "gewisse Traurigkeit" im Umgang mit der DDR-Vergangenheit.'
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(url, video_id)
  26. title = self._html_search_regex(
  27. r'<h2 class="white">(.*?)</h2>', webpage, 'title')
  28. video_info_dicts = re.findall(
  29. r"({\s*src:\s*'http://film\.bpb\.de/[^}]+})", webpage)
  30. formats = []
  31. for video_info in video_info_dicts:
  32. video_info = self._parse_json(video_info, video_id, transform_source=js_to_json)
  33. quality = video_info['quality']
  34. video_url = video_info['src']
  35. formats.append({
  36. 'url': video_url,
  37. 'preference': 10 if quality == 'high' else 0,
  38. 'format_note': quality,
  39. 'format_id': '%s-%s' % (quality, determine_ext(video_url)),
  40. })
  41. self._sort_formats(formats)
  42. return {
  43. 'id': video_id,
  44. 'formats': formats,
  45. 'title': title,
  46. 'description': self._og_search_description(webpage),
  47. }