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.

130 lines
5.4 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/.*-(?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. def _real_extract(self, url):
  36. page_id = self._match_id(url)
  37. webpage = self._download_webpage(url, page_id)
  38. data_video_json = self._search_regex(
  39. r'data-video=["\'](.*?)["\']', webpage, 'data video')
  40. data_video = self._parse_json(unescapeHTML(data_video_json), page_id)
  41. streams = data_video['videoStreams']
  42. manifest_url = None
  43. formats = []
  44. f4m_url = streams.get('f4m_stream')
  45. if f4m_url:
  46. manifest_url = f4m_url
  47. formats.extend(self._extract_f4m_formats(
  48. f4m_url + '?hdcore=3.7.0', page_id, f4m_id='hds', fatal=False))
  49. m3u8_url = streams.get('m3u8_stream')
  50. if m3u8_url:
  51. manifest_url = m3u8_url
  52. m3u8_formats = self._extract_m3u8_formats(
  53. m3u8_url, page_id, 'mp4', 'm3u8_native',
  54. m3u8_id='hls', fatal=False)
  55. formats.extend(m3u8_formats)
  56. progressive_url = dict_get(
  57. streams, ('progressive_hd', 'progressive_high', 'progressive_low'))
  58. if progressive_url and manifest_url:
  59. qualities_basename = self._search_regex(
  60. r'/([^/]+)\.csmil/',
  61. manifest_url, 'qualities basename', default=None)
  62. if qualities_basename:
  63. QUALITIES_RE = r'((,\d+)+,?)'
  64. qualities = self._search_regex(
  65. QUALITIES_RE, qualities_basename,
  66. 'qualities', default=None)
  67. if qualities:
  68. qualities = list(map(lambda q: int(q), qualities.strip(',').split(',')))
  69. qualities.sort()
  70. http_template = re.sub(QUALITIES_RE, r'%d', qualities_basename)
  71. http_url_basename = url_basename(progressive_url)
  72. if m3u8_formats:
  73. self._sort_formats(m3u8_formats)
  74. m3u8_formats = list(filter(
  75. lambda f: f.get('vcodec') != 'none' and f.get('resolution') != 'multiple',
  76. m3u8_formats))
  77. if len(qualities) == len(m3u8_formats):
  78. for q, m3u8_format in zip(qualities, m3u8_formats):
  79. f = m3u8_format.copy()
  80. f.update({
  81. 'url': progressive_url.replace(
  82. http_url_basename, http_template % q),
  83. 'format_id': f['format_id'].replace('hls', 'http'),
  84. 'protocol': 'http',
  85. })
  86. formats.append(f)
  87. else:
  88. for q in qualities:
  89. formats.append({
  90. 'url': progressive_url.replace(
  91. http_url_basename, http_template % q),
  92. 'ext': 'mp4',
  93. 'format_id': 'http-%d' % q,
  94. 'tbr': q,
  95. })
  96. onceux_json = self._search_regex(
  97. r'data-onceux-options=["\'](.*?)["\']', webpage, 'data video', default=None)
  98. if onceux_json:
  99. onceux_url = self._parse_json(unescapeHTML(onceux_json), page_id).get('metadataUri')
  100. if onceux_url:
  101. formats.extend(self._extract_once_formats(re.sub(
  102. r'https?://[^/]+', 'http://once.unicornmedia.com', onceux_url).replace('ads/vmap/', '')))
  103. if not formats:
  104. for quality in ['sd', 'hd']:
  105. # It's actually a link to a flv file
  106. flv_url = streams.get('f4m_{0}'.format(quality))
  107. if flv_url is not None:
  108. formats.append({
  109. 'url': flv_url,
  110. 'ext': 'flv',
  111. 'format_id': quality,
  112. })
  113. self._sort_formats(formats)
  114. return {
  115. 'id': data_video['guid'],
  116. 'display_id': page_id,
  117. 'title': compat_urllib_parse_unquote(data_video['title']),
  118. 'formats': formats,
  119. 'description': self._html_search_meta('description', webpage),
  120. 'thumbnail': self._og_search_thumbnail(webpage),
  121. }