fifa.py 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. traverse_obj,
  5. unified_timestamp,
  6. )
  7. class FifaIE(InfoExtractor):
  8. _VALID_URL = r'https?://www.fifa.com/fifaplus/(?P<locale>\w{2})/watch/([^#?]+/)?(?P<id>\w+)'
  9. _TESTS = [{
  10. 'url': 'https://www.fifa.com/fifaplus/en/watch/7on10qPcnyLajDDU3ntg6y',
  11. 'info_dict': {
  12. 'id': '7on10qPcnyLajDDU3ntg6y',
  13. 'title': 'Italy v France | Final | 2006 FIFA World Cup Germany™ | Full Match Replay',
  14. 'description': 'md5:f4520d0ee80529c8ba4134a7d692ff8b',
  15. 'ext': 'mp4',
  16. 'categories': ['FIFA Tournaments'],
  17. 'thumbnail': 'https://digitalhub.fifa.com/transform/fa6f0b3e-a2e9-4cf7-9f32-53c57bcb7360/2006_Final_ITA_FRA',
  18. 'duration': 8165,
  19. },
  20. 'params': {'skip_download': 'm3u8'},
  21. }, {
  22. 'url': 'https://www.fifa.com/fifaplus/pt/watch/1cg5r5Qt6Qt12ilkDgb1sV',
  23. 'info_dict': {
  24. 'id': '1cg5r5Qt6Qt12ilkDgb1sV',
  25. 'title': 'Brazil v Germany | Semi-finals | 2014 FIFA World Cup Brazil™ | Extended Highlights',
  26. 'description': 'md5:d908c74ee66322b804ae2e521b02a855',
  27. 'ext': 'mp4',
  28. 'categories': ['FIFA Tournaments', 'Highlights'],
  29. 'thumbnail': 'https://digitalhub.fifa.com/transform/d8fe6f61-276d-4a73-a7fe-6878a35fd082/FIFAPLS_100EXTHL_2014BRAvGER_TMB',
  30. 'duration': 902,
  31. 'release_timestamp': 1404777600,
  32. 'release_date': '20140708',
  33. },
  34. 'params': {'skip_download': 'm3u8'},
  35. }, {
  36. 'url': 'https://www.fifa.com/fifaplus/fr/watch/3C6gQH9C2DLwzNx7BMRQdp',
  37. 'info_dict': {
  38. 'id': '3C6gQH9C2DLwzNx7BMRQdp',
  39. 'title': 'Josimar goal against Northern Ireland | Classic Goals',
  40. 'description': 'md5:cbe7e7bb52f603c9f1fe9a4780fe983b',
  41. 'ext': 'mp4',
  42. 'categories': ['FIFA Tournaments', 'Goal'],
  43. 'duration': 28,
  44. 'thumbnail': 'https://digitalhub.fifa.com/transform/f9301391-f8d9-48b5-823e-c093ac5e3e11/CG_MEN_1986_JOSIMAR',
  45. },
  46. 'params': {'skip_download': 'm3u8'},
  47. }]
  48. def _real_extract(self, url):
  49. video_id, locale = self._match_valid_url(url).group('id', 'locale')
  50. webpage = self._download_webpage(url, video_id)
  51. preconnect_link = self._search_regex(
  52. r'<link[^>]+rel\s*=\s*"preconnect"[^>]+href\s*=\s*"([^"]+)"', webpage, 'Preconnect Link')
  53. video_details = self._download_json(
  54. f'{preconnect_link}/sections/videoDetails/{video_id}', video_id, 'Downloading Video Details', fatal=False)
  55. preplay_parameters = self._download_json(
  56. f'{preconnect_link}/videoPlayerData/{video_id}', video_id, 'Downloading Preplay Parameters')['preplayParameters']
  57. cid = preplay_parameters['contentId']
  58. content_data = self._download_json(
  59. f'https://content.uplynk.com/preplay/{cid}/multiple.json', video_id, 'Downloading Content Data', query={
  60. 'v': preplay_parameters['preplayAPIVersion'],
  61. 'tc': preplay_parameters['tokenCheckAlgorithmVersion'],
  62. 'rn': preplay_parameters['randomNumber'],
  63. 'exp': preplay_parameters['tokenExpirationDate'],
  64. 'ct': preplay_parameters['contentType'],
  65. 'cid': cid,
  66. 'mbtracks': preplay_parameters['tracksAssetNumber'],
  67. 'ad': preplay_parameters['adConfiguration'],
  68. 'ad.preroll': int(preplay_parameters['adPreroll']),
  69. 'ad.cmsid': preplay_parameters['adCMSSourceId'],
  70. 'ad.vid': preplay_parameters['adSourceVideoID'],
  71. 'sig': preplay_parameters['signature'],
  72. })
  73. formats, subtitles = self._extract_m3u8_formats_and_subtitles(content_data['playURL'], video_id)
  74. return {
  75. 'id': video_id,
  76. 'title': video_details.get('title'),
  77. 'description': video_details.get('description'),
  78. 'duration': int_or_none(video_details.get('duration')),
  79. 'release_timestamp': unified_timestamp(video_details.get('dateOfRelease')),
  80. 'categories': traverse_obj(video_details, (('videoCategory', 'videoSubcategory'),)),
  81. 'thumbnail': traverse_obj(video_details, ('backgroundImage', 'src')),
  82. 'formats': formats,
  83. 'subtitles': subtitles,
  84. }