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