logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

fifa.py (4483B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. traverse_obj,
  7. unified_timestamp,
  8. )
  9. if not callable(getattr(InfoExtractor, '_match_valid_url', None)):
  10. BaseInfoExtractor = InfoExtractor
  11. import re
  12. class InfoExtractor(BaseInfoExtractor):
  13. @classmethod
  14. def _match_valid_url(cls, url):
  15. return re.match(cls._VALID_URL, url)
  16. class FifaIE(InfoExtractor):
  17. _VALID_URL = r'https?://www.fifa.com/fifaplus/(?P<locale>\w{2})/watch/([^#?]+/)?(?P<id>\w+)'
  18. _TESTS = [{
  19. 'url': 'https://www.fifa.com/fifaplus/en/watch/7on10qPcnyLajDDU3ntg6y',
  20. 'info_dict': {
  21. 'id': '7on10qPcnyLajDDU3ntg6y',
  22. 'title': 'Italy v France | Final | 2006 FIFA World Cup Germany™ | Full Match Replay',
  23. 'description': 'md5:f4520d0ee80529c8ba4134a7d692ff8b',
  24. 'ext': 'mp4',
  25. 'categories': ['FIFA Tournaments'],
  26. 'thumbnail': 'https://digitalhub.fifa.com/transform/135e2656-3a51-407b-8810-6c34bec5b59b/FMR_2006_Italy_France_Final_Hero',
  27. 'duration': 8165,
  28. },
  29. 'params': {'skip_download': 'm3u8'},
  30. }, {
  31. 'url': 'https://www.fifa.com/fifaplus/pt/watch/1cg5r5Qt6Qt12ilkDgb1sV',
  32. 'info_dict': {
  33. 'id': '1cg5r5Qt6Qt12ilkDgb1sV',
  34. 'title': 'Brazil v Germany | Semi-finals | 2014 FIFA World Cup Brazil™ | Extended Highlights',
  35. 'description': 'md5:d908c74ee66322b804ae2e521b02a855',
  36. 'ext': 'mp4',
  37. 'categories': ['FIFA Tournaments', 'Highlights'],
  38. 'thumbnail': 'https://digitalhub.fifa.com/transform/d8fe6f61-276d-4a73-a7fe-6878a35fd082/FIFAPLS_100EXTHL_2014BRAvGER_TMB',
  39. 'duration': 902,
  40. 'release_timestamp': 1404777600,
  41. 'release_date': '20140708',
  42. },
  43. 'params': {'skip_download': 'm3u8'},
  44. }, {
  45. 'url': 'https://www.fifa.com/fifaplus/fr/watch/3C6gQH9C2DLwzNx7BMRQdp',
  46. 'info_dict': {
  47. 'id': '3C6gQH9C2DLwzNx7BMRQdp',
  48. 'title': 'Josimar goal against Northern Ireland | Classic Goals',
  49. 'description': 'md5:cbe7e7bb52f603c9f1fe9a4780fe983b',
  50. 'ext': 'mp4',
  51. 'categories': ['FIFA Tournaments', 'Goal'],
  52. 'duration': 28,
  53. 'thumbnail': 'https://digitalhub.fifa.com/transform/f9301391-f8d9-48b5-823e-c093ac5e3e11/CG_MEN_1986_JOSIMAR',
  54. },
  55. 'params': {'skip_download': 'm3u8'},
  56. }]
  57. def _real_extract(self, url):
  58. video_id, locale = self._match_valid_url(url).group('id', 'locale')
  59. webpage = self._download_webpage(url, video_id)
  60. preconnect_link = self._search_regex(
  61. r'<link\b[^>]+\brel\s*=\s*"preconnect"[^>]+href\s*=\s*"([^"]+)"', webpage, 'Preconnect Link')
  62. video_details = self._download_json(
  63. '{preconnect_link}/sections/videoDetails/{video_id}'.format(**locals()), video_id, 'Downloading Video Details', fatal=False)
  64. preplay_parameters = self._download_json(
  65. '{preconnect_link}/videoPlayerData/{video_id}'.format(**locals()), video_id, 'Downloading Preplay Parameters')['preplayParameters']
  66. content_data = self._download_json(
  67. # 1. query string is expected to be sent as-is
  68. # 2. `sig` must be appended
  69. # 3. if absent, the call appears to work but the manifest is bad (404)
  70. 'https://content.uplynk.com/preplay/{contentId}/multiple.json?{queryStr}&sig={signature}'.format(**preplay_parameters),
  71. video_id, 'Downloading Content Data')
  72. # formats, subtitles = self._extract_m3u8_formats_and_subtitles(content_data['playURL'], video_id)
  73. formats, subtitles = self._extract_m3u8_formats(content_data['playURL'], video_id, ext='mp4', entry_protocol='m3u8_native'), None
  74. self._sort_formats(formats)
  75. return {
  76. 'id': video_id,
  77. 'title': video_details['title'],
  78. 'description': video_details.get('description'),
  79. 'duration': int_or_none(video_details.get('duration')),
  80. 'release_timestamp': unified_timestamp(video_details.get('dateOfRelease')),
  81. 'categories': traverse_obj(video_details, (('videoCategory', 'videoSubcategory'),)),
  82. 'thumbnail': traverse_obj(video_details, ('backgroundImage', 'src')),
  83. 'formats': formats,
  84. 'subtitles': subtitles,
  85. }