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 _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]) 
  29     def _extract_video(self
, info
): 
  31         self
.report_extraction(video_id
) 
  33         initial_video_url 
= info
['publishPoint'] 
  34         if info
['formats'] == '1': 
  35             parsed_url 
= compat_urllib_parse_urlparse(initial_video_url
) 
  36             filename
, ext 
= os
.path
.splitext(parsed_url
.path
) 
  37             path 
= '%s_sd%s' % (filename
, ext
) 
  38             data 
= compat_urllib_parse
.urlencode({ 
  40                 'path': compat_urlparse
.urlunparse(parsed_url
[:2] + (path
,) + parsed_url
[3:]) 
  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
 
  47             video_url 
= initial_video_url
 
  49         join 
= compat_urlparse
.urljoin
 
  52             'title': info
['name'], 
  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]), 
  61 class NHLIE(NHLBaseInfoExtractor
): 
  63     _VALID_URL 
= r
'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/(?:console)?(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)' 
  66         'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614', 
  67         'md5': 'db704a4ea09e8d3988c85e36cc892d09', 
  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.', 
  74             'upload_date': '20131006', 
  77         'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h', 
  78         'md5': 'd22e82bc592f52d37d24b03531ee9696', 
  80             'id': '2014020024-628-h', 
  82             'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)', 
  83             'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014', 
  85             'upload_date': '20141011', 
  88         'url': 'http://video.mapleleafs.nhl.com/videocenter/console?id=58665&catid=802', 
  89         'md5': 'c78fc64ea01777e426cfc202b746c825', 
  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.', 
  96             'upload_date': '20100129' 
  99         'url': 'http://video.flames.nhl.com/videocenter/console?id=630616', 
 100         'only_matching': True, 
 102         'url': 'http://video.nhl.com/videocenter/?id=736722', 
 103         'only_matching': True, 
 106     def _real_extract(self
, url
): 
 107         video_id 
= self
._match
_id
(url
) 
 108         return self
._real
_extract
_video
(video_id
) 
 111 class NHLNewsIE(NHLBaseInfoExtractor
): 
 112     IE_NAME 
= 'nhl.com:news' 
 114     _VALID_URL 
= r
'https?://(?:www\.)?nhl\.com/ice/news\.html?(?:\?(?:.*?[?&])?)id=(?P<id>[-0-9a-zA-Z]+)' 
 117         'url': 'http://www.nhl.com/ice/news.htm?id=750727', 
 118         'md5': '4b3d1262e177687a3009937bd9ec0be8', 
 122             'title': 'Cal Clutterbuck has been fined $2,000', 
 123             'description': 'md5:45fe547d30edab88b23e0dd0ab1ed9e6', 
 125             'upload_date': '20150128', 
 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+)'"], 
 135         return self
._real
_extract
_video
(video_id
) 
 138 class NHLVideocenterIE(NHLBaseInfoExtractor
): 
 139     IE_NAME 
= 'nhl.com:videocenter' 
 140     IE_DESC 
= 'NHL videocenter category' 
 141     _VALID_URL 
= r
'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?[^(id=)]*catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$' 
 143         'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999', 
 146             'title': 'Highlights', 
 148         'playlist_count': 12, 
 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:(.*?),'], 
 158             webpage
, 'category id') 
 159         playlist_title 
= self
._html
_search
_regex
( 
 160             r
'tab0"[^>]*?>(.*?)</td>', 
 161             webpage
, 'playlist title', flags
=re
.DOTALL
).lower().capitalize() 
 163         data 
= compat_urllib_parse
.urlencode({ 
 165             # This is the default value 
 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(): 
 175             self
._downloader
.report_warning('Got an empty reponse, trying ' 
 176                                             'adding the "newvideos" parameter') 
 177             response 
= self
._download
_webpage
(request_url 
+ '&newvideos=true', 
 179             response 
= self
._fix
_json
(response
) 
 180         videos 
= json
.loads(response
) 
 184             'title': playlist_title
, 
 186             'entries': [self
._extract
_video
(v
) for v 
in videos
],