]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nhl.py
3 import xml
.etree
.ElementTree
5 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 data
= compat_urllib_parse
.urlencode({
26 'path': initial_video_url
.replace('.mp4', '_sd.mp4'),
28 path_url
= 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
29 path_response
= self
._download
_webpage
(path_url
, video_id
,
30 u
'Downloading final video url')
31 path_doc
= xml
.etree
.ElementTree
.fromstring(path_response
)
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>\d+)'
52 u
'url': u
'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
53 u
'file': u
'453614.mp4',
55 u
'title': u
'Quick clip: Weise 4-3 goal vs Flames',
56 u
'description': u
'Dale Weise scores his first of the season to put the Canucks up 4-3.',
58 u
'upload_date': u
'20131006',
62 def _real_extract(self
, url
):
63 mobj
= re
.match(self
._VALID
_URL
, url
)
64 video_id
= mobj
.group('id')
65 json_url
= 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
66 info_json
= self
._download
_webpage
(json_url
, video_id
,
67 u
'Downloading info json')
68 info_json
= self
._fix
_json
(info_json
)
69 info
= json
.loads(info_json
)[0]
70 return self
._extract
_video
(info
)
73 class NHLVideocenterIE(NHLBaseInfoExtractor
):
74 IE_NAME
= u
'nhl.com:videocenter'
75 IE_DESC
= u
'Download the first 12 videos from a videocenter category'
76 _VALID_URL
= r
'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[^&]+))?'
79 def suitable(cls
, url
):
80 if NHLIE
.suitable(url
):
82 return super(NHLVideocenterIE
, cls
).suitable(url
)
84 def _real_extract(self
, url
):
85 mobj
= re
.match(self
._VALID
_URL
, url
)
86 team
= mobj
.group('team')
87 webpage
= self
._download
_webpage
(url
, team
)
88 cat_id
= self
._search
_regex
(
89 [r
'var defaultCatId = "(.+?)";',
90 r
'{statusIndex:0,index:0,.*?id:(.*?),'],
91 webpage
, u
'category id')
92 playlist_title
= self
._html
_search
_regex
(
93 r
'tab0"[^>]*?>(.*?)</td>',
94 webpage
, u
'playlist title', flags
=re
.DOTALL
).lower().capitalize()
96 data
= compat_urllib_parse
.urlencode({
98 # This is the default value
103 path
= '/videocenter/servlets/browse?' + data
104 request_url
= compat_urlparse
.urljoin(url
, path
)
105 response
= self
._download
_webpage
(request_url
, playlist_title
)
106 response
= self
._fix
_json
(response
)
107 if not response
.strip():
108 self
._downloader
.report_warning(u
'Got an empty reponse, trying '
109 u
'adding the "newvideos" parameter')
110 response
= self
._download
_webpage
(request_url
+ '&newvideos=true',
112 response
= self
._fix
_json
(response
)
113 videos
= json
.loads(response
)
117 'title': playlist_title
,
119 'entries': [self
._extract
_video
(i
) for i
in videos
],