fifa.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/135e2656-3a51-407b-8810-6c34bec5b59b/FMR_2006_Italy_France_Final_Hero',
  18. 'duration': 8165,
  19. 'release_timestamp': 1152403200,
  20. 'release_date': '20060709',
  21. },
  22. 'params': {'skip_download': 'm3u8'},
  23. }, {
  24. 'url': 'https://www.fifa.com/fifaplus/pt/watch/1cg5r5Qt6Qt12ilkDgb1sV',
  25. 'info_dict': {
  26. 'id': '1cg5r5Qt6Qt12ilkDgb1sV',
  27. 'title': 'Brazil v Germany | Semi-finals | 2014 FIFA World Cup Brazil™ | Extended Highlights',
  28. 'description': 'md5:d908c74ee66322b804ae2e521b02a855',
  29. 'ext': 'mp4',
  30. 'categories': ['FIFA Tournaments', 'Highlights'],
  31. 'thumbnail': 'https://digitalhub.fifa.com/transform/d8fe6f61-276d-4a73-a7fe-6878a35fd082/FIFAPLS_100EXTHL_2014BRAvGER_TMB',
  32. 'duration': 902,
  33. 'release_timestamp': 1404777600,
  34. 'release_date': '20140708',
  35. },
  36. 'params': {'skip_download': 'm3u8'},
  37. }, {
  38. 'url': 'https://www.fifa.com/fifaplus/fr/watch/3C6gQH9C2DLwzNx7BMRQdp',
  39. 'info_dict': {
  40. 'id': '3C6gQH9C2DLwzNx7BMRQdp',
  41. 'title': 'Josimar goal against Northern Ireland | Classic Goals',
  42. 'description': 'md5:cbe7e7bb52f603c9f1fe9a4780fe983b',
  43. 'ext': 'mp4',
  44. 'categories': ['FIFA Tournaments', 'Goal'],
  45. 'duration': 28,
  46. 'thumbnail': 'https://digitalhub.fifa.com/transform/f9301391-f8d9-48b5-823e-c093ac5e3e11/CG_MEN_1986_JOSIMAR',
  47. },
  48. 'params': {'skip_download': 'm3u8'},
  49. }]
  50. def _real_extract(self, url):
  51. video_id, locale = self._match_valid_url(url).group('id', 'locale')
  52. webpage = self._download_webpage(url, video_id)
  53. preconnect_link = self._search_regex(
  54. r'<link\b[^>]+\brel\s*=\s*"preconnect"[^>]+href\s*=\s*"([^"]+)"', webpage, 'Preconnect Link')
  55. video_details = self._download_json(
  56. f'{preconnect_link}/sections/videoDetails/{video_id}', video_id, 'Downloading Video Details', fatal=False)
  57. preplay_parameters = self._download_json(
  58. f'{preconnect_link}/videoPlayerData/{video_id}', video_id, 'Downloading Preplay Parameters')['preplayParameters']
  59. content_data = self._download_json(
  60. 'https://content.uplynk.com/preplay/{contentId}/multiple.json?{queryStr}&sig={signature}'.format(**preplay_parameters),
  61. video_id, 'Downloading Content Data')
  62. formats, subtitles = self._extract_m3u8_formats_and_subtitles(content_data['playURL'], video_id)
  63. return {
  64. 'id': video_id,
  65. 'title': video_details.get('title'),
  66. 'description': video_details.get('description'),
  67. 'duration': int_or_none(video_details.get('duration')),
  68. 'release_timestamp': unified_timestamp(video_details.get('dateOfRelease')),
  69. 'categories': traverse_obj(video_details, (('videoCategory', 'videoSubcategory'),)),
  70. 'thumbnail': traverse_obj(video_details, ('backgroundImage', 'src')),
  71. 'formats': formats,
  72. 'subtitles': subtitles,
  73. }