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.

82 lines
3.1 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_unquote,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. unescapeHTML,
  11. )
  12. class GameSpotIE(InfoExtractor):
  13. _VALID_URL = r'http://(?: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 = json.loads(unescapeHTML(data_video_json))
  38. streams = data_video['videoStreams']
  39. formats = []
  40. f4m_url = streams.get('f4m_stream')
  41. if f4m_url is not None:
  42. # Transform the manifest url to a link to the mp4 files
  43. # they are used in mobile devices.
  44. f4m_path = compat_urlparse.urlparse(f4m_url).path
  45. QUALITIES_RE = r'((,\d+)+,?)'
  46. qualities = self._search_regex(QUALITIES_RE, f4m_path, 'qualities').strip(',').split(',')
  47. http_path = f4m_path[1:].split('/', 1)[1]
  48. http_template = re.sub(QUALITIES_RE, r'%s', http_path)
  49. http_template = http_template.replace('.csmil/manifest.f4m', '')
  50. http_template = compat_urlparse.urljoin(
  51. 'http://video.gamespotcdn.com/', http_template)
  52. for q in qualities:
  53. formats.append({
  54. 'url': http_template % q,
  55. 'ext': 'mp4',
  56. 'format_id': q,
  57. })
  58. else:
  59. for quality in ['sd', 'hd']:
  60. # It's actually a link to a flv file
  61. flv_url = streams.get('f4m_{0}'.format(quality))
  62. if flv_url is not None:
  63. formats.append({
  64. 'url': flv_url,
  65. 'ext': 'flv',
  66. 'format_id': quality,
  67. })
  68. return {
  69. 'id': data_video['guid'],
  70. 'display_id': page_id,
  71. 'title': compat_urllib_parse_unquote(data_video['title']),
  72. 'formats': formats,
  73. 'description': self._html_search_meta('description', webpage),
  74. 'thumbnail': self._og_search_thumbnail(webpage),
  75. }