]>
Commit | Line | Data |
---|---|---|
006374e3 S |
1 | import re |
2 | ||
11d19ff5 | 3 | from .common import InfoExtractor |
006374e3 S |
4 | from ..utils import ( |
5 | try_get, | |
6 | unescapeHTML, | |
7 | url_or_none, | |
8 | urljoin, | |
9 | ) | |
10 | ||
11 | ||
12 | class WWEBaseIE(InfoExtractor): | |
13 | _SUBTITLE_LANGS = { | |
14 | 'English': 'en', | |
15 | 'Deutsch': 'de', | |
16 | } | |
17 | ||
18 | def _extract_entry(self, data, url, video_id=None): | |
add96eb9 | 19 | video_id = str(video_id or data['nid']) |
006374e3 S |
20 | title = data['title'] |
21 | ||
22 | formats = self._extract_m3u8_formats( | |
23 | data['file'], video_id, 'mp4', entry_protocol='m3u8_native', | |
24 | m3u8_id='hls') | |
11d19ff5 | 25 | |
006374e3 S |
26 | description = data.get('description') |
27 | thumbnail = urljoin(url, data.get('image')) | |
28 | series = data.get('show_name') | |
29 | episode = data.get('episode_name') | |
11d19ff5 | 30 | |
006374e3 S |
31 | subtitles = {} |
32 | tracks = data.get('tracks') | |
33 | if isinstance(tracks, list): | |
34 | for track in tracks: | |
35 | if not isinstance(track, dict): | |
36 | continue | |
37 | if track.get('kind') != 'captions': | |
38 | continue | |
39 | track_file = url_or_none(track.get('file')) | |
40 | if not track_file: | |
41 | continue | |
42 | label = track.get('label') | |
43 | lang = self._SUBTITLE_LANGS.get(label, label) or 'en' | |
44 | subtitles.setdefault(lang, []).append({ | |
45 | 'url': track_file, | |
46 | }) | |
47 | ||
48 | return { | |
49 | 'id': video_id, | |
50 | 'title': title, | |
51 | 'description': description, | |
52 | 'thumbnail': thumbnail, | |
53 | 'series': series, | |
54 | 'episode': episode, | |
55 | 'formats': formats, | |
56 | 'subtitles': subtitles, | |
57 | } | |
58 | ||
59 | ||
60 | class WWEIE(WWEBaseIE): | |
61 | _VALID_URL = r'https?://(?:[^/]+\.)?wwe\.com/(?:[^/]+/)*videos/(?P<id>[^/?#&]+)' | |
11d19ff5 | 62 | _TESTS = [{ |
63 | 'url': 'https://www.wwe.com/videos/daniel-bryan-vs-andrade-cien-almas-smackdown-live-sept-4-2018', | |
006374e3 | 64 | 'md5': '92811c6a14bfc206f7a6a9c5d9140184', |
11d19ff5 | 65 | 'info_dict': { |
66 | 'id': '40048199', | |
67 | 'ext': 'mp4', | |
68 | 'title': 'Daniel Bryan vs. Andrade "Cien" Almas: SmackDown LIVE, Sept. 4, 2018', | |
006374e3 | 69 | 'description': 'md5:2d7424dbc6755c61a0e649d2a8677f67', |
11d19ff5 | 70 | 'thumbnail': r're:^https?://.*\.jpg$', |
add96eb9 | 71 | }, |
11d19ff5 | 72 | }, { |
73 | 'url': 'https://de.wwe.com/videos/gran-metalik-vs-tony-nese-wwe-205-live-sept-4-2018', | |
74 | 'only_matching': True, | |
75 | }] | |
76 | ||
77 | def _real_extract(self, url): | |
78 | display_id = self._match_id(url) | |
79 | webpage = self._download_webpage(url, display_id) | |
80 | ||
006374e3 | 81 | landing = self._parse_json( |
11d19ff5 | 82 | self._html_search_regex( |
006374e3 | 83 | r'(?s)Drupal\.settings\s*,\s*({.+?})\s*\)\s*;', |
11d19ff5 | 84 | webpage, 'drupal settings'), |
006374e3 | 85 | display_id)['WWEVideoLanding'] |
11d19ff5 | 86 | |
006374e3 S |
87 | data = landing['initialVideo']['playlist'][0] |
88 | video_id = landing.get('initialVideoId') | |
11d19ff5 | 89 | |
006374e3 S |
90 | info = self._extract_entry(data, url, video_id) |
91 | info['display_id'] = display_id | |
92 | return info | |
11d19ff5 | 93 | |
11d19ff5 | 94 | |
006374e3 S |
95 | class WWEPlaylistIE(WWEBaseIE): |
96 | _VALID_URL = r'https?://(?:[^/]+\.)?wwe\.com/(?:[^/]+/)*(?P<id>[^/?#&]+)' | |
97 | _TESTS = [{ | |
98 | 'url': 'https://www.wwe.com/shows/raw/2018-11-12', | |
99 | 'info_dict': { | |
100 | 'id': '2018-11-12', | |
101 | }, | |
102 | 'playlist_mincount': 11, | |
103 | }, { | |
104 | 'url': 'http://www.wwe.com/article/walk-the-prank-wwe-edition', | |
105 | 'only_matching': True, | |
106 | }, { | |
107 | 'url': 'https://www.wwe.com/shows/wwenxt/article/matt-riddle-interview', | |
108 | 'only_matching': True, | |
109 | }] | |
110 | ||
111 | @classmethod | |
112 | def suitable(cls, url): | |
add96eb9 | 113 | return False if WWEIE.suitable(url) else super().suitable(url) |
006374e3 S |
114 | |
115 | def _real_extract(self, url): | |
116 | display_id = self._match_id(url) | |
117 | webpage = self._download_webpage(url, display_id) | |
118 | ||
119 | entries = [] | |
120 | for mobj in re.finditer( | |
121 | r'data-video\s*=\s*(["\'])(?P<data>{.+?})\1', webpage): | |
122 | video = self._parse_json( | |
123 | mobj.group('data'), display_id, transform_source=unescapeHTML, | |
124 | fatal=False) | |
125 | if not video: | |
126 | continue | |
127 | data = try_get(video, lambda x: x['playlist'][0], dict) | |
128 | if not data: | |
129 | continue | |
130 | try: | |
131 | entry = self._extract_entry(data, url) | |
132 | except Exception: | |
133 | continue | |
134 | entry['extractor_key'] = WWEIE.ie_key() | |
135 | entries.append(entry) | |
136 | ||
137 | return self.playlist_result(entries, display_id) |