]>
Commit | Line | Data |
---|---|---|
c70a9f2a DB |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import json | |
5 | import re | |
6 | ||
86878b6c | 7 | from ..utils import int_or_none, unified_timestamp, unescapeHTML |
c70a9f2a DB |
8 | from .common import InfoExtractor |
9 | ||
10 | ||
11 | class HRFernsehenIE(InfoExtractor): | |
12 | IE_NAME = 'hrfernsehen' | |
13 | _VALID_URL = r'^https?://www\.(?:hr-fernsehen|hessenschau)\.de/.*,video-(?P<id>[0-9]{6})\.html' | |
14 | ||
15 | _TESTS = [{ | |
16 | 'url': 'https://www.hessenschau.de/tv-sendung/hessenschau-vom-26082020,video-130546.html', | |
17 | 'md5': '5c4e0ba94677c516a2f65a84110fc536', | |
18 | 'info_dict': { | |
19 | 'id': '130546', | |
20 | 'ext': 'mp4', | |
21 | 'description': 'Sturmtief Kirsten fegt über Hessen / Die Corona-Pandemie – eine Chronologie / ' | |
22 | 'Sterbehilfe: Die Lage in Hessen / Miss Hessen leitet zwei eigene Unternehmen / ' | |
23 | 'Pop-Up Museum zeigt Schwarze Unterhaltung und Black Music', | |
24 | 'subtitles': {'de': [{ | |
25 | 'url': 'https://hr-a.akamaihd.net/video/as/hessenschau/2020_08/hrLogo_200826200407_L385592_512x288-25p-500kbit.vtt' | |
26 | }]}, | |
27 | 'timestamp': 1598470200, | |
28 | 'upload_date': '20200826', | |
29 | 'thumbnails': [{ | |
30 | 'url': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9.jpg', | |
31 | 'id': '0' | |
32 | }, { | |
33 | 'url': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9__medium.jpg', | |
34 | 'id': '1' | |
35 | }], | |
36 | 'title': 'hessenschau vom 26.08.2020' | |
37 | } | |
38 | }, { | |
39 | 'url': 'https://www.hr-fernsehen.de/sendungen-a-z/mex/sendungen/fair-und-gut---was-hinter-aldis-eigenem-guetesiegel-steckt,video-130544.html', | |
40 | 'only_matching': True | |
41 | }] | |
42 | ||
43 | _GEO_COUNTRIES = ['DE'] | |
44 | ||
45 | def extract_airdate(self, loader_data): | |
46 | airdate_str = loader_data.get('mediaMetadata', {}).get('agf', {}).get('airdate') | |
47 | ||
48 | if airdate_str is None: | |
49 | return None | |
50 | ||
51 | return unified_timestamp(airdate_str) | |
52 | ||
53 | def extract_formats(self, loader_data): | |
54 | stream_formats = [] | |
55 | for stream_obj in loader_data["videoResolutionLevels"]: | |
56 | stream_format = { | |
57 | 'format_id': str(stream_obj['verticalResolution']) + "p", | |
58 | 'height': stream_obj['verticalResolution'], | |
59 | 'url': stream_obj['url'], | |
60 | } | |
61 | ||
62 | quality_information = re.search(r'([0-9]{3,4})x([0-9]{3,4})-([0-9]{2})p-([0-9]{3,4})kbit', | |
63 | stream_obj['url']) | |
64 | if quality_information: | |
65 | stream_format['width'] = int_or_none(quality_information.group(1)) | |
66 | stream_format['height'] = int_or_none(quality_information.group(2)) | |
67 | stream_format['fps'] = int_or_none(quality_information.group(3)) | |
68 | stream_format['tbr'] = int_or_none(quality_information.group(4)) | |
69 | ||
70 | stream_formats.append(stream_format) | |
71 | ||
72 | self._sort_formats(stream_formats) | |
73 | return stream_formats | |
74 | ||
75 | def _real_extract(self, url): | |
76 | video_id = self._match_id(url) | |
77 | webpage = self._download_webpage(url, video_id) | |
78 | ||
79 | title = self._html_search_meta( | |
80 | ['og:title', 'twitter:title', 'name'], webpage) | |
81 | description = self._html_search_meta( | |
82 | ['description'], webpage) | |
83 | ||
84 | loader_str = unescapeHTML(self._search_regex(r"data-hr-mediaplayer-loader='([^']*)'", webpage, "ardloader")) | |
85 | loader_data = json.loads(loader_str) | |
86 | ||
87 | info = { | |
88 | 'id': video_id, | |
89 | 'title': title, | |
90 | 'description': description, | |
91 | 'formats': self.extract_formats(loader_data), | |
92 | 'timestamp': self.extract_airdate(loader_data) | |
93 | } | |
94 | ||
95 | if "subtitle" in loader_data: | |
96 | info["subtitles"] = {"de": [{"url": loader_data["subtitle"]}]} | |
97 | ||
98 | thumbnails = list(set([t for t in loader_data.get("previewImageUrl", {}).values()])) | |
99 | if len(thumbnails) > 0: | |
100 | info["thumbnails"] = [{"url": t} for t in thumbnails] | |
101 | ||
102 | return info |