]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nhl.py
82af6e33098eaa9018c6f58b93b4e8b4c9cff399
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class NHLBaseInfoExtractor(InfoExtractor
):
16 def _fix_json(json_string
):
17 return json_string
.replace('\\\'', '\'')
19 def _extract_video(self
, info
):
21 self
.report_extraction(video_id
)
23 initial_video_url
= info
['publishPoint']
24 if info
['formats'] == '1':
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 video_url
= initial_video_url
36 join
= compat_urlparse
.urljoin
39 'title': info
['name'],
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]),
48 class NHLIE(NHLBaseInfoExtractor
):
50 _VALID_URL
= r
'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console(?:\?(?:.*?[?&])?)id=(?P<id>[0-9a-z-]+)'
53 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
54 'md5': 'db704a4ea09e8d3988c85e36cc892d09',
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.',
61 'upload_date': '20131006',
64 'url': 'http://video.nhl.com/videocenter/console?id=2014020024-628-h',
65 'md5': 'd22e82bc592f52d37d24b03531ee9696',
67 'id': '2014020024-628-h',
69 'title': 'Alex Galchenyuk Goal on Ray Emery (14:40/3rd)',
70 'description': 'Home broadcast - Montreal Canadiens at Philadelphia Flyers - October 11, 2014',
72 'upload_date': '20141011',
75 'url': 'http://video.flames.nhl.com/videocenter/console?id=630616',
76 'only_matching': True,
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
83 data
= self
._download
_json
(
84 json_url
, video_id
, transform_source
=self
._fix
_json
)
85 return self
._extract
_video
(data
[0])
88 class NHLVideocenterIE(NHLBaseInfoExtractor
):
89 IE_NAME
= 'nhl.com:videocenter'
90 IE_DESC
= 'NHL videocenter category'
91 _VALID_URL
= r
'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
93 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
96 'title': 'Highlights',
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:(.*?),'],
108 webpage
, 'category id')
109 playlist_title
= self
._html
_search
_regex
(
110 r
'tab0"[^>]*?>(.*?)</td>',
111 webpage
, 'playlist title', flags
=re
.DOTALL
).lower().capitalize()
113 data
= compat_urllib_parse
.urlencode({
115 # This is the default value
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 '
126 'adding the "newvideos" parameter')
127 response
= self
._download
_webpage
(request_url
+ '&newvideos=true',
129 response
= self
._fix
_json
(response
)
130 videos
= json
.loads(response
)
134 'title': playlist_title
,
136 'entries': [self
._extract
_video
(v
) for v
in videos
],