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.

62 lines
2.2 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,
  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. _TEST = {
  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. def _real_extract(self, url):
  25. page_id = self._match_id(url)
  26. webpage = self._download_webpage(url, page_id)
  27. data_video_json = self._search_regex(
  28. r'data-video=["\'](.*?)["\']', webpage, 'data video')
  29. data_video = json.loads(unescapeHTML(data_video_json))
  30. # Transform the manifest url to a link to the mp4 files
  31. # they are used in mobile devices.
  32. f4m_url = data_video['videoStreams']['f4m_stream']
  33. f4m_path = compat_urlparse.urlparse(f4m_url).path
  34. QUALITIES_RE = r'((,\d+)+,?)'
  35. qualities = self._search_regex(QUALITIES_RE, f4m_path, 'qualities').strip(',').split(',')
  36. http_path = f4m_path[1:].split('/', 1)[1]
  37. http_template = re.sub(QUALITIES_RE, r'%s', http_path)
  38. http_template = http_template.replace('.csmil/manifest.f4m', '')
  39. http_template = compat_urlparse.urljoin(
  40. 'http://video.gamespotcdn.com/', http_template)
  41. formats = []
  42. for q in qualities:
  43. formats.append({
  44. 'url': http_template % q,
  45. 'ext': 'mp4',
  46. 'format_id': q,
  47. })
  48. return {
  49. 'id': data_video['guid'],
  50. 'display_id': page_id,
  51. 'title': compat_urllib_parse.unquote(data_video['title']),
  52. 'formats': formats,
  53. 'description': self._html_search_meta('description', webpage),
  54. 'thumbnail': self._og_search_thumbnail(webpage),
  55. }