]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bpb.py
debian/changelog: Prepare for release.
[youtubedl] / youtube_dl / extractor / bpb.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 js_to_json,
9 determine_ext,
10 )
11
12
13 class BpbIE(InfoExtractor):
14 IE_DESC = 'Bundeszentrale für politische Bildung'
15 _VALID_URL = r'https?://(?:www\.)?bpb\.de/mediathek/(?P<id>[0-9]+)/'
16
17 _TEST = {
18 'url': 'http://www.bpb.de/mediathek/297/joachim-gauck-zu-1989-und-die-erinnerung-an-die-ddr',
19 # md5 fails in Python 2.6 due to buggy server response and wrong handling of urllib2
20 'md5': 'c4f84c8a8044ca9ff68bb8441d300b3f',
21 'info_dict': {
22 'id': '297',
23 'ext': 'mp4',
24 'title': 'Joachim Gauck zu 1989 und die Erinnerung an die DDR',
25 '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.'
26 }
27 }
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31 webpage = self._download_webpage(url, video_id)
32
33 title = self._html_search_regex(
34 r'<h2 class="white">(.*?)</h2>', webpage, 'title')
35 video_info_dicts = re.findall(
36 r"({\s*src:\s*'http://film\.bpb\.de/[^}]+})", webpage)
37
38 formats = []
39 for video_info in video_info_dicts:
40 video_info = self._parse_json(video_info, video_id, transform_source=js_to_json)
41 quality = video_info['quality']
42 video_url = video_info['src']
43 formats.append({
44 'url': video_url,
45 'preference': 10 if quality == 'high' else 0,
46 'format_note': quality,
47 'format_id': '%s-%s' % (quality, determine_ext(video_url)),
48 })
49
50 self._sort_formats(formats)
51
52 return {
53 'id': video_id,
54 'formats': formats,
55 'title': title,
56 'description': self._og_search_description(webpage),
57 }