]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/watchbox.py
7469fe9624c97412fe7d8612d2de7db7a1401039
[yt-dlp.git] / yt_dlp / extractor / watchbox.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..compat import compat_str
7 from ..utils import (
8 int_or_none,
9 js_to_json,
10 strip_or_none,
11 try_get,
12 unescapeHTML,
13 unified_timestamp,
14 )
15
16
17 class WatchBoxIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?watchbox\.de/(?P<kind>serien|filme)/(?:[^/]+/)*[^/]+-(?P<id>\d+)'
19 _TESTS = [{
20 # film
21 'url': 'https://www.watchbox.de/filme/free-jimmy-12325.html',
22 'info_dict': {
23 'id': '341368',
24 'ext': 'mp4',
25 'title': 'Free Jimmy',
26 'description': 'md5:bcd8bafbbf9dc0ef98063d344d7cc5f6',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'duration': 4890,
29 'age_limit': 16,
30 'release_year': 2009,
31 },
32 'params': {
33 'format': 'bestvideo',
34 'skip_download': True,
35 },
36 'expected_warnings': ['Failed to download m3u8 information'],
37 }, {
38 # episode
39 'url': 'https://www.watchbox.de/serien/ugly-americans-12231/staffel-1/date-in-der-hoelle-328286.html',
40 'info_dict': {
41 'id': '328286',
42 'ext': 'mp4',
43 'title': 'S01 E01 - Date in der Hölle',
44 'description': 'md5:2f31c74a8186899f33cb5114491dae2b',
45 'thumbnail': r're:^https?://.*\.jpg$',
46 'duration': 1291,
47 'age_limit': 12,
48 'release_year': 2010,
49 'series': 'Ugly Americans',
50 'season_number': 1,
51 'episode': 'Date in der Hölle',
52 'episode_number': 1,
53 },
54 'params': {
55 'format': 'bestvideo',
56 'skip_download': True,
57 },
58 'expected_warnings': ['Failed to download m3u8 information'],
59 }, {
60 'url': 'https://www.watchbox.de/serien/ugly-americans-12231/staffel-2/der-ring-des-powers-328270',
61 'only_matching': True,
62 }]
63
64 def _real_extract(self, url):
65 mobj = self._match_valid_url(url)
66 kind, video_id = mobj.group('kind', 'id')
67
68 webpage = self._download_webpage(url, video_id)
69
70 player_config = self._parse_json(
71 self._search_regex(
72 r'data-player-conf=(["\'])(?P<data>{.+?})\1', webpage,
73 'player config', default='{}', group='data'),
74 video_id, transform_source=unescapeHTML, fatal=False)
75
76 if not player_config:
77 player_config = self._parse_json(
78 self._search_regex(
79 r'playerConf\s*=\s*({.+?})\s*;', webpage, 'player config',
80 default='{}'),
81 video_id, transform_source=js_to_json, fatal=False) or {}
82
83 source = player_config.get('source') or {}
84
85 video_id = compat_str(source.get('videoId') or video_id)
86
87 devapi = self._download_json(
88 'http://api.watchbox.de/devapi/id/%s' % video_id, video_id, query={
89 'format': 'json',
90 'apikey': 'hbbtv',
91 }, fatal=False)
92
93 item = try_get(devapi, lambda x: x['items'][0], dict) or {}
94
95 title = item.get('title') or try_get(
96 item, lambda x: x['movie']['headline_movie'],
97 compat_str) or source['title']
98
99 formats = []
100 hls_url = item.get('media_videourl_hls') or source.get('hls')
101 if hls_url:
102 formats.extend(self._extract_m3u8_formats(
103 hls_url, video_id, 'mp4', entry_protocol='m3u8_native',
104 m3u8_id='hls', fatal=False))
105 dash_url = item.get('media_videourl_wv') or source.get('dash')
106 if dash_url:
107 formats.extend(self._extract_mpd_formats(
108 dash_url, video_id, mpd_id='dash', fatal=False))
109 mp4_url = item.get('media_videourl')
110 if mp4_url:
111 formats.append({
112 'url': mp4_url,
113 'format_id': 'mp4',
114 'width': int_or_none(item.get('width')),
115 'height': int_or_none(item.get('height')),
116 'tbr': int_or_none(item.get('bitrate')),
117 })
118 self._sort_formats(formats)
119
120 description = strip_or_none(item.get('descr'))
121 thumbnail = item.get('media_content_thumbnail_large') or source.get('poster') or item.get('media_thumbnail')
122 duration = int_or_none(item.get('media_length') or source.get('length'))
123 timestamp = unified_timestamp(item.get('pubDate'))
124 view_count = int_or_none(item.get('media_views'))
125 age_limit = int_or_none(try_get(item, lambda x: x['movie']['fsk']))
126 release_year = int_or_none(try_get(item, lambda x: x['movie']['rel_year']))
127
128 info = {
129 'id': video_id,
130 'title': title,
131 'description': description,
132 'thumbnail': thumbnail,
133 'duration': duration,
134 'timestamp': timestamp,
135 'view_count': view_count,
136 'age_limit': age_limit,
137 'release_year': release_year,
138 'formats': formats,
139 }
140
141 if kind.lower() == 'serien':
142 series = try_get(
143 item, lambda x: x['special']['title'],
144 compat_str) or source.get('format')
145 season_number = int_or_none(self._search_regex(
146 r'^S(\d{1,2})\s*E\d{1,2}', title, 'season number',
147 default=None) or self._search_regex(
148 r'/staffel-(\d+)/', url, 'season number', default=None))
149 episode = source.get('title')
150 episode_number = int_or_none(self._search_regex(
151 r'^S\d{1,2}\s*E(\d{1,2})', title, 'episode number',
152 default=None))
153 info.update({
154 'series': series,
155 'season_number': season_number,
156 'episode': episode,
157 'episode_number': episode_number,
158 })
159
160 return info