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