]>
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 S |
23 | def _real_extract_video(self, video_id): |
24 | json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id | |
25 | data = self._download_json( | |
26 | json_url, video_id, transform_source=self._fix_json) | |
27 | return self._extract_video(data[0]) | |
28 | ||
91dbaef4 JMF |
29 | def _extract_video(self, info): |
30 | video_id = info['id'] | |
31 | self.report_extraction(video_id) | |
32 | ||
33 | initial_video_url = info['publishPoint'] | |
43d9718f | 34 | if info['formats'] == '1': |
62d8b566 | 35 | parsed_url = compat_urllib_parse_urlparse(initial_video_url) |
603c9208 JMF |
36 | filename, ext = os.path.splitext(parsed_url.path) |
37 | path = '%s_sd%s' % (filename, ext) | |
43d9718f S |
38 | data = compat_urllib_parse.urlencode({ |
39 | 'type': 'fvod', | |
62d8b566 | 40 | 'path': compat_urlparse.urlunparse(parsed_url[:2] + (path,) + parsed_url[3:]) |
43d9718f S |
41 | }) |
42 | path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data | |
43 | path_doc = self._download_xml( | |
44 | path_url, video_id, 'Downloading final video url') | |
45 | video_url = path_doc.find('path').text | |
46 | else: | |
5f6a1245 | 47 | video_url = initial_video_url |
91dbaef4 JMF |
48 | |
49 | join = compat_urlparse.urljoin | |
50 | return { | |
51 | 'id': video_id, | |
52 | 'title': info['name'], | |
53 | 'url': video_url, | |
91dbaef4 JMF |
54 | 'description': info['description'], |
55 | 'duration': int(info['duration']), | |
56 | 'thumbnail': join(join(video_url, '/u/'), info['bigImage']), | |
57 | 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]), | |
58 | } | |
59 | ||
60 | ||
61 | class NHLIE(NHLBaseInfoExtractor): | |
25945452 | 62 | IE_NAME = 'nhl.com' |
2c58674e | 63 | _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/(?:console)?(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)' |
2e1fa03b | 64 | |
7bb5df1c | 65 | _TESTS = [{ |
25945452 | 66 | 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614', |
43d9718f | 67 | 'md5': 'db704a4ea09e8d3988c85e36cc892d09', |
25945452 PH |
68 | 'info_dict': { |
69 | 'id': '453614', | |
70 | 'ext': 'mp4', | |
71 | 'title': 'Quick clip: Weise 4-3 goal vs Flames', | |
72 | 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.', | |
73 | 'duration': 18, | |
74 | 'upload_date': '20131006', | |
2e1fa03b | 75 | }, |
43d9718f S |
76 | }, { |
77 | 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h', | |
78 | 'md5': 'd22e82bc592f52d37d24b03531ee9696', | |
79 | 'info_dict': { | |
80 | 'id': '2014020024-628-h', | |
81 | 'ext': 'mp4', | |
82 | 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)', | |
83 | 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014', | |
84 | 'duration': 0, | |
85 | 'upload_date': '20141011', | |
86 | }, | |
62d8b566 AK |
87 | }, { |
88 | 'url': 'http://video.mapleleafs.nhl.com/videocenter/console?id=58665&catid=802', | |
89 | 'md5': 'c78fc64ea01777e426cfc202b746c825', | |
90 | 'info_dict': { | |
91 | 'id': '58665', | |
92 | 'ext': 'flv', | |
93 | 'title': 'Classic Game In Six - April 22, 1979', | |
94 | '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.', | |
95 | 'duration': 400, | |
96 | 'upload_date': '20100129' | |
97 | }, | |
7bb5df1c PH |
98 | }, { |
99 | 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616', | |
100 | 'only_matching': True, | |
2c58674e S |
101 | }, { |
102 | 'url': 'http://video.nhl.com/videocenter/?id=736722', | |
103 | 'only_matching': True, | |
7bb5df1c | 104 | }] |
2e1fa03b JMF |
105 | |
106 | def _real_extract(self, url): | |
e4c17d72 S |
107 | video_id = self._match_id(url) |
108 | return self._real_extract_video(video_id) | |
109 | ||
110 | ||
111 | class NHLNewsIE(NHLBaseInfoExtractor): | |
112 | IE_NAME = 'nhl.com:news' | |
113 | IE_DESC = 'NHL news' | |
114 | _VALID_URL = r'https?://(?:www\.)?nhl\.com/ice/news\.html?(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)' | |
115 | ||
116 | _TEST = { | |
117 | 'url': 'http://www.nhl.com/ice/news.htm?id=750727', | |
118 | 'md5': '4b3d1262e177687a3009937bd9ec0be8', | |
119 | 'info_dict': { | |
120 | 'id': '736722', | |
121 | 'ext': 'mp4', | |
122 | 'title': 'Cal Clutterbuck has been fined $2,000', | |
123 | 'description': 'md5:45fe547d30edab88b23e0dd0ab1ed9e6', | |
124 | 'duration': 37, | |
125 | 'upload_date': '20150128', | |
126 | }, | |
127 | } | |
128 | ||
129 | def _real_extract(self, url): | |
130 | news_id = self._match_id(url) | |
131 | webpage = self._download_webpage(url, news_id) | |
132 | video_id = self._search_regex( | |
133 | [r'pVid(\d+)', r"nlid\s*:\s*'(\d+)'"], | |
134 | webpage, 'video id') | |
135 | return self._real_extract_video(video_id) | |
91dbaef4 JMF |
136 | |
137 | ||
138 | class NHLVideocenterIE(NHLBaseInfoExtractor): | |
25945452 PH |
139 | IE_NAME = 'nhl.com:videocenter' |
140 | IE_DESC = 'NHL videocenter category' | |
ea2ee403 | 141 | _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?[^(id=)]*catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$' |
25945452 PH |
142 | _TEST = { |
143 | 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999', | |
144 | 'info_dict': { | |
145 | 'id': '999', | |
146 | 'title': 'Highlights', | |
147 | }, | |
148 | 'playlist_count': 12, | |
149 | } | |
91dbaef4 JMF |
150 | |
151 | def _real_extract(self, url): | |
152 | mobj = re.match(self._VALID_URL, url) | |
153 | team = mobj.group('team') | |
154 | webpage = self._download_webpage(url, team) | |
155 | cat_id = self._search_regex( | |
156 | [r'var defaultCatId = "(.+?)";', | |
157 | r'{statusIndex:0,index:0,.*?id:(.*?),'], | |
25945452 | 158 | webpage, 'category id') |
91dbaef4 | 159 | playlist_title = self._html_search_regex( |
ce68b590 | 160 | r'tab0"[^>]*?>(.*?)</td>', |
25945452 | 161 | webpage, 'playlist title', flags=re.DOTALL).lower().capitalize() |
2e1fa03b | 162 | |
2e1fa03b | 163 | data = compat_urllib_parse.urlencode({ |
91dbaef4 JMF |
164 | 'cid': cat_id, |
165 | # This is the default value | |
166 | 'count': 12, | |
167 | 'ptrs': 3, | |
168 | 'format': 'json', | |
2e1fa03b | 169 | }) |
91dbaef4 JMF |
170 | path = '/videocenter/servlets/browse?' + data |
171 | request_url = compat_urlparse.urljoin(url, path) | |
172 | response = self._download_webpage(request_url, playlist_title) | |
173 | response = self._fix_json(response) | |
174 | if not response.strip(): | |
8865bdeb | 175 | self._downloader.report_warning('Got an empty reponse, trying ' |
25945452 | 176 | 'adding the "newvideos" parameter') |
91dbaef4 | 177 | response = self._download_webpage(request_url + '&newvideos=true', |
9e1a5b84 | 178 | playlist_title) |
91dbaef4 JMF |
179 | response = self._fix_json(response) |
180 | videos = json.loads(response) | |
2e1fa03b | 181 | |
2e1fa03b | 182 | return { |
91dbaef4 JMF |
183 | '_type': 'playlist', |
184 | 'title': playlist_title, | |
185 | 'id': cat_id, | |
25945452 | 186 | 'entries': [self._extract_video(v) for v in videos], |
2e1fa03b | 187 | } |