1 from __future__ import unicode_literals
6 from .common import InfoExtractor
15 class NHLBaseInfoExtractor(InfoExtractor):
17 def _fix_json(json_string):
18 return json_string.replace('\\\'', '\'')
20 def _extract_video(self, info):
22 self.report_extraction(video_id)
24 initial_video_url = info['publishPoint']
25 data = compat_urllib_parse.urlencode({
27 'path': initial_video_url.replace('.mp4', '_sd.mp4'),
29 path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
30 path_doc = self._download_xml(
31 path_url, video_id, 'Downloading final video url')
32 video_url = path_doc.find('path').text
34 join = compat_urlparse.urljoin
37 'title': info['name'],
39 'ext': determine_ext(video_url),
40 'description': info['description'],
41 'duration': int(info['duration']),
42 'thumbnail': join(join(video_url, '/u/'), info['bigImage']),
43 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]),
47 class NHLIE(NHLBaseInfoExtractor):
49 _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console\?.*?(?:[?&])id=(?P<id>[0-9]+)'
52 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
56 'title': 'Quick clip: Weise 4-3 goal vs Flames',
57 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.',
59 'upload_date': '20131006',
63 def _real_extract(self, url):
64 mobj = re.match(self._VALID_URL, url)
65 video_id = mobj.group('id')
66 json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
67 data = self._download_json(
68 json_url, video_id, transform_source=self._fix_json)
69 return self._extract_video(data[0])
72 class NHLVideocenterIE(NHLBaseInfoExtractor):
73 IE_NAME = 'nhl.com:videocenter'
74 IE_DESC = 'NHL videocenter category'
75 _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
77 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
80 'title': 'Highlights',
85 def _real_extract(self, url):
86 mobj = re.match(self._VALID_URL, url)
87 team = mobj.group('team')
88 webpage = self._download_webpage(url, team)
89 cat_id = self._search_regex(
90 [r'var defaultCatId = "(.+?)";',
91 r'{statusIndex:0,index:0,.*?id:(.*?),'],
92 webpage, 'category id')
93 playlist_title = self._html_search_regex(
94 r'tab0"[^>]*?>(.*?)</td>',
95 webpage, 'playlist title', flags=re.DOTALL).lower().capitalize()
97 data = compat_urllib_parse.urlencode({
99 # This is the default value
104 path = '/videocenter/servlets/browse?' + data
105 request_url = compat_urlparse.urljoin(url, path)
106 response = self._download_webpage(request_url, playlist_title)
107 response = self._fix_json(response)
108 if not response.strip():
109 self._downloader.report_warning(u'Got an empty reponse, trying '
110 'adding the "newvideos" parameter')
111 response = self._download_webpage(request_url + '&newvideos=true',
113 response = self._fix_json(response)
114 videos = json.loads(response)
118 'title': playlist_title,
120 'entries': [self._extract_video(v) for v in videos],