cbssports.py 4.7 KB

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