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.

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