]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nhl.py
cf440f713c274ab96e61927c4f303e51abcdca12
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
15 class NHLBaseIE(InfoExtractor
):
16 def _real_extract(self
, url
):
17 site
, tmp_id
= re
.match(self
._VALID
_URL
, url
).groups()
18 video_data
= self
._download
_json
(
19 'https://%s/%s/%sid/v1/%s/details/web-v1.json'
20 % (self
._CONTENT
_DOMAIN
, site
[:3], 'item/' if site
== 'mlb' else '', tmp_id
), tmp_id
)
21 if video_data
.get('type') != 'video':
22 video_data
= video_data
['media']
23 video
= video_data
.get('video')
27 videos
= video_data
.get('videos')
29 video_data
= videos
[0]
31 video_id
= compat_str(video_data
['id'])
32 title
= video_data
['title']
35 for playback
in video_data
.get('playbacks', []):
36 playback_url
= playback
.get('url')
39 ext
= determine_ext(playback_url
)
41 m3u8_formats
= self
._extract
_m
3u8_formats
(
42 playback_url
, video_id
, 'mp4', 'm3u8_native',
43 m3u8_id
=playback
.get('name', 'hls'), fatal
=False)
44 self
._check
_formats
(m3u8_formats
, video_id
)
45 formats
.extend(m3u8_formats
)
47 height
= int_or_none(playback
.get('height'))
49 'format_id': playback
.get('name', 'http' + ('-%dp' % height
if height
else '')),
51 'width': int_or_none(playback
.get('width')),
53 'tbr': int_or_none(self
._search
_regex
(r
'_(\d+)[kK]', playback_url
, 'bitrate', default
=None)),
55 self
._sort
_formats
(formats
)
58 cuts
= video_data
.get('image', {}).get('cuts') or []
59 if isinstance(cuts
, dict):
61 for thumbnail_data
in cuts
:
62 thumbnail_url
= thumbnail_data
.get('src')
67 'width': int_or_none(thumbnail_data
.get('width')),
68 'height': int_or_none(thumbnail_data
.get('height')),
74 'description': video_data
.get('description'),
75 'timestamp': parse_iso8601(video_data
.get('date')),
76 'duration': parse_duration(video_data
.get('duration')),
77 'thumbnails': thumbnails
,
82 class NHLIE(NHLBaseIE
):
84 _VALID_URL
= r
'https?://(?:www\.)?(?P<site>nhl|wch2016)\.com/(?:[^/]+/)*c-(?P<id>\d+)'
85 _CONTENT_DOMAIN
= 'nhl.bamcontent.com'
88 'url': 'https://www.nhl.com/video/anisimov-cleans-up-mess/t-277752844/c-43663503',
89 'md5': '0f7b9a8f986fb4b4eeeece9a56416eaf',
93 'title': 'Anisimov cleans up mess',
94 'description': 'md5:a02354acdfe900e940ce40706939ca63',
95 'timestamp': 1461288600,
96 'upload_date': '20160422',
100 'url': 'https://www.nhl.com/news/dennis-wideman-suspended/c-278258934',
101 'md5': '1f39f4ea74c1394dea110699a25b366c',
105 'title': 'Wideman suspended by NHL',
106 'description': 'Flames defenseman Dennis Wideman was banned 20 games for violation of Rule 40 (Physical Abuse of Officials)',
107 'upload_date': '20160204',
108 'timestamp': 1454544904,
111 # Some m3u8 URLs are invalid (https://github.com/rg3/youtube-dl/issues/10713)
112 'url': 'https://www.nhl.com/predators/video/poile-laviolette-on-subban-trade/t-277437416/c-44315003',
113 'md5': '50b2bb47f405121484dda3ccbea25459',
117 'title': 'Poile, Laviolette on Subban trade',
118 'description': 'General manager David Poile and head coach Peter Laviolette share their thoughts on acquiring P.K. Subban from Montreal (06/29/16)',
119 'timestamp': 1467242866,
120 'upload_date': '20160629',
123 'url': 'https://www.wch2016.com/video/caneur-best-of-game-2-micd-up/t-281230378/c-44983703',
124 'only_matching': True,
126 'url': 'https://www.wch2016.com/news/3-stars-team-europe-vs-team-canada/c-282195068',
127 'only_matching': True,