1 from __future__
import unicode_literals
7 from .common
import InfoExtractor
11 compat_urllib_parse_urlparse
18 class NHLBaseInfoExtractor(InfoExtractor
):
20 def _fix_json(json_string
):
21 return json_string
.replace('\\\'', '\'')
23 def _extract_video(self
, info
):
25 self
.report_extraction(video_id
)
27 initial_video_url
= info
['publishPoint']
28 if info
['formats'] == '1':
29 parsed_url
= compat_urllib_parse_urlparse(initial_video_url
)
30 filename
, ext
= os
.path
.splitext(parsed_url
.path
)
31 path
= '%s_sd%s' % (filename
, ext
)
32 data
= compat_urllib_parse
.urlencode({
34 'path': compat_urlparse
.urlunparse(parsed_url
[:2] + (path
,) + parsed_url
[3:])
36 path_url
= 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
37 path_doc
= self
._download
_xml
(
38 path_url
, video_id
, 'Downloading final video url')
39 video_url
= path_doc
.find('path').text
41 video_url
= initial_video_url
43 join
= compat_urlparse
.urljoin
46 'title': info
['name'],
48 'description': info
['description'],
49 'duration': int(info
['duration']),
50 'thumbnail': join(join(video_url
, '/u/'), info
['bigImage']),
51 'upload_date': unified_strdate(info
['releaseDate'].split('.')[0]),
55 class NHLIE(NHLBaseInfoExtractor
):
57 _VALID_URL
= r
'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)'
60 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
61 'md5': 'db704a4ea09e8d3988c85e36cc892d09',
65 'title': 'Quick clip: Weise 4-3 goal vs Flames',
66 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.',
68 'upload_date': '20131006',
71 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h',
72 'md5': 'd22e82bc592f52d37d24b03531ee9696',
74 'id': '2014020024-628-h',
76 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)',
77 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014',
79 'upload_date': '20141011',
82 'url': 'http://video.mapleleafs.nhl.com/videocenter/console?id=58665&catid=802',
83 'md5': 'c78fc64ea01777e426cfc202b746c825',
87 'title': 'Classic Game In Six - April 22, 1979',
88 '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.',
90 'upload_date': '20100129'
93 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616',
94 'only_matching': True,
97 def _real_extract(self
, url
):
98 mobj
= re
.match(self
._VALID
_URL
, url
)
99 video_id
= mobj
.group('id')
100 json_url
= 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
101 data
= self
._download
_json
(
102 json_url
, video_id
, transform_source
=self
._fix
_json
)
103 return self
._extract
_video
(data
[0])
106 class NHLVideocenterIE(NHLBaseInfoExtractor
):
107 IE_NAME
= 'nhl.com:videocenter'
108 IE_DESC
= 'NHL videocenter category'
109 _VALID_URL
= r
'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?[^(id=)]*catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
111 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
114 'title': 'Highlights',
116 'playlist_count': 12,
119 def _real_extract(self
, url
):
120 mobj
= re
.match(self
._VALID
_URL
, url
)
121 team
= mobj
.group('team')
122 webpage
= self
._download
_webpage
(url
, team
)
123 cat_id
= self
._search
_regex
(
124 [r
'var defaultCatId = "(.+?)";',
125 r
'{statusIndex:0,index:0,.*?id:(.*?),'],
126 webpage
, 'category id')
127 playlist_title
= self
._html
_search
_regex
(
128 r
'tab0"[^>]*?>(.*?)</td>',
129 webpage
, 'playlist title', flags
=re
.DOTALL
).lower().capitalize()
131 data
= compat_urllib_parse
.urlencode({
133 # This is the default value
138 path
= '/videocenter/servlets/browse?' + data
139 request_url
= compat_urlparse
.urljoin(url
, path
)
140 response
= self
._download
_webpage
(request_url
, playlist_title
)
141 response
= self
._fix
_json
(response
)
142 if not response
.strip():
143 self
._downloader
.report_warning('Got an empty reponse, trying '
144 'adding the "newvideos" parameter')
145 response
= self
._download
_webpage
(request_url
+ '&newvideos=true',
147 response
= self
._fix
_json
(response
)
148 videos
= json
.loads(response
)
152 'title': playlist_title
,
154 'entries': [self
._extract
_video
(v
) for v
in videos
],