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