]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/cbssports.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / cbssports.py
1 # from .cbs import CBSBaseIE
2 from .common import InfoExtractor
3 from ..utils import (
4 int_or_none,
5 try_get,
6 )
7
8
9 # class CBSSportsEmbedIE(CBSBaseIE):
10 class CBSSportsEmbedIE(InfoExtractor):
11 _WORKING = False
12 IE_NAME = 'cbssports:embed'
13 _VALID_URL = r'''(?ix)https?://(?:(?:www\.)?cbs|embed\.247)sports\.com/player/embed.+?
14 (?:
15 ids%3D(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})|
16 pcid%3D(?P<pcid>\d+)
17 )'''
18 _TESTS = [{
19 'url': 'https://www.cbssports.com/player/embed/?args=player_id%3Db56c03a6-231a-4bbe-9c55-af3c8a8e9636%26ids%3Db56c03a6-231a-4bbe-9c55-af3c8a8e9636%26resizable%3D1%26autoplay%3Dtrue%26domain%3Dcbssports.com%26comp_ads_enabled%3Dfalse%26watchAndRead%3D0%26startTime%3D0%26env%3Dprod',
20 'only_matching': True,
21 }, {
22 'url': 'https://embed.247sports.com/player/embed/?args=%3fplayer_id%3d1827823171591%26channel%3dcollege-football-recruiting%26pcid%3d1827823171591%26width%3d640%26height%3d360%26autoplay%3dTrue%26comp_ads_enabled%3dFalse%26uvpc%3dhttps%253a%252f%252fwww.cbssports.com%252fapi%252fcontent%252fvideo%252fconfig%252f%253fcfg%253duvp_247sports_v4%2526partner%253d247%26uvpc_m%3dhttps%253a%252f%252fwww.cbssports.com%252fapi%252fcontent%252fvideo%252fconfig%252f%253fcfg%253duvp_247sports_m_v4%2526partner_m%253d247_mobile%26utag%3d247sportssite%26resizable%3dTrue',
23 'only_matching': True,
24 }]
25
26 # def _extract_video_info(self, filter_query, video_id):
27 # return self._extract_feed_info('dJ5BDC', 'VxxJg8Ymh8sE', filter_query, video_id)
28
29 def _real_extract(self, url):
30 uuid, pcid = self._match_valid_url(url).groups()
31 query = {'id': uuid} if uuid else {'pcid': pcid}
32 video = self._download_json(
33 'https://www.cbssports.com/api/content/video/',
34 uuid or pcid, query=query)[0]
35 video_id = video['id']
36 title = video['title']
37 metadata = video.get('metaData') or {}
38 # return self._extract_video_info('byId=%d' % metadata['mpxOutletId'], video_id)
39 # return self._extract_video_info('byGuid=' + metadata['mpxRefId'], video_id)
40
41 formats = self._extract_m3u8_formats(
42 metadata['files'][0]['url'], video_id, 'mp4',
43 'm3u8_native', m3u8_id='hls', fatal=False)
44
45 image = video.get('image')
46 thumbnails = None
47 if image:
48 image_path = image.get('path')
49 if image_path:
50 thumbnails = [{
51 'url': image_path,
52 'width': int_or_none(image.get('width')),
53 'height': int_or_none(image.get('height')),
54 'filesize': int_or_none(image.get('size')),
55 }]
56
57 return {
58 'id': video_id,
59 'title': title,
60 'formats': formats,
61 'thumbnails': thumbnails,
62 'description': video.get('description'),
63 'timestamp': int_or_none(try_get(video, lambda x: x['dateCreated']['epoch'])),
64 'duration': int_or_none(metadata.get('duration')),
65 }
66
67
68 class CBSSportsBaseIE(InfoExtractor):
69 def _real_extract(self, url):
70 display_id = self._match_id(url)
71 webpage = self._download_webpage(url, display_id)
72 iframe_url = self._search_regex(
73 r'<iframe[^>]+(?:data-)?src="(https?://[^/]+/player/embed[^"]+)"',
74 webpage, 'embed url')
75 return self.url_result(iframe_url, CBSSportsEmbedIE.ie_key())
76
77
78 class CBSSportsIE(CBSSportsBaseIE):
79 _WORKING = False
80 IE_NAME = 'cbssports'
81 _VALID_URL = r'https?://(?:www\.)?cbssports\.com/[^/]+/video/(?P<id>[^/?#&]+)'
82 _TESTS = [{
83 'url': 'https://www.cbssports.com/college-football/video/cover-3-stanford-spring-gleaning/',
84 'info_dict': {
85 'id': 'b56c03a6-231a-4bbe-9c55-af3c8a8e9636',
86 'ext': 'mp4',
87 'title': 'Cover 3: Stanford Spring Gleaning',
88 'description': 'The Cover 3 crew break down everything you need to know about the Stanford Cardinal this spring.',
89 'timestamp': 1617218398,
90 'upload_date': '20210331',
91 'duration': 502,
92 },
93 }]
94
95
96 class TwentyFourSevenSportsIE(CBSSportsBaseIE):
97 _WORKING = False
98 IE_NAME = '247sports'
99 _VALID_URL = r'https?://(?:www\.)?247sports\.com/Video/(?:[^/?#&]+-)?(?P<id>\d+)'
100 _TESTS = [{
101 'url': 'https://247sports.com/Video/2021-QB-Jake-Garcia-senior-highlights-through-five-games-10084854/',
102 'info_dict': {
103 'id': '4f1265cb-c3b5-44a8-bb1d-1914119a0ccc',
104 'ext': 'mp4',
105 'title': '2021 QB Jake Garcia senior highlights through five games',
106 'description': 'md5:8cb67ebed48e2e6adac1701e0ff6e45b',
107 'timestamp': 1607114223,
108 'upload_date': '20201204',
109 'duration': 208,
110 },
111 }]