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.

60 lines
2.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse,
  7. compat_urlparse,
  8. unescapeHTML,
  9. )
  10. class GameSpotIE(InfoExtractor):
  11. _VALID_URL = r'(?:http://)?(?:www\.)?gamespot\.com/.*-(?P<id>\d+)/?'
  12. _TEST = {
  13. 'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/',
  14. 'md5': 'b2a30deaa8654fcccd43713a6b6a4825',
  15. 'info_dict': {
  16. 'id': 'gs-2300-6410818',
  17. 'ext': 'mp4',
  18. 'title': 'Arma 3 - Community Guide: SITREP I',
  19. 'description': 'Check out this video where some of the basics of Arma 3 is explained.',
  20. }
  21. }
  22. def _real_extract(self, url):
  23. page_id = self._match_id(url)
  24. webpage = self._download_webpage(url, page_id)
  25. data_video_json = self._search_regex(
  26. r'data-video=["\'](.*?)["\']', webpage, 'data video')
  27. data_video = json.loads(unescapeHTML(data_video_json))
  28. # Transform the manifest url to a link to the mp4 files
  29. # they are used in mobile devices.
  30. f4m_url = data_video['videoStreams']['f4m_stream']
  31. f4m_path = compat_urlparse.urlparse(f4m_url).path
  32. QUALITIES_RE = r'((,\d+)+,?)'
  33. qualities = self._search_regex(QUALITIES_RE, f4m_path, 'qualities').strip(',').split(',')
  34. http_path = f4m_path[1:].split('/', 1)[1]
  35. http_template = re.sub(QUALITIES_RE, r'%s', http_path)
  36. http_template = http_template.replace('.csmil/manifest.f4m', '')
  37. http_template = compat_urlparse.urljoin(
  38. 'http://video.gamespotcdn.com/', http_template)
  39. formats = []
  40. for q in qualities:
  41. formats.append({
  42. 'url': http_template % q,
  43. 'ext': 'mp4',
  44. 'format_id': q,
  45. })
  46. return {
  47. 'id': data_video['guid'],
  48. 'display_id': page_id,
  49. 'title': compat_urllib_parse.unquote(data_video['title']),
  50. 'formats': formats,
  51. 'description': self._html_search_meta('description', webpage),
  52. 'thumbnail': self._og_search_thumbnail(webpage),
  53. }