]>
Commit | Line | Data |
---|---|---|
2e1fa03b | 1 | from .common import InfoExtractor |
8865bdeb | 2 | from ..utils import ( |
29a7e8f6 | 3 | determine_ext, |
4 | int_or_none, | |
29a7e8f6 | 5 | parse_duration, |
e897bd82 | 6 | parse_iso8601, |
2e1fa03b JMF |
7 | ) |
8 | ||
9 | ||
128b58ad | 10 | class NHLBaseIE(InfoExtractor): |
e4c17d72 | 11 | def _real_extract(self, url): |
5ad28e7f | 12 | site, tmp_id = self._match_valid_url(url).groups() |
128b58ad | 13 | video_data = self._download_json( |
add96eb9 | 14 | 'https://{}/{}/{}id/v1/{}/details/web-v1.json'.format( |
15 | self._CONTENT_DOMAIN, site[:3], 'item/' if site == 'mlb' else '', tmp_id), tmp_id) | |
128b58ad RA |
16 | if video_data.get('type') != 'video': |
17 | video_data = video_data['media'] | |
18 | video = video_data.get('video') | |
19 | if video: | |
20 | video_data = video | |
21 | else: | |
22 | videos = video_data.get('videos') | |
23 | if videos: | |
24 | video_data = videos[0] | |
91dbaef4 | 25 | |
add96eb9 | 26 | video_id = str(video_data['id']) |
128b58ad | 27 | title = video_data['title'] |
91dbaef4 | 28 | |
128b58ad RA |
29 | formats = [] |
30 | for playback in video_data.get('playbacks', []): | |
31 | playback_url = playback.get('url') | |
32 | if not playback_url: | |
33 | continue | |
34 | ext = determine_ext(playback_url) | |
35 | if ext == 'm3u8': | |
36 | m3u8_formats = self._extract_m3u8_formats( | |
37 | playback_url, video_id, 'mp4', 'm3u8_native', | |
38 | m3u8_id=playback.get('name', 'hls'), fatal=False) | |
39 | self._check_formats(m3u8_formats, video_id) | |
40 | formats.extend(m3u8_formats) | |
41 | else: | |
42 | height = int_or_none(playback.get('height')) | |
43 | formats.append({ | |
add96eb9 | 44 | 'format_id': playback.get('name', 'http' + (f'-{height}p' if height else '')), |
128b58ad RA |
45 | 'url': playback_url, |
46 | 'width': int_or_none(playback.get('width')), | |
47 | 'height': height, | |
48 | 'tbr': int_or_none(self._search_regex(r'_(\d+)[kK]', playback_url, 'bitrate', default=None)), | |
49 | }) | |
2e1fa03b | 50 | |
128b58ad RA |
51 | thumbnails = [] |
52 | cuts = video_data.get('image', {}).get('cuts') or [] | |
53 | if isinstance(cuts, dict): | |
54 | cuts = cuts.values() | |
55 | for thumbnail_data in cuts: | |
56 | thumbnail_url = thumbnail_data.get('src') | |
57 | if not thumbnail_url: | |
58 | continue | |
59 | thumbnails.append({ | |
60 | 'url': thumbnail_url, | |
61 | 'width': int_or_none(thumbnail_data.get('width')), | |
62 | 'height': int_or_none(thumbnail_data.get('height')), | |
63 | }) | |
2e1fa03b | 64 | |
2e1fa03b | 65 | return { |
128b58ad RA |
66 | 'id': video_id, |
67 | 'title': title, | |
68 | 'description': video_data.get('description'), | |
69 | 'timestamp': parse_iso8601(video_data.get('date')), | |
70 | 'duration': parse_duration(video_data.get('duration')), | |
71 | 'thumbnails': thumbnails, | |
72 | 'formats': formats, | |
2e1fa03b | 73 | } |
29a7e8f6 | 74 | |
75 | ||
128b58ad | 76 | class NHLIE(NHLBaseIE): |
29a7e8f6 | 77 | IE_NAME = 'nhl.com' |
ee5de4e3 | 78 | _VALID_URL = r'https?://(?:www\.)?(?P<site>nhl|wch2016)\.com/(?:[^/]+/)*c-(?P<id>\d+)' |
128b58ad | 79 | _CONTENT_DOMAIN = 'nhl.bamcontent.com' |
29a7e8f6 | 80 | _TESTS = [{ |
81 | # type=video | |
82 | 'url': 'https://www.nhl.com/video/anisimov-cleans-up-mess/t-277752844/c-43663503', | |
83 | 'md5': '0f7b9a8f986fb4b4eeeece9a56416eaf', | |
84 | 'info_dict': { | |
85 | 'id': '43663503', | |
86 | 'ext': 'mp4', | |
87 | 'title': 'Anisimov cleans up mess', | |
88 | 'description': 'md5:a02354acdfe900e940ce40706939ca63', | |
89 | 'timestamp': 1461288600, | |
90 | 'upload_date': '20160422', | |
91 | }, | |
92 | }, { | |
93 | # type=article | |
94 | 'url': 'https://www.nhl.com/news/dennis-wideman-suspended/c-278258934', | |
95 | 'md5': '1f39f4ea74c1394dea110699a25b366c', | |
96 | 'info_dict': { | |
97 | 'id': '40784403', | |
98 | 'ext': 'mp4', | |
99 | 'title': 'Wideman suspended by NHL', | |
100 | 'description': 'Flames defenseman Dennis Wideman was banned 20 games for violation of Rule 40 (Physical Abuse of Officials)', | |
101 | 'upload_date': '20160204', | |
102 | 'timestamp': 1454544904, | |
103 | }, | |
55642487 | 104 | }, { |
067aa17e | 105 | # Some m3u8 URLs are invalid (https://github.com/ytdl-org/youtube-dl/issues/10713) |
55642487 YCH |
106 | 'url': 'https://www.nhl.com/predators/video/poile-laviolette-on-subban-trade/t-277437416/c-44315003', |
107 | 'md5': '50b2bb47f405121484dda3ccbea25459', | |
108 | 'info_dict': { | |
109 | 'id': '44315003', | |
110 | 'ext': 'mp4', | |
111 | 'title': 'Poile, Laviolette on Subban trade', | |
112 | 'description': 'General manager David Poile and head coach Peter Laviolette share their thoughts on acquiring P.K. Subban from Montreal (06/29/16)', | |
113 | 'timestamp': 1467242866, | |
114 | 'upload_date': '20160629', | |
115 | }, | |
ee5de4e3 S |
116 | }, { |
117 | 'url': 'https://www.wch2016.com/video/caneur-best-of-game-2-micd-up/t-281230378/c-44983703', | |
118 | 'only_matching': True, | |
119 | }, { | |
120 | 'url': 'https://www.wch2016.com/news/3-stars-team-europe-vs-team-canada/c-282195068', | |
121 | 'only_matching': True, | |
29a7e8f6 | 122 | }] |