]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nhl.py
1 from .common
import InfoExtractor
2 from ..compat
import compat_str
11 class NHLBaseIE(InfoExtractor
):
12 def _real_extract(self
, url
):
13 site
, tmp_id
= self
._match
_valid
_url
(url
).groups()
14 video_data
= self
._download
_json
(
15 'https://%s/%s/%sid/v1/%s/details/web-v1.json'
16 % (self
._CONTENT
_DOMAIN
, site
[:3], 'item/' if site
== 'mlb' else '', tmp_id
), tmp_id
)
17 if video_data
.get('type') != 'video':
18 video_data
= video_data
['media']
19 video
= video_data
.get('video')
23 videos
= video_data
.get('videos')
25 video_data
= videos
[0]
27 video_id
= compat_str(video_data
['id'])
28 title
= video_data
['title']
31 for playback
in video_data
.get('playbacks', []):
32 playback_url
= playback
.get('url')
35 ext
= determine_ext(playback_url
)
37 m3u8_formats
= self
._extract
_m
3u8_formats
(
38 playback_url
, video_id
, 'mp4', 'm3u8_native',
39 m3u8_id
=playback
.get('name', 'hls'), fatal
=False)
40 self
._check
_formats
(m3u8_formats
, video_id
)
41 formats
.extend(m3u8_formats
)
43 height
= int_or_none(playback
.get('height'))
45 'format_id': playback
.get('name', 'http' + ('-%dp' % height
if height
else '')),
47 'width': int_or_none(playback
.get('width')),
49 'tbr': int_or_none(self
._search
_regex
(r
'_(\d+)[kK]', playback_url
, 'bitrate', default
=None)),
51 self
._sort
_formats
(formats
)
54 cuts
= video_data
.get('image', {}).get('cuts') or []
55 if isinstance(cuts
, dict):
57 for thumbnail_data
in cuts
:
58 thumbnail_url
= thumbnail_data
.get('src')
63 'width': int_or_none(thumbnail_data
.get('width')),
64 'height': int_or_none(thumbnail_data
.get('height')),
70 'description': video_data
.get('description'),
71 'timestamp': parse_iso8601(video_data
.get('date')),
72 'duration': parse_duration(video_data
.get('duration')),
73 'thumbnails': thumbnails
,
78 class NHLIE(NHLBaseIE
):
80 _VALID_URL
= r
'https?://(?:www\.)?(?P<site>nhl|wch2016)\.com/(?:[^/]+/)*c-(?P<id>\d+)'
81 _CONTENT_DOMAIN
= 'nhl.bamcontent.com'
84 'url': 'https://www.nhl.com/video/anisimov-cleans-up-mess/t-277752844/c-43663503',
85 'md5': '0f7b9a8f986fb4b4eeeece9a56416eaf',
89 'title': 'Anisimov cleans up mess',
90 'description': 'md5:a02354acdfe900e940ce40706939ca63',
91 'timestamp': 1461288600,
92 'upload_date': '20160422',
96 'url': 'https://www.nhl.com/news/dennis-wideman-suspended/c-278258934',
97 'md5': '1f39f4ea74c1394dea110699a25b366c',
101 'title': 'Wideman suspended by NHL',
102 'description': 'Flames defenseman Dennis Wideman was banned 20 games for violation of Rule 40 (Physical Abuse of Officials)',
103 'upload_date': '20160204',
104 'timestamp': 1454544904,
107 # Some m3u8 URLs are invalid (https://github.com/ytdl-org/youtube-dl/issues/10713)
108 'url': 'https://www.nhl.com/predators/video/poile-laviolette-on-subban-trade/t-277437416/c-44315003',
109 'md5': '50b2bb47f405121484dda3ccbea25459',
113 'title': 'Poile, Laviolette on Subban trade',
114 'description': 'General manager David Poile and head coach Peter Laviolette share their thoughts on acquiring P.K. Subban from Montreal (06/29/16)',
115 'timestamp': 1467242866,
116 'upload_date': '20160629',
119 'url': 'https://www.wch2016.com/video/caneur-best-of-game-2-micd-up/t-281230378/c-44983703',
120 'only_matching': True,
122 'url': 'https://www.wch2016.com/news/3-stars-team-europe-vs-team-canada/c-282195068',
123 'only_matching': True,