]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bpb.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / bpb.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 js_to_json,
6 determine_ext,
7 )
8
9
10 class BpbIE(InfoExtractor):
11 IE_DESC = 'Bundeszentrale für politische Bildung'
12 _VALID_URL = r'https?://(?:www\.)?bpb\.de/mediathek/(?P<id>[0-9]+)/'
13
14 _TEST = {
15 'url': 'http://www.bpb.de/mediathek/297/joachim-gauck-zu-1989-und-die-erinnerung-an-die-ddr',
16 'md5': 'c4f84c8a8044ca9ff68bb8441d300b3f',
17 'info_dict': {
18 'id': '297',
19 'ext': 'mp4',
20 'title': 'Joachim Gauck zu 1989 und die Erinnerung an die DDR',
21 '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.'
22 }
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27 webpage = self._download_webpage(url, video_id)
28
29 title = self._html_search_regex(
30 r'<h2 class="white">(.*?)</h2>', webpage, 'title')
31 video_info_dicts = re.findall(
32 r"({\s*src\s*:\s*'https?://film\.bpb\.de/[^}]+})", webpage)
33
34 formats = []
35 for video_info in video_info_dicts:
36 video_info = self._parse_json(
37 video_info, video_id, transform_source=js_to_json, fatal=False)
38 if not video_info:
39 continue
40 video_url = video_info.get('src')
41 if not video_url:
42 continue
43 quality = 'high' if '_high' in video_url else 'low'
44 formats.append({
45 'url': video_url,
46 'quality': 10 if quality == 'high' else 0,
47 'format_note': quality,
48 'format_id': '%s-%s' % (quality, determine_ext(video_url)),
49 })
50
51 return {
52 'id': video_id,
53 'formats': formats,
54 'title': title,
55 'description': self._og_search_description(webpage),
56 }