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.

139 lines
5.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .once import OnceIE
  4. from ..compat import (
  5. compat_urllib_parse_unquote,
  6. )
  7. from ..utils import (
  8. unescapeHTML,
  9. url_basename,
  10. dict_get,
  11. )
  12. class GameSpotIE(OnceIE):
  13. _VALID_URL = r'https?://(?:www\.)?gamespot\.com/(?:video|article|review)s/(?:[^/]+/\d+-|embed/)(?P<id>\d+)'
  14. _TESTS = [{
  15. 'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/',
  16. 'md5': 'b2a30deaa8654fcccd43713a6b6a4825',
  17. 'info_dict': {
  18. 'id': 'gs-2300-6410818',
  19. 'ext': 'mp4',
  20. 'title': 'Arma 3 - Community Guide: SITREP I',
  21. 'description': 'Check out this video where some of the basics of Arma 3 is explained.',
  22. },
  23. }, {
  24. 'url': 'http://www.gamespot.com/videos/the-witcher-3-wild-hunt-xbox-one-now-playing/2300-6424837/',
  25. 'info_dict': {
  26. 'id': 'gs-2300-6424837',
  27. 'ext': 'mp4',
  28. 'title': 'Now Playing - The Witcher 3: Wild Hunt',
  29. 'description': 'Join us as we take a look at the early hours of The Witcher 3: Wild Hunt and more.',
  30. },
  31. 'params': {
  32. 'skip_download': True, # m3u8 downloads
  33. },
  34. }, {
  35. 'url': 'https://www.gamespot.com/videos/embed/6439218/',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'https://www.gamespot.com/articles/the-last-of-us-2-receives-new-ps4-trailer/1100-6454469/',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'https://www.gamespot.com/reviews/gears-of-war-review/1900-6161188/',
  42. 'only_matching': True,
  43. }]
  44. def _real_extract(self, url):
  45. page_id = self._match_id(url)
  46. webpage = self._download_webpage(url, page_id)
  47. data_video_json = self._search_regex(
  48. r'data-video=["\'](.*?)["\']', webpage, 'data video')
  49. data_video = self._parse_json(unescapeHTML(data_video_json), page_id)
  50. streams = data_video['videoStreams']
  51. manifest_url = None
  52. formats = []
  53. f4m_url = streams.get('f4m_stream')
  54. if f4m_url:
  55. manifest_url = f4m_url
  56. formats.extend(self._extract_f4m_formats(
  57. f4m_url + '?hdcore=3.7.0', page_id, f4m_id='hds', fatal=False))
  58. m3u8_url = dict_get(streams, ('m3u8_stream', 'adaptive_stream'))
  59. if m3u8_url:
  60. manifest_url = m3u8_url
  61. m3u8_formats = self._extract_m3u8_formats(
  62. m3u8_url, page_id, 'mp4', 'm3u8_native',
  63. m3u8_id='hls', fatal=False)
  64. formats.extend(m3u8_formats)
  65. progressive_url = dict_get(
  66. streams, ('progressive_hd', 'progressive_high', 'progressive_low', 'other_lr'))
  67. if progressive_url and manifest_url:
  68. qualities_basename = self._search_regex(
  69. r'/([^/]+)\.csmil/',
  70. manifest_url, 'qualities basename', default=None)
  71. if qualities_basename:
  72. QUALITIES_RE = r'((,\d+)+,?)'
  73. qualities = self._search_regex(
  74. QUALITIES_RE, qualities_basename,
  75. 'qualities', default=None)
  76. if qualities:
  77. qualities = list(map(lambda q: int(q), qualities.strip(',').split(',')))
  78. qualities.sort()
  79. http_template = re.sub(QUALITIES_RE, r'%d', qualities_basename)
  80. http_url_basename = url_basename(progressive_url)
  81. if m3u8_formats:
  82. self._sort_formats(m3u8_formats)
  83. m3u8_formats = list(filter(
  84. lambda f: f.get('vcodec') != 'none', m3u8_formats))
  85. if len(qualities) == len(m3u8_formats):
  86. for q, m3u8_format in zip(qualities, m3u8_formats):
  87. f = m3u8_format.copy()
  88. f.update({
  89. 'url': progressive_url.replace(
  90. http_url_basename, http_template % q),
  91. 'format_id': f['format_id'].replace('hls', 'http'),
  92. 'protocol': 'http',
  93. })
  94. formats.append(f)
  95. else:
  96. for q in qualities:
  97. formats.append({
  98. 'url': progressive_url.replace(
  99. http_url_basename, http_template % q),
  100. 'ext': 'mp4',
  101. 'format_id': 'http-%d' % q,
  102. 'tbr': q,
  103. })
  104. onceux_json = self._search_regex(
  105. r'data-onceux-options=["\'](.*?)["\']', webpage, 'data video', default=None)
  106. if onceux_json:
  107. onceux_url = self._parse_json(unescapeHTML(onceux_json), page_id).get('metadataUri')
  108. if onceux_url:
  109. formats.extend(self._extract_once_formats(re.sub(
  110. r'https?://[^/]+', 'http://once.unicornmedia.com', onceux_url),
  111. http_formats_preference=-1))
  112. if not formats:
  113. for quality in ['sd', 'hd']:
  114. # It's actually a link to a flv file
  115. flv_url = streams.get('f4m_{0}'.format(quality))
  116. if flv_url is not None:
  117. formats.append({
  118. 'url': flv_url,
  119. 'ext': 'flv',
  120. 'format_id': quality,
  121. })
  122. self._sort_formats(formats)
  123. return {
  124. 'id': data_video['guid'],
  125. 'display_id': page_id,
  126. 'title': compat_urllib_parse_unquote(data_video['title']),
  127. 'formats': formats,
  128. 'description': self._html_search_meta('description', webpage),
  129. 'thumbnail': self._og_search_thumbnail(webpage),
  130. }