]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/nfl.py
[extractor/generic] Decode unicode-escaped embed URLs (#5919)
[yt-dlp.git] / yt_dlp / extractor / nfl.py
CommitLineData
632e5684
NJ
1import re
2
3from .common import InfoExtractor
4from ..utils import (
29f7c58a 5 clean_html,
6 determine_ext,
7 get_element_by_class,
632e5684
NJ
8)
9
10
29f7c58a 11class NFLBaseIE(InfoExtractor):
12 _VALID_URL_BASE = r'''(?x)
5b4c5463
S
13 https?://
14 (?P<host>
15 (?:www\.)?
16 (?:
17 (?:
18 nfl|
19 buffalobills|
20 miamidolphins|
21 patriots|
22 newyorkjets|
23 baltimoreravens|
24 bengals|
25 clevelandbrowns|
26 steelers|
27 houstontexans|
28 colts|
29 jaguars|
29f7c58a 30 (?:titansonline|tennesseetitans)|
5b4c5463 31 denverbroncos|
29f7c58a 32 (?:kc)?chiefs|
5b4c5463
S
33 raiders|
34 chargers|
35 dallascowboys|
36 giants|
37 philadelphiaeagles|
29f7c58a 38 (?:redskins|washingtonfootball)|
5b4c5463
S
39 chicagobears|
40 detroitlions|
41 packers|
42 vikings|
43 atlantafalcons|
44 panthers|
45 neworleanssaints|
46 buccaneers|
47 azcardinals|
29f7c58a 48 (?:stlouis|the)rams|
5b4c5463
S
49 49ers|
50 seahawks
51 )\.com|
52 .+?\.clubs\.nfl\.com
53 )
54 )/
5b4c5463 55 '''
dd4411aa 56 _VIDEO_CONFIG_REGEX = r'<script[^>]+id="[^"]*video-config-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}[^"]*"[^>]*>\s*({.+});?\s*</script>'
29f7c58a 57
58 def _parse_video_config(self, video_config, display_id):
59 video_config = self._parse_json(video_config, display_id)
60 item = video_config['playlist'][0]
61 mcp_id = item.get('mcpID')
62 if mcp_id:
63 info = self.url_result(
64 'anvato:GXvEgwyJeWem8KCYXfeoHWknwP48Mboj:' + mcp_id,
65 'Anvato', mcp_id)
66 else:
67 media_id = item.get('id') or item['entityId']
dd4411aa 68 title = item.get('title')
29f7c58a 69 item_url = item['url']
70 info = {'id': media_id}
71 ext = determine_ext(item_url)
72 if ext == 'm3u8':
73 info['formats'] = self._extract_m3u8_formats(item_url, media_id, 'mp4')
29f7c58a 74 else:
75 info['url'] = item_url
76 if item.get('audio') is True:
77 info['vcodec'] = 'none'
78 is_live = video_config.get('live') is True
79 thumbnails = None
80 image_url = item.get(item.get('imageSrc')) or item.get(item.get('posterImage'))
81 if image_url:
82 thumbnails = [{
83 'url': image_url,
84 'ext': determine_ext(image_url, 'jpg'),
85 }]
86 info.update({
39ca3b5c 87 'title': title,
29f7c58a 88 'is_live': is_live,
89 'description': clean_html(item.get('description')),
90 'thumbnails': thumbnails,
91 })
92 return info
93
94
95class NFLIE(NFLBaseIE):
96 IE_NAME = 'nfl.com'
97 _VALID_URL = NFLBaseIE._VALID_URL_BASE + r'(?:videos?|listen|audio)/(?P<id>[^/#?&]+)'
5b4c5463 98 _TESTS = [{
29f7c58a 99 'url': 'https://www.nfl.com/videos/baker-mayfield-s-game-changing-plays-from-3-td-game-week-14',
5b4c5463 100 'info_dict': {
29f7c58a 101 'id': '899441',
5b4c5463 102 'ext': 'mp4',
29f7c58a 103 'title': "Baker Mayfield's game-changing plays from 3-TD game Week 14",
104 'description': 'md5:85e05a3cc163f8c344340f220521136d',
105 'upload_date': '20201215',
106 'timestamp': 1608009755,
ec85ded8 107 'thumbnail': r're:^https?://.*\.jpg$',
29f7c58a 108 'uploader': 'NFL',
dd4411aa 109 'tags': 'count:6',
110 'duration': 157,
111 'categories': 'count:3',
7ebd5376 112 }
5b4c5463 113 }, {
29f7c58a 114 'url': 'https://www.chiefs.com/listen/patrick-mahomes-travis-kelce-react-to-win-over-dolphins-the-breakdown',
115 'md5': '6886b32c24b463038c760ceb55a34566',
5b4c5463 116 'info_dict': {
29f7c58a 117 'id': 'd87e8790-3e14-11eb-8ceb-ff05c2867f99',
118 'ext': 'mp3',
119 'title': 'Patrick Mahomes, Travis Kelce React to Win Over Dolphins | The Breakdown',
120 'description': 'md5:12ada8ee70e6762658c30e223e095075',
dd4411aa 121 },
122 'skip': 'HTTP Error 404: Not Found',
5b4c5463 123 }, {
29f7c58a 124 'url': 'https://www.buffalobills.com/video/buffalo-bills-military-recognition-week-14',
5b4c5463
S
125 'only_matching': True,
126 }, {
29f7c58a 127 'url': 'https://www.raiders.com/audio/instant-reactions-raiders-week-14-loss-to-indianapolis-colts-espn-jason-fitz',
5b4c5463
S
128 'only_matching': True,
129 }]
5f4c3188 130
632e5684 131 def _real_extract(self, url):
29f7c58a 132 display_id = self._match_id(url)
133 webpage = self._download_webpage(url, display_id)
134 return self._parse_video_config(self._search_regex(
135 self._VIDEO_CONFIG_REGEX, webpage, 'video config'), display_id)
5f4c3188 136
632e5684 137
29f7c58a 138class NFLArticleIE(NFLBaseIE):
139 IE_NAME = 'nfl.com:article'
140 _VALID_URL = NFLBaseIE._VALID_URL_BASE + r'news/(?P<id>[^/#?&]+)'
141 _TEST = {
142 'url': 'https://www.buffalobills.com/news/the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
143 'info_dict': {
144 'id': 'the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
145 'title': "'The only thing we've earned is the noise' | Bills coaches discuss handling rising expectations",
146 },
147 'playlist_count': 4,
148 }
632e5684 149
29f7c58a 150 def _real_extract(self, url):
151 display_id = self._match_id(url)
152 webpage = self._download_webpage(url, display_id)
153 entries = []
154 for video_config in re.findall(self._VIDEO_CONFIG_REGEX, webpage):
155 entries.append(self._parse_video_config(video_config, display_id))
156 title = clean_html(get_element_by_class(
157 'nfl-c-article__title', webpage)) or self._html_search_meta(
158 ['og:title', 'twitter:title'], webpage)
159 return self.playlist_result(entries, display_id, title)