1 from __future__ import unicode_literals
7 from .common import InfoExtractor
10 compat_urllib_parse_urlencode,
11 compat_urllib_parse_urlparse,
23 class NHLBaseInfoExtractor(InfoExtractor):
25 def _fix_json(json_string):
26 return json_string.replace('\\\'', '\'')
28 def _real_extract_video(self, video_id):
29 vid_parts = video_id.split(',')
30 if len(vid_parts) == 3:
31 video_id = '%s0%s%s-X-h' % (vid_parts[0][:4], vid_parts[1], vid_parts[2].rjust(4, '0'))
32 json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
33 data = self._download_json(
34 json_url, video_id, transform_source=self._fix_json)
35 return self._extract_video(data[0])
37 def _extract_video(self, info):
39 self.report_extraction(video_id)
41 initial_video_url = info['publishPoint']
42 if info['formats'] == '1':
43 parsed_url = compat_urllib_parse_urlparse(initial_video_url)
44 filename, ext = os.path.splitext(parsed_url.path)
45 path = '%s_sd%s' % (filename, ext)
46 data = compat_urllib_parse_urlencode({
48 'path': compat_urlparse.urlunparse(parsed_url[:2] + (path,) + parsed_url[3:])
50 path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
51 path_doc = self._download_xml(
52 path_url, video_id, 'Downloading final video url')
53 video_url = path_doc.find('path').text
55 video_url = initial_video_url
57 join = compat_urlparse.urljoin
60 'title': info['name'],
62 'description': info['description'],
63 'duration': int(info['duration']),
64 'thumbnail': join(join(video_url, '/u/'), info['bigImage']),
65 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]),
67 if video_url.startswith('rtmp:'):
68 mobj = re.match(r'(?P<tc_url>rtmp://[^/]+/(?P<app>[a-z0-9/]+))/(?P<play_path>mp4:.*)', video_url)
70 'tc_url': mobj.group('tc_url'),
71 'play_path': mobj.group('play_path'),
72 'app': mobj.group('app'),
78 class NHLVideocenterIE(NHLBaseInfoExtractor):
79 IE_NAME = 'nhl.com:videocenter'
80 _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/(?:console|embed)?(?:\?(?:.*?[?&])?)(?:id|hlg|playlist)=(?P<id>[-0-9a-zA-Z,]+)'
83 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
84 'md5': 'db704a4ea09e8d3988c85e36cc892d09',
88 'title': 'Quick clip: Weise 4-3 goal vs Flames',
89 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.',
91 'upload_date': '20131006',
94 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h',
95 'md5': 'd22e82bc592f52d37d24b03531ee9696',
97 'id': '2014020024-628-h',
99 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)',
100 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014',
102 'upload_date': '20141011',
105 'url': 'http://video.mapleleafs.nhl.com/videocenter/console?id=58665&catid=802',
106 'md5': 'c78fc64ea01777e426cfc202b746c825',
110 'title': 'Classic Game In Six - April 22, 1979',
111 '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.',
113 'upload_date': '20100129'
116 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616',
117 'only_matching': True,
119 'url': 'http://video.nhl.com/videocenter/?id=736722',
120 'only_matching': True,
122 'url': 'http://video.nhl.com/videocenter/console?hlg=20142015,2,299&lang=en',
123 'md5': '076fcb88c255154aacbf0a7accc3f340',
125 'id': '2014020299-X-h',
127 'title': 'Penguins at Islanders / Game Highlights',
128 'description': 'Home broadcast - Pittsburgh Penguins at New York Islanders - November 22, 2014',
130 'upload_date': '20141122',
133 'url': 'http://video.oilers.nhl.com/videocenter/console?id=691469&catid=4',
137 'title': 'RAW | Craig MacTavish Full Press Conference',
138 'description': 'Oilers GM Craig MacTavish addresses the media at Rexall Place on Friday.',
139 'upload_date': '20141205',
142 'skip_download': True, # Requires rtmpdump
145 'url': 'http://video.nhl.com/videocenter/embed?playlist=836127',
146 'only_matching': True,
149 def _real_extract(self, url):
150 video_id = self._match_id(url)
151 return self._real_extract_video(video_id)
154 class NHLNewsIE(NHLBaseInfoExtractor):
155 IE_NAME = 'nhl.com:news'
157 _VALID_URL = r'https?://(?:.+?\.)?nhl\.com/(?:ice|club)/news\.html?(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)'
160 'url': 'http://www.nhl.com/ice/news.htm?id=750727',
161 'md5': '4b3d1262e177687a3009937bd9ec0be8',
165 'title': 'Cal Clutterbuck has been fined $2,000',
166 'description': 'md5:45fe547d30edab88b23e0dd0ab1ed9e6',
168 'upload_date': '20150128',
172 'url': 'http://sabres.nhl.com/club/news.htm?id=780189',
173 'md5': '9f663d1c006c90ac9fb82777d4294e12',
177 'title': 'Morning Skate: OTT vs. BUF (9/23/15)',
178 'description': "Brian Duff chats with Tyler Ennis prior to Buffalo's first preseason home game.",
180 'upload_date': '20150923',
184 def _real_extract(self, url):
185 news_id = self._match_id(url)
186 webpage = self._download_webpage(url, news_id)
187 video_id = self._search_regex(
188 [r'pVid(\d+)', r"nlid\s*:\s*'(\d+)'",
189 r'<iframe[^>]+src=["\']https?://video.*?\.nhl\.com/videocenter/embed\?.*\bplaylist=(\d+)'],
191 return self._real_extract_video(video_id)
194 class NHLVideocenterCategoryIE(NHLBaseInfoExtractor):
195 IE_NAME = 'nhl.com:videocenter:category'
196 IE_DESC = 'NHL videocenter category'
197 _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?[^(id=)]*catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
199 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
202 'title': 'Highlights',
204 'playlist_count': 12,
207 def _real_extract(self, url):
208 mobj = re.match(self._VALID_URL, url)
209 team = mobj.group('team')
210 webpage = self._download_webpage(url, team)
211 cat_id = self._search_regex(
212 [r'var defaultCatId = "(.+?)";',
213 r'{statusIndex:0,index:0,.*?id:(.*?),'],
214 webpage, 'category id')
215 playlist_title = self._html_search_regex(
216 r'tab0"[^>]*?>(.*?)</td>',
217 webpage, 'playlist title', flags=re.DOTALL).lower().capitalize()
219 data = compat_urllib_parse_urlencode({
221 # This is the default value
226 path = '/videocenter/servlets/browse?' + data
227 request_url = compat_urlparse.urljoin(url, path)
228 response = self._download_webpage(request_url, playlist_title)
229 response = self._fix_json(response)
230 if not response.strip():
231 self._downloader.report_warning('Got an empty response, trying '
232 'adding the "newvideos" parameter')
233 response = self._download_webpage(request_url + '&newvideos=true',
235 response = self._fix_json(response)
236 videos = json.loads(response)
240 'title': playlist_title,
242 'entries': [self._extract_video(v) for v in videos],
246 class NHLIE(InfoExtractor):
248 _VALID_URL = r'https?://(?:www\.)?nhl\.com/([^/]+/)*c-(?P<id>\d+)'
251 'url': 'https://www.nhl.com/video/anisimov-cleans-up-mess/t-277752844/c-43663503',
252 'md5': '0f7b9a8f986fb4b4eeeece9a56416eaf',
256 'title': 'Anisimov cleans up mess',
257 'description': 'md5:a02354acdfe900e940ce40706939ca63',
258 'timestamp': 1461288600,
259 'upload_date': '20160422',
263 'url': 'https://www.nhl.com/news/dennis-wideman-suspended/c-278258934',
264 'md5': '1f39f4ea74c1394dea110699a25b366c',
268 'title': 'Wideman suspended by NHL',
269 'description': 'Flames defenseman Dennis Wideman was banned 20 games for violation of Rule 40 (Physical Abuse of Officials)',
270 'upload_date': '20160204',
271 'timestamp': 1454544904,
275 def _real_extract(self, url):
276 tmp_id = self._match_id(url)
277 video_data = self._download_json(
278 'https://nhl.bamcontent.com/nhl/id/v1/%s/details/web-v1.json' % tmp_id,
280 if video_data.get('type') == 'article':
281 video_data = video_data['media']
283 video_id = compat_str(video_data['id'])
284 title = video_data['title']
287 for playback in video_data.get('playbacks', []):
288 playback_url = playback.get('url')
291 ext = determine_ext(playback_url)
293 formats.extend(self._extract_m3u8_formats(
294 playback_url, video_id, 'mp4', 'm3u8_native',
295 m3u8_id=playback.get('name', 'hls'), fatal=False))
297 height = int_or_none(playback.get('height'))
299 'format_id': playback.get('name', 'http' + ('-%dp' % height if height else '')),
301 'width': int_or_none(playback.get('width')),
304 self._sort_formats(formats, ('preference', 'width', 'height', 'tbr', 'format_id'))
307 for thumbnail_id, thumbnail_data in video_data.get('image', {}).get('cuts', {}).items():
308 thumbnail_url = thumbnail_data.get('src')
309 if not thumbnail_url:
313 'url': thumbnail_url,
314 'width': int_or_none(thumbnail_data.get('width')),
315 'height': int_or_none(thumbnail_data.get('height')),
321 'description': video_data.get('description'),
322 'timestamp': parse_iso8601(video_data.get('date')),
323 'duration': parse_duration(video_data.get('duration')),
324 'thumbnails': thumbnails,