]>
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', | |
db477870 | 29 | 'thumbnail': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9__medium.jpg', |
c70a9f2a DB |
30 | 'title': 'hessenschau vom 26.08.2020' |
31 | } | |
32 | }, { | |
33 | 'url': 'https://www.hr-fernsehen.de/sendungen-a-z/mex/sendungen/fair-und-gut---was-hinter-aldis-eigenem-guetesiegel-steckt,video-130544.html', | |
34 | 'only_matching': True | |
35 | }] | |
36 | ||
37 | _GEO_COUNTRIES = ['DE'] | |
38 | ||
39 | def extract_airdate(self, loader_data): | |
40 | airdate_str = loader_data.get('mediaMetadata', {}).get('agf', {}).get('airdate') | |
41 | ||
42 | if airdate_str is None: | |
43 | return None | |
44 | ||
45 | return unified_timestamp(airdate_str) | |
46 | ||
47 | def extract_formats(self, loader_data): | |
48 | stream_formats = [] | |
49 | for stream_obj in loader_data["videoResolutionLevels"]: | |
50 | stream_format = { | |
51 | 'format_id': str(stream_obj['verticalResolution']) + "p", | |
52 | 'height': stream_obj['verticalResolution'], | |
53 | 'url': stream_obj['url'], | |
54 | } | |
55 | ||
56 | quality_information = re.search(r'([0-9]{3,4})x([0-9]{3,4})-([0-9]{2})p-([0-9]{3,4})kbit', | |
57 | stream_obj['url']) | |
58 | if quality_information: | |
59 | stream_format['width'] = int_or_none(quality_information.group(1)) | |
60 | stream_format['height'] = int_or_none(quality_information.group(2)) | |
61 | stream_format['fps'] = int_or_none(quality_information.group(3)) | |
62 | stream_format['tbr'] = int_or_none(quality_information.group(4)) | |
63 | ||
64 | stream_formats.append(stream_format) | |
65 | ||
66 | self._sort_formats(stream_formats) | |
67 | return stream_formats | |
68 | ||
69 | def _real_extract(self, url): | |
70 | video_id = self._match_id(url) | |
71 | webpage = self._download_webpage(url, video_id) | |
72 | ||
73 | title = self._html_search_meta( | |
74 | ['og:title', 'twitter:title', 'name'], webpage) | |
75 | description = self._html_search_meta( | |
76 | ['description'], webpage) | |
77 | ||
db477870 | 78 | loader_str = unescapeHTML(self._search_regex(r"data-new-hr-mediaplayer-loader='([^']*)'", webpage, "ardloader")) |
c70a9f2a DB |
79 | loader_data = json.loads(loader_str) |
80 | ||
81 | info = { | |
82 | 'id': video_id, | |
83 | 'title': title, | |
84 | 'description': description, | |
85 | 'formats': self.extract_formats(loader_data), | |
86 | 'timestamp': self.extract_airdate(loader_data) | |
87 | } | |
88 | ||
89 | if "subtitle" in loader_data: | |
90 | info["subtitles"] = {"de": [{"url": loader_data["subtitle"]}]} | |
91 | ||
92 | thumbnails = list(set([t for t in loader_data.get("previewImageUrl", {}).values()])) | |
93 | if len(thumbnails) > 0: | |
94 | info["thumbnails"] = [{"url": t} for t in thumbnails] | |
95 | ||
96 | return info |