]>
Commit | Line | Data |
---|---|---|
25945452 PH |
1 | from __future__ import unicode_literals |
2 | ||
2e1fa03b JMF |
3 | import re |
4 | import json | |
603c9208 | 5 | import os |
2e1fa03b JMF |
6 | |
7 | from .common import InfoExtractor | |
8865bdeb | 8 | from ..compat import ( |
2e1fa03b JMF |
9 | compat_urlparse, |
10 | compat_urllib_parse, | |
62d8b566 | 11 | compat_urllib_parse_urlparse |
8865bdeb PH |
12 | ) |
13 | from ..utils import ( | |
2e1fa03b JMF |
14 | unified_strdate, |
15 | ) | |
16 | ||
17 | ||
91dbaef4 JMF |
18 | class NHLBaseInfoExtractor(InfoExtractor): |
19 | @staticmethod | |
20 | def _fix_json(json_string): | |
21 | return json_string.replace('\\\'', '\'') | |
22 | ||
e4c17d72 | 23 | def _real_extract_video(self, video_id): |
09b412da YCH |
24 | vid_parts = video_id.split(',') |
25 | if len(vid_parts) == 3: | |
26 | video_id = '%s0%s%s-X-h' % (vid_parts[0][:4], vid_parts[1], vid_parts[2].rjust(4, '0')) | |
e4c17d72 S |
27 | json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id |
28 | data = self._download_json( | |
29 | json_url, video_id, transform_source=self._fix_json) | |
30 | return self._extract_video(data[0]) | |
31 | ||
91dbaef4 JMF |
32 | def _extract_video(self, info): |
33 | video_id = info['id'] | |
34 | self.report_extraction(video_id) | |
35 | ||
36 | initial_video_url = info['publishPoint'] | |
43d9718f | 37 | if info['formats'] == '1': |
62d8b566 | 38 | parsed_url = compat_urllib_parse_urlparse(initial_video_url) |
603c9208 JMF |
39 | filename, ext = os.path.splitext(parsed_url.path) |
40 | path = '%s_sd%s' % (filename, ext) | |
43d9718f S |
41 | data = compat_urllib_parse.urlencode({ |
42 | 'type': 'fvod', | |
62d8b566 | 43 | 'path': compat_urlparse.urlunparse(parsed_url[:2] + (path,) + parsed_url[3:]) |
43d9718f S |
44 | }) |
45 | path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data | |
46 | path_doc = self._download_xml( | |
47 | path_url, video_id, 'Downloading final video url') | |
48 | video_url = path_doc.find('path').text | |
49 | else: | |
5f6a1245 | 50 | video_url = initial_video_url |
91dbaef4 JMF |
51 | |
52 | join = compat_urlparse.urljoin | |
7ef00afe | 53 | ret = { |
91dbaef4 JMF |
54 | 'id': video_id, |
55 | 'title': info['name'], | |
56 | 'url': video_url, | |
91dbaef4 JMF |
57 | 'description': info['description'], |
58 | 'duration': int(info['duration']), | |
59 | 'thumbnail': join(join(video_url, '/u/'), info['bigImage']), | |
60 | 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]), | |
61 | } | |
7ef00afe YCH |
62 | if video_url.startswith('rtmp:'): |
63 | mobj = re.match(r'(?P<tc_url>rtmp://[^/]+/(?P<app>[a-z0-9/]+))/(?P<play_path>mp4:.*)', video_url) | |
64 | ret.update({ | |
65 | 'tc_url': mobj.group('tc_url'), | |
66 | 'play_path': mobj.group('play_path'), | |
67 | 'app': mobj.group('app'), | |
68 | 'no_resume': True, | |
69 | }) | |
70 | return ret | |
91dbaef4 JMF |
71 | |
72 | ||
73 | class NHLIE(NHLBaseInfoExtractor): | |
25945452 | 74 | IE_NAME = 'nhl.com' |
9fbd4b35 | 75 | _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/(?:console|embed)?(?:\?(?:.*?[?&])?)(?:id|hlg|playlist)=(?P<id>[-0-9a-zA-Z,]+)' |
2e1fa03b | 76 | |
7bb5df1c | 77 | _TESTS = [{ |
25945452 | 78 | 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614', |
43d9718f | 79 | 'md5': 'db704a4ea09e8d3988c85e36cc892d09', |
25945452 PH |
80 | 'info_dict': { |
81 | 'id': '453614', | |
82 | 'ext': 'mp4', | |
83 | 'title': 'Quick clip: Weise 4-3 goal vs Flames', | |
84 | 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.', | |
85 | 'duration': 18, | |
86 | 'upload_date': '20131006', | |
2e1fa03b | 87 | }, |
43d9718f S |
88 | }, { |
89 | 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h', | |
90 | 'md5': 'd22e82bc592f52d37d24b03531ee9696', | |
91 | 'info_dict': { | |
92 | 'id': '2014020024-628-h', | |
93 | 'ext': 'mp4', | |
94 | 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)', | |
95 | 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014', | |
96 | 'duration': 0, | |
97 | 'upload_date': '20141011', | |
98 | }, | |
62d8b566 AK |
99 | }, { |
100 | 'url': 'http://video.mapleleafs.nhl.com/videocenter/console?id=58665&catid=802', | |
101 | 'md5': 'c78fc64ea01777e426cfc202b746c825', | |
102 | 'info_dict': { | |
103 | 'id': '58665', | |
104 | 'ext': 'flv', | |
105 | 'title': 'Classic Game In Six - April 22, 1979', | |
106 | 'description': 'It was the last playoff game for the Leafs in the decade, and the last time the Leafs and Habs played in the playoffs. Great game, not a great ending.', | |
107 | 'duration': 400, | |
108 | 'upload_date': '20100129' | |
109 | }, | |
7bb5df1c PH |
110 | }, { |
111 | 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616', | |
112 | 'only_matching': True, | |
2c58674e S |
113 | }, { |
114 | 'url': 'http://video.nhl.com/videocenter/?id=736722', | |
115 | 'only_matching': True, | |
09b412da YCH |
116 | }, { |
117 | 'url': 'http://video.nhl.com/videocenter/console?hlg=20142015,2,299&lang=en', | |
118 | 'md5': '076fcb88c255154aacbf0a7accc3f340', | |
119 | 'info_dict': { | |
120 | 'id': '2014020299-X-h', | |
121 | 'ext': 'mp4', | |
122 | 'title': 'Penguins at Islanders / Game Highlights', | |
123 | 'description': 'Home broadcast - Pittsburgh Penguins at New York Islanders - November 22, 2014', | |
124 | 'duration': 268, | |
125 | 'upload_date': '20141122', | |
126 | } | |
7ef00afe YCH |
127 | }, { |
128 | 'url': 'http://video.oilers.nhl.com/videocenter/console?id=691469&catid=4', | |
129 | 'info_dict': { | |
130 | 'id': '691469', | |
131 | 'ext': 'mp4', | |
132 | 'title': 'RAW | Craig MacTavish Full Press Conference', | |
133 | 'description': 'Oilers GM Craig MacTavish addresses the media at Rexall Place on Friday.', | |
134 | 'upload_date': '20141205', | |
135 | }, | |
136 | 'params': { | |
137 | 'skip_download': True, # Requires rtmpdump | |
138 | } | |
9fbd4b35 S |
139 | }, { |
140 | 'url': 'http://video.nhl.com/videocenter/embed?playlist=836127', | |
141 | 'only_matching': True, | |
7bb5df1c | 142 | }] |
2e1fa03b JMF |
143 | |
144 | def _real_extract(self, url): | |
e4c17d72 S |
145 | video_id = self._match_id(url) |
146 | return self._real_extract_video(video_id) | |
147 | ||
148 | ||
149 | class NHLNewsIE(NHLBaseInfoExtractor): | |
150 | IE_NAME = 'nhl.com:news' | |
151 | IE_DESC = 'NHL news' | |
9c58885c | 152 | _VALID_URL = r'https?://(?:.+?\.)?nhl\.com/(?:ice|club)/news\.html?(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)' |
e4c17d72 | 153 | |
9c58885c | 154 | _TESTS = [{ |
e4c17d72 S |
155 | 'url': 'http://www.nhl.com/ice/news.htm?id=750727', |
156 | 'md5': '4b3d1262e177687a3009937bd9ec0be8', | |
157 | 'info_dict': { | |
158 | 'id': '736722', | |
159 | 'ext': 'mp4', | |
160 | 'title': 'Cal Clutterbuck has been fined $2,000', | |
161 | 'description': 'md5:45fe547d30edab88b23e0dd0ab1ed9e6', | |
162 | 'duration': 37, | |
163 | 'upload_date': '20150128', | |
164 | }, | |
9c58885c S |
165 | }, { |
166 | # iframe embed | |
167 | 'url': 'http://sabres.nhl.com/club/news.htm?id=780189', | |
168 | 'md5': '9f663d1c006c90ac9fb82777d4294e12', | |
169 | 'info_dict': { | |
170 | 'id': '836127', | |
171 | 'ext': 'mp4', | |
172 | 'title': 'Morning Skate: OTT vs. BUF (9/23/15)', | |
173 | 'description': "Brian Duff chats with Tyler Ennis prior to Buffalo's first preseason home game.", | |
174 | 'duration': 93, | |
175 | 'upload_date': '20150923', | |
176 | }, | |
177 | }] | |
e4c17d72 S |
178 | |
179 | def _real_extract(self, url): | |
180 | news_id = self._match_id(url) | |
181 | webpage = self._download_webpage(url, news_id) | |
182 | video_id = self._search_regex( | |
9c58885c S |
183 | [r'pVid(\d+)', r"nlid\s*:\s*'(\d+)'", |
184 | r'<iframe[^>]+src=["\']https?://video.*?\.nhl\.com/videocenter/embed\?.*\bplaylist=(\d+)'], | |
e4c17d72 S |
185 | webpage, 'video id') |
186 | return self._real_extract_video(video_id) | |
91dbaef4 JMF |
187 | |
188 | ||
189 | class NHLVideocenterIE(NHLBaseInfoExtractor): | |
25945452 PH |
190 | IE_NAME = 'nhl.com:videocenter' |
191 | IE_DESC = 'NHL videocenter category' | |
ea2ee403 | 192 | _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?[^(id=)]*catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$' |
25945452 PH |
193 | _TEST = { |
194 | 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999', | |
195 | 'info_dict': { | |
196 | 'id': '999', | |
197 | 'title': 'Highlights', | |
198 | }, | |
199 | 'playlist_count': 12, | |
200 | } | |
91dbaef4 JMF |
201 | |
202 | def _real_extract(self, url): | |
203 | mobj = re.match(self._VALID_URL, url) | |
204 | team = mobj.group('team') | |
205 | webpage = self._download_webpage(url, team) | |
206 | cat_id = self._search_regex( | |
207 | [r'var defaultCatId = "(.+?)";', | |
208 | r'{statusIndex:0,index:0,.*?id:(.*?),'], | |
25945452 | 209 | webpage, 'category id') |
91dbaef4 | 210 | playlist_title = self._html_search_regex( |
ce68b590 | 211 | r'tab0"[^>]*?>(.*?)</td>', |
25945452 | 212 | webpage, 'playlist title', flags=re.DOTALL).lower().capitalize() |
2e1fa03b | 213 | |
2e1fa03b | 214 | data = compat_urllib_parse.urlencode({ |
91dbaef4 JMF |
215 | 'cid': cat_id, |
216 | # This is the default value | |
217 | 'count': 12, | |
218 | 'ptrs': 3, | |
219 | 'format': 'json', | |
2e1fa03b | 220 | }) |
91dbaef4 JMF |
221 | path = '/videocenter/servlets/browse?' + data |
222 | request_url = compat_urlparse.urljoin(url, path) | |
223 | response = self._download_webpage(request_url, playlist_title) | |
224 | response = self._fix_json(response) | |
225 | if not response.strip(): | |
8865bdeb | 226 | self._downloader.report_warning('Got an empty reponse, trying ' |
25945452 | 227 | 'adding the "newvideos" parameter') |
91dbaef4 | 228 | response = self._download_webpage(request_url + '&newvideos=true', |
9e1a5b84 | 229 | playlist_title) |
91dbaef4 JMF |
230 | response = self._fix_json(response) |
231 | videos = json.loads(response) | |
2e1fa03b | 232 | |
2e1fa03b | 233 | return { |
91dbaef4 JMF |
234 | '_type': 'playlist', |
235 | 'title': playlist_title, | |
236 | 'id': cat_id, | |
25945452 | 237 | 'entries': [self._extract_video(v) for v in videos], |
2e1fa03b | 238 | } |