]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/nhl.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class NHLBaseInfoExtractor(InfoExtractor
):
17 def _fix_json(json_string
):
18 return json_string
.replace('\\\'', '\'')
20 def _extract_video(self
, info
):
22 self
.report_extraction(video_id
)
24 initial_video_url
= info
['publishPoint']
25 data
= compat_urllib_parse
.urlencode({
27 'path': initial_video_url
.replace('.mp4', '_sd.mp4'),
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
34 join
= compat_urlparse
.urljoin
37 'title': info
['name'],
39 'ext': determine_ext(video_url
),
40 'description': info
['description'],
41 'duration': int(info
['duration']),
42 'thumbnail': join(join(video_url
, '/u/'), info
['bigImage']),
43 'upload_date': unified_strdate(info
['releaseDate'].split('.')[0]),
47 class NHLIE(NHLBaseInfoExtractor
):
49 _VALID_URL
= r
'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console(?:\?(?:.*?[?&])?)id=(?P<id>[0-9]+)'
52 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
56 'title': 'Quick clip: Weise 4-3 goal vs Flames',
57 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.',
59 'upload_date': '20131006',
62 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616',
63 'only_matching': True,
66 def _real_extract(self
, url
):
67 mobj
= re
.match(self
._VALID
_URL
, url
)
68 video_id
= mobj
.group('id')
69 json_url
= 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
70 data
= self
._download
_json
(
71 json_url
, video_id
, transform_source
=self
._fix
_json
)
72 return self
._extract
_video
(data
[0])
75 class NHLVideocenterIE(NHLBaseInfoExtractor
):
76 IE_NAME
= 'nhl.com:videocenter'
77 IE_DESC
= 'NHL videocenter category'
78 _VALID_URL
= r
'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
80 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
83 'title': 'Highlights',
88 def _real_extract(self
, url
):
89 mobj
= re
.match(self
._VALID
_URL
, url
)
90 team
= mobj
.group('team')
91 webpage
= self
._download
_webpage
(url
, team
)
92 cat_id
= self
._search
_regex
(
93 [r
'var defaultCatId = "(.+?)";',
94 r
'{statusIndex:0,index:0,.*?id:(.*?),'],
95 webpage
, 'category id')
96 playlist_title
= self
._html
_search
_regex
(
97 r
'tab0"[^>]*?>(.*?)</td>',
98 webpage
, 'playlist title', flags
=re
.DOTALL
).lower().capitalize()
100 data
= compat_urllib_parse
.urlencode({
102 # This is the default value
107 path
= '/videocenter/servlets/browse?' + data
108 request_url
= compat_urlparse
.urljoin(url
, path
)
109 response
= self
._download
_webpage
(request_url
, playlist_title
)
110 response
= self
._fix
_json
(response
)
111 if not response
.strip():
112 self
._downloader
.report_warning(u
'Got an empty reponse, trying '
113 'adding the "newvideos" parameter')
114 response
= self
._download
_webpage
(request_url
+ '&newvideos=true',
116 response
= self
._fix
_json
(response
)
117 videos
= json
.loads(response
)
121 'title': playlist_title
,
123 'entries': [self
._extract
_video
(v
) for v
in videos
],