logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

bpb.py (2204B)


  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*:\s*'https?://film\.bpb\.de/[^}]+})", webpage)
  30. formats = []
  31. for video_info in video_info_dicts:
  32. video_info = self._parse_json(
  33. video_info, video_id, transform_source=js_to_json, fatal=False)
  34. if not video_info:
  35. continue
  36. video_url = video_info.get('src')
  37. if not video_url:
  38. continue
  39. quality = 'high' if '_high' in video_url else 'low'
  40. formats.append({
  41. 'url': video_url,
  42. 'preference': 10 if quality == 'high' else 0,
  43. 'format_note': quality,
  44. 'format_id': '%s-%s' % (quality, determine_ext(video_url)),
  45. })
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'formats': formats,
  50. 'title': title,
  51. 'description': self._og_search_description(webpage),
  52. }