logo

youtube-dl

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

nfl.py (6731B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. determine_ext,
  8. get_element_by_class,
  9. )
  10. class NFLBaseIE(InfoExtractor):
  11. _VALID_URL_BASE = r'''(?x)
  12. https?://
  13. (?P<host>
  14. (?:www\.)?
  15. (?:
  16. (?:
  17. nfl|
  18. buffalobills|
  19. miamidolphins|
  20. patriots|
  21. newyorkjets|
  22. baltimoreravens|
  23. bengals|
  24. clevelandbrowns|
  25. steelers|
  26. houstontexans|
  27. colts|
  28. jaguars|
  29. (?:titansonline|tennesseetitans)|
  30. denverbroncos|
  31. (?:kc)?chiefs|
  32. raiders|
  33. chargers|
  34. dallascowboys|
  35. giants|
  36. philadelphiaeagles|
  37. (?:redskins|washingtonfootball)|
  38. chicagobears|
  39. detroitlions|
  40. packers|
  41. vikings|
  42. atlantafalcons|
  43. panthers|
  44. neworleanssaints|
  45. buccaneers|
  46. azcardinals|
  47. (?:stlouis|the)rams|
  48. 49ers|
  49. seahawks
  50. )\.com|
  51. .+?\.clubs\.nfl\.com
  52. )
  53. )/
  54. '''
  55. _VIDEO_CONFIG_REGEX = r'<script[^>]+id="[^"]*video-config-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}[^"]*"[^>]*>\s*({.+})'
  56. _WORKING = False
  57. def _parse_video_config(self, video_config, display_id):
  58. video_config = self._parse_json(video_config, display_id)
  59. item = video_config['playlist'][0]
  60. mcp_id = item.get('mcpID')
  61. if mcp_id:
  62. info = self.url_result(
  63. 'anvato:GXvEgwyJeWem8KCYXfeoHWknwP48Mboj:' + mcp_id,
  64. 'Anvato', mcp_id)
  65. else:
  66. media_id = item.get('id') or item['entityId']
  67. title = item['title']
  68. item_url = item['url']
  69. info = {'id': media_id}
  70. ext = determine_ext(item_url)
  71. if ext == 'm3u8':
  72. info['formats'] = self._extract_m3u8_formats(item_url, media_id, 'mp4')
  73. self._sort_formats(info['formats'])
  74. else:
  75. info['url'] = item_url
  76. if item.get('audio') is True:
  77. info['vcodec'] = 'none'
  78. is_live = video_config.get('live') is True
  79. thumbnails = None
  80. image_url = item.get(item.get('imageSrc')) or item.get(item.get('posterImage'))
  81. if image_url:
  82. thumbnails = [{
  83. 'url': image_url,
  84. 'ext': determine_ext(image_url, 'jpg'),
  85. }]
  86. info.update({
  87. 'title': self._live_title(title) if is_live else title,
  88. 'is_live': is_live,
  89. 'description': clean_html(item.get('description')),
  90. 'thumbnails': thumbnails,
  91. })
  92. return info
  93. class NFLIE(NFLBaseIE):
  94. IE_NAME = 'nfl.com'
  95. _VALID_URL = NFLBaseIE._VALID_URL_BASE + r'(?:videos?|listen|audio)/(?P<id>[^/#?&]+)'
  96. _TESTS = [{
  97. 'url': 'https://www.nfl.com/videos/baker-mayfield-s-game-changing-plays-from-3-td-game-week-14',
  98. 'info_dict': {
  99. 'id': '899441',
  100. 'ext': 'mp4',
  101. 'title': "Baker Mayfield's game-changing plays from 3-TD game Week 14",
  102. 'description': 'md5:85e05a3cc163f8c344340f220521136d',
  103. 'upload_date': '20201215',
  104. 'timestamp': 1608009755,
  105. 'thumbnail': r're:^https?://.*\.jpg$',
  106. 'uploader': 'NFL',
  107. }
  108. }, {
  109. 'url': 'https://www.chiefs.com/listen/patrick-mahomes-travis-kelce-react-to-win-over-dolphins-the-breakdown',
  110. 'md5': '6886b32c24b463038c760ceb55a34566',
  111. 'info_dict': {
  112. 'id': 'd87e8790-3e14-11eb-8ceb-ff05c2867f99',
  113. 'ext': 'mp3',
  114. 'title': 'Patrick Mahomes, Travis Kelce React to Win Over Dolphins | The Breakdown',
  115. 'description': 'md5:12ada8ee70e6762658c30e223e095075',
  116. }
  117. }, {
  118. 'url': 'https://www.buffalobills.com/video/buffalo-bills-military-recognition-week-14',
  119. 'only_matching': True,
  120. }, {
  121. 'url': 'https://www.raiders.com/audio/instant-reactions-raiders-week-14-loss-to-indianapolis-colts-espn-jason-fitz',
  122. 'only_matching': True,
  123. }]
  124. def _real_extract(self, url):
  125. display_id = self._match_id(url)
  126. webpage = self._download_webpage(url, display_id)
  127. return self._parse_video_config(self._search_regex(
  128. self._VIDEO_CONFIG_REGEX, webpage, 'video config'), display_id)
  129. class NFLArticleIE(NFLBaseIE):
  130. IE_NAME = 'nfl.com:article'
  131. _VALID_URL = NFLBaseIE._VALID_URL_BASE + r'news/(?P<id>[^/#?&]+)'
  132. _TEST = {
  133. 'url': 'https://www.buffalobills.com/news/the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
  134. 'info_dict': {
  135. 'id': 'the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-e',
  136. 'title': "'The only thing we've earned is the noise' | Bills coaches discuss handling rising expectations",
  137. },
  138. 'playlist_count': 4,
  139. }
  140. def _real_extract(self, url):
  141. display_id = self._match_id(url)
  142. webpage = self._download_webpage(url, display_id)
  143. entries = []
  144. for video_config in re.findall(self._VIDEO_CONFIG_REGEX, webpage):
  145. entries.append(self._parse_video_config(video_config, display_id))
  146. title = clean_html(get_element_by_class(
  147. 'nfl-c-article__title', webpage)) or self._html_search_meta(
  148. ['og:title', 'twitter:title'], webpage)
  149. return self.playlist_result(entries, display_id, title)