1 from __future__ import unicode_literals
6 from .common import InfoExtractor
16 class NHLBaseInfoExtractor(InfoExtractor):
18 def _fix_json(json_string):
19 return json_string.replace('\\\'', '\'')
21 def _extract_video(self, info):
23 self.report_extraction(video_id)
25 initial_video_url = info['publishPoint']
26 if info['formats'] == '1':
27 data = compat_urllib_parse.urlencode({
29 'path': initial_video_url.replace('.mp4', '_sd.mp4'),
31 path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
32 path_doc = self._download_xml(
33 path_url, video_id, 'Downloading final video url')
34 video_url = path_doc.find('path').text
36 video_url = initial_video_url
38 join = compat_urlparse.urljoin
41 'title': info['name'],
43 'description': info['description'],
44 'duration': int(info['duration']),
45 'thumbnail': join(join(video_url, '/u/'), info['bigImage']),
46 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]),
50 class NHLIE(NHLBaseInfoExtractor):
52 _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console(?:\?(?:.*?[?&])?)id=(?P<id>[0-9a-z-]+)'
55 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
56 'md5': 'db704a4ea09e8d3988c85e36cc892d09',
60 'title': 'Quick clip: Weise 4-3 goal vs Flames',
61 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.',
63 'upload_date': '20131006',
66 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h',
67 'md5': 'd22e82bc592f52d37d24b03531ee9696',
69 'id': '2014020024-628-h',
71 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)',
72 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014',
74 'upload_date': '20141011',
77 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616',
78 'only_matching': True,
81 def _real_extract(self, url):
82 mobj = re.match(self._VALID_URL, url)
83 video_id = mobj.group('id')
84 json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
85 data = self._download_json(
86 json_url, video_id, transform_source=self._fix_json)
87 return self._extract_video(data[0])
90 class NHLVideocenterIE(NHLBaseInfoExtractor):
91 IE_NAME = 'nhl.com:videocenter'
92 IE_DESC = 'NHL videocenter category'
93 _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
95 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
98 'title': 'Highlights',
100 'playlist_count': 12,
103 def _real_extract(self, url):
104 mobj = re.match(self._VALID_URL, url)
105 team = mobj.group('team')
106 webpage = self._download_webpage(url, team)
107 cat_id = self._search_regex(
108 [r'var defaultCatId = "(.+?)";',
109 r'{statusIndex:0,index:0,.*?id:(.*?),'],
110 webpage, 'category id')
111 playlist_title = self._html_search_regex(
112 r'tab0"[^>]*?>(.*?)</td>',
113 webpage, 'playlist title', flags=re.DOTALL).lower().capitalize()
115 data = compat_urllib_parse.urlencode({
117 # This is the default value
122 path = '/videocenter/servlets/browse?' + data
123 request_url = compat_urlparse.urljoin(url, path)
124 response = self._download_webpage(request_url, playlist_title)
125 response = self._fix_json(response)
126 if not response.strip():
127 self._downloader.report_warning('Got an empty reponse, trying '
128 'adding the "newvideos" parameter')
129 response = self._download_webpage(request_url + '&newvideos=true',
131 response = self._fix_json(response)
132 videos = json.loads(response)
136 'title': playlist_title,
138 'entries': [self._extract_video(v) for v in videos],