]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/nhl.py
Make sure it only runs rtmpdump one time in test mode and return True if the download...
[yt-dlp.git] / youtube_dl / extractor / nhl.py
CommitLineData
2e1fa03b
JMF
1import re
2import json
3import xml.etree.ElementTree
4
5from .common import InfoExtractor
6from ..utils import (
7 compat_urlparse,
8 compat_urllib_parse,
9 determine_ext,
10 unified_strdate,
11)
12
13
14class NHLIE(InfoExtractor):
15 IE_NAME = u'nhl.com'
16 _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console\?.*?(?<=[?&])id=(?P<id>\d+)'
17
18 _TEST = {
19 u'url': u'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
20 u'file': u'453614.mp4',
21 u'info_dict': {
22 u'title': u'Quick clip: Weise 4-3 goal vs Flames',
23 u'description': u'Dale Weise scores his first of the season to put the Canucks up 4-3.',
24 u'duration': 18,
25 u'upload_date': u'20131006',
26 },
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32 json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
33 info_json = self._download_webpage(json_url, video_id,
34 u'Downloading info json')
35 info_json = info_json.replace('\\\'', '\'')
36 info = json.loads(info_json)[0]
37
38 initial_video_url = info['publishPoint']
39 data = compat_urllib_parse.urlencode({
40 'type': 'fvod',
41 'path': initial_video_url.replace('.mp4', '_sd.mp4'),
42 })
43 path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
44 path_response = self._download_webpage(path_url, video_id,
45 u'Downloading final video url')
46 path_doc = xml.etree.ElementTree.fromstring(path_response)
47 video_url = path_doc.find('path').text
48
49 join = compat_urlparse.urljoin
50 return {
51 'id': video_id,
52 'title': info['name'],
53 'url': video_url,
54 'ext': determine_ext(video_url),
55 'description': info['description'],
56 'duration': int(info['duration']),
57 'thumbnail': join(join(video_url, '/u/'), info['bigImage']),
58 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]),
59 }