You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.1 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import (
  5. determine_ext,
  6. int_or_none,
  7. unified_timestamp,
  8. )
  9. class ESPNIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:espn\.go|(?:www\.)?espn)\.com/video/clip(?:\?.*?\bid=|/_/id/)(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'http://espn.go.com/video/clip?id=10365079',
  13. 'info_dict': {
  14. 'id': '10365079',
  15. 'ext': 'mp4',
  16. 'title': '30 for 30 Shorts: Judging Jewell',
  17. 'description': 'md5:39370c2e016cb4ecf498ffe75bef7f0f',
  18. 'timestamp': 1390936111,
  19. 'upload_date': '20140128',
  20. },
  21. 'params': {
  22. 'skip_download': True,
  23. },
  24. }, {
  25. # intl video, from http://www.espnfc.us/video/mls-highlights/150/video/2743663/must-see-moments-best-of-the-mls-season
  26. 'url': 'http://espn.go.com/video/clip?id=2743663',
  27. 'info_dict': {
  28. 'id': '2743663',
  29. 'ext': 'mp4',
  30. 'title': 'Must-See Moments: Best of the MLS season',
  31. 'description': 'md5:4c2d7232beaea572632bec41004f0aeb',
  32. 'timestamp': 1449446454,
  33. 'upload_date': '20151207',
  34. },
  35. 'params': {
  36. 'skip_download': True,
  37. },
  38. 'expected_warnings': ['Unable to download f4m manifest'],
  39. }, {
  40. 'url': 'http://www.espn.com/video/clip?id=10365079',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://www.espn.com/video/clip/_/id/17989860',
  44. 'only_matching': True,
  45. }]
  46. def _real_extract(self, url):
  47. video_id = self._match_id(url)
  48. clip = self._download_json(
  49. 'http://api-app.espn.com/v1/video/clips/%s' % video_id,
  50. video_id)['videos'][0]
  51. title = clip['headline']
  52. format_urls = set()
  53. formats = []
  54. def traverse_source(source, base_source_id=None):
  55. for source_id, source in source.items():
  56. if isinstance(source, compat_str):
  57. extract_source(source, base_source_id)
  58. elif isinstance(source, dict):
  59. traverse_source(
  60. source,
  61. '%s-%s' % (base_source_id, source_id)
  62. if base_source_id else source_id)
  63. def extract_source(source_url, source_id=None):
  64. if source_url in format_urls:
  65. return
  66. format_urls.add(source_url)
  67. ext = determine_ext(source_url)
  68. if ext == 'smil':
  69. formats.extend(self._extract_smil_formats(
  70. source_url, video_id, fatal=False))
  71. elif ext == 'f4m':
  72. formats.extend(self._extract_f4m_formats(
  73. source_url, video_id, f4m_id=source_id, fatal=False))
  74. elif ext == 'm3u8':
  75. formats.extend(self._extract_m3u8_formats(
  76. source_url, video_id, 'mp4', entry_protocol='m3u8_native',
  77. m3u8_id=source_id, fatal=False))
  78. else:
  79. formats.append({
  80. 'url': source_url,
  81. 'format_id': source_id,
  82. })
  83. traverse_source(clip['links']['source'])
  84. self._sort_formats(formats)
  85. description = clip.get('caption') or clip.get('description')
  86. thumbnail = clip.get('thumbnail')
  87. duration = int_or_none(clip.get('duration'))
  88. timestamp = unified_timestamp(clip.get('originalPublishDate'))
  89. return {
  90. 'id': video_id,
  91. 'title': title,
  92. 'description': description,
  93. 'thumbnail': thumbnail,
  94. 'timestamp': timestamp,
  95. 'duration': duration,
  96. 'formats': formats,
  97. }
  98. class ESPNArticleIE(InfoExtractor):
  99. _VALID_URL = r'https?://(?:espn\.go|(?:www\.)?espn)\.com/(?:[^/]+/)*(?P<id>[^/]+)'
  100. _TESTS = [{
  101. 'url': 'https://espn.go.com/video/iframe/twitter/?cms=espn&id=10365079',
  102. 'only_matching': True,
  103. }, {
  104. 'url': 'http://espn.go.com/nba/recap?gameId=400793786',
  105. 'only_matching': True,
  106. }, {
  107. 'url': 'http://espn.go.com/blog/golden-state-warriors/post/_/id/593/how-warriors-rapidly-regained-a-winning-edge',
  108. 'only_matching': True,
  109. }, {
  110. 'url': 'http://espn.go.com/sports/endurance/story/_/id/12893522/dzhokhar-tsarnaev-sentenced-role-boston-marathon-bombings',
  111. 'only_matching': True,
  112. }, {
  113. 'url': 'http://espn.go.com/nba/playoffs/2015/story/_/id/12887571/john-wall-washington-wizards-no-swelling-left-hand-wrist-game-5-return',
  114. 'only_matching': True,
  115. }]
  116. @classmethod
  117. def suitable(cls, url):
  118. return False if ESPNIE.suitable(url) else super(ESPNArticleIE, cls).suitable(url)
  119. def _real_extract(self, url):
  120. video_id = self._match_id(url)
  121. webpage = self._download_webpage(url, video_id)
  122. video_id = self._search_regex(
  123. r'class=(["\']).*?video-play-button.*?\1[^>]+data-id=["\'](?P<id>\d+)',
  124. webpage, 'video id', group='id')
  125. return self.url_result(
  126. 'http://espn.go.com/video/clip?id=%s' % video_id, ESPNIE.ie_key())