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