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