]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nhl.py
2edd806a3f6aa12792f3c8d8065a57fd2e2e70a1
4 from .common
import InfoExtractor
13 class NHLBaseInfoExtractor(InfoExtractor
):
15 def _fix_json(json_string
):
16 return json_string
.replace('\\\'', '\'')
18 def _extract_video(self
, info
):
20 self
.report_extraction(video_id
)
22 initial_video_url
= info
['publishPoint']
23 data
= compat_urllib_parse
.urlencode({
25 'path': initial_video_url
.replace('.mp4', '_sd.mp4'),
27 path_url
= 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
28 path_doc
= self
._download
_xml
(path_url
, video_id
,
29 u
'Downloading final video url')
30 video_url
= path_doc
.find('path').text
32 join
= compat_urlparse
.urljoin
35 'title': info
['name'],
37 'ext': determine_ext(video_url
),
38 'description': info
['description'],
39 'duration': int(info
['duration']),
40 'thumbnail': join(join(video_url
, '/u/'), info
['bigImage']),
41 'upload_date': unified_strdate(info
['releaseDate'].split('.')[0]),
45 class NHLIE(NHLBaseInfoExtractor
):
47 _VALID_URL
= r
'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console\?.*?(?<=[?&])id=(?P<id>\d+)'
50 u
'url': u
'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
51 u
'file': u
'453614.mp4',
53 u
'title': u
'Quick clip: Weise 4-3 goal vs Flames',
54 u
'description': u
'Dale Weise scores his first of the season to put the Canucks up 4-3.',
56 u
'upload_date': u
'20131006',
60 def _real_extract(self
, url
):
61 mobj
= re
.match(self
._VALID
_URL
, url
)
62 video_id
= mobj
.group('id')
63 json_url
= 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
64 info_json
= self
._download
_webpage
(json_url
, video_id
,
65 u
'Downloading info json')
66 info_json
= self
._fix
_json
(info_json
)
67 info
= json
.loads(info_json
)[0]
68 return self
._extract
_video
(info
)
71 class NHLVideocenterIE(NHLBaseInfoExtractor
):
72 IE_NAME
= u
'nhl.com:videocenter'
73 IE_DESC
= u
'NHL videocenter category'
74 _VALID_URL
= r
'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[^&]+))?'
77 def suitable(cls
, url
):
78 if NHLIE
.suitable(url
):
80 return super(NHLVideocenterIE
, cls
).suitable(url
)
82 def _real_extract(self
, url
):
83 mobj
= re
.match(self
._VALID
_URL
, url
)
84 team
= mobj
.group('team')
85 webpage
= self
._download
_webpage
(url
, team
)
86 cat_id
= self
._search
_regex
(
87 [r
'var defaultCatId = "(.+?)";',
88 r
'{statusIndex:0,index:0,.*?id:(.*?),'],
89 webpage
, u
'category id')
90 playlist_title
= self
._html
_search
_regex
(
91 r
'tab0"[^>]*?>(.*?)</td>',
92 webpage
, u
'playlist title', flags
=re
.DOTALL
).lower().capitalize()
94 data
= compat_urllib_parse
.urlencode({
96 # This is the default value
101 path
= '/videocenter/servlets/browse?' + data
102 request_url
= compat_urlparse
.urljoin(url
, path
)
103 response
= self
._download
_webpage
(request_url
, playlist_title
)
104 response
= self
._fix
_json
(response
)
105 if not response
.strip():
106 self
._downloader
.report_warning(u
'Got an empty reponse, trying '
107 u
'adding the "newvideos" parameter')
108 response
= self
._download
_webpage
(request_url
+ '&newvideos=true',
110 response
= self
._fix
_json
(response
)
111 videos
= json
.loads(response
)
115 'title': playlist_title
,
117 'entries': [self
._extract
_video
(i
) for i
in videos
],