]>
Commit | Line | Data |
---|---|---|
25945452 PH |
1 | from __future__ import unicode_literals |
2 | ||
2e1fa03b JMF |
3 | import re |
4 | import json | |
2e1fa03b JMF |
5 | |
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | compat_urlparse, | |
9 | compat_urllib_parse, | |
2e1fa03b JMF |
10 | unified_strdate, |
11 | ) | |
12 | ||
13 | ||
91dbaef4 JMF |
14 | class NHLBaseInfoExtractor(InfoExtractor): |
15 | @staticmethod | |
16 | def _fix_json(json_string): | |
17 | return json_string.replace('\\\'', '\'') | |
18 | ||
19 | def _extract_video(self, info): | |
20 | video_id = info['id'] | |
21 | self.report_extraction(video_id) | |
22 | ||
23 | initial_video_url = info['publishPoint'] | |
43d9718f S |
24 | if info['formats'] == '1': |
25 | data = compat_urllib_parse.urlencode({ | |
26 | 'type': 'fvod', | |
27 | 'path': initial_video_url.replace('.mp4', '_sd.mp4'), | |
28 | }) | |
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 | |
33 | else: | |
5f6a1245 | 34 | video_url = initial_video_url |
91dbaef4 JMF |
35 | |
36 | join = compat_urlparse.urljoin | |
37 | return { | |
38 | 'id': video_id, | |
39 | 'title': info['name'], | |
40 | 'url': video_url, | |
91dbaef4 JMF |
41 | 'description': info['description'], |
42 | 'duration': int(info['duration']), | |
43 | 'thumbnail': join(join(video_url, '/u/'), info['bigImage']), | |
44 | 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]), | |
45 | } | |
46 | ||
47 | ||
48 | class NHLIE(NHLBaseInfoExtractor): | |
25945452 | 49 | IE_NAME = 'nhl.com' |
43d9718f | 50 | _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console(?:\?(?:.*?[?&])?)id=(?P<id>[0-9a-z-]+)' |
2e1fa03b | 51 | |
7bb5df1c | 52 | _TESTS = [{ |
25945452 | 53 | 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614', |
43d9718f | 54 | 'md5': 'db704a4ea09e8d3988c85e36cc892d09', |
25945452 PH |
55 | 'info_dict': { |
56 | 'id': '453614', | |
57 | 'ext': 'mp4', | |
58 | 'title': 'Quick clip: Weise 4-3 goal vs Flames', | |
59 | 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.', | |
60 | 'duration': 18, | |
61 | 'upload_date': '20131006', | |
2e1fa03b | 62 | }, |
43d9718f S |
63 | }, { |
64 | 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h', | |
65 | 'md5': 'd22e82bc592f52d37d24b03531ee9696', | |
66 | 'info_dict': { | |
67 | 'id': '2014020024-628-h', | |
68 | 'ext': 'mp4', | |
69 | 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)', | |
70 | 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014', | |
71 | 'duration': 0, | |
72 | 'upload_date': '20141011', | |
73 | }, | |
7bb5df1c PH |
74 | }, { |
75 | 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616', | |
76 | 'only_matching': True, | |
77 | }] | |
2e1fa03b JMF |
78 | |
79 | def _real_extract(self, url): | |
80 | mobj = re.match(self._VALID_URL, url) | |
81 | video_id = mobj.group('id') | |
82 | json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id | |
25945452 PH |
83 | data = self._download_json( |
84 | json_url, video_id, transform_source=self._fix_json) | |
85 | return self._extract_video(data[0]) | |
91dbaef4 JMF |
86 | |
87 | ||
88 | class NHLVideocenterIE(NHLBaseInfoExtractor): | |
25945452 PH |
89 | IE_NAME = 'nhl.com:videocenter' |
90 | IE_DESC = 'NHL videocenter category' | |
22a6f150 | 91 | _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$' |
25945452 PH |
92 | _TEST = { |
93 | 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999', | |
94 | 'info_dict': { | |
95 | 'id': '999', | |
96 | 'title': 'Highlights', | |
97 | }, | |
98 | 'playlist_count': 12, | |
99 | } | |
91dbaef4 JMF |
100 | |
101 | def _real_extract(self, url): | |
102 | mobj = re.match(self._VALID_URL, url) | |
103 | team = mobj.group('team') | |
104 | webpage = self._download_webpage(url, team) | |
105 | cat_id = self._search_regex( | |
106 | [r'var defaultCatId = "(.+?)";', | |
107 | r'{statusIndex:0,index:0,.*?id:(.*?),'], | |
25945452 | 108 | webpage, 'category id') |
91dbaef4 | 109 | playlist_title = self._html_search_regex( |
ce68b590 | 110 | r'tab0"[^>]*?>(.*?)</td>', |
25945452 | 111 | webpage, 'playlist title', flags=re.DOTALL).lower().capitalize() |
2e1fa03b | 112 | |
2e1fa03b | 113 | data = compat_urllib_parse.urlencode({ |
91dbaef4 JMF |
114 | 'cid': cat_id, |
115 | # This is the default value | |
116 | 'count': 12, | |
117 | 'ptrs': 3, | |
118 | 'format': 'json', | |
2e1fa03b | 119 | }) |
91dbaef4 JMF |
120 | path = '/videocenter/servlets/browse?' + data |
121 | request_url = compat_urlparse.urljoin(url, path) | |
122 | response = self._download_webpage(request_url, playlist_title) | |
123 | response = self._fix_json(response) | |
124 | if not response.strip(): | |
125 | self._downloader.report_warning(u'Got an empty reponse, trying ' | |
25945452 | 126 | 'adding the "newvideos" parameter') |
91dbaef4 JMF |
127 | response = self._download_webpage(request_url + '&newvideos=true', |
128 | playlist_title) | |
129 | response = self._fix_json(response) | |
130 | videos = json.loads(response) | |
2e1fa03b | 131 | |
2e1fa03b | 132 | return { |
91dbaef4 JMF |
133 | '_type': 'playlist', |
134 | 'title': playlist_title, | |
135 | 'id': cat_id, | |
25945452 | 136 | 'entries': [self._extract_video(v) for v in videos], |
2e1fa03b | 137 | } |