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.

59 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. get_meta_content,
  10. )
  11. class GameSpotIE(InfoExtractor):
  12. _VALID_URL = r'(?:http://)?(?:www\.)?gamespot\.com/.*-(?P<page_id>\d+)/?'
  13. _TEST = {
  14. 'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/',
  15. 'md5': 'b2a30deaa8654fcccd43713a6b6a4825',
  16. 'info_dict': {
  17. 'id': 'gs-2300-6410818',
  18. 'ext': 'mp4',
  19. 'title': 'Arma 3 - Community Guide: SITREP I',
  20. 'description': 'Check out this video where some of the basics of Arma 3 is explained.',
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. page_id = mobj.group('page_id')
  26. webpage = self._download_webpage(url, page_id)
  27. data_video_json = self._search_regex(r'data-video=["\'](.*?)["\']', webpage, 'data video')
  28. data_video = json.loads(unescapeHTML(data_video_json))
  29. # Transform the manifest url to a link to the mp4 files
  30. # they are used in mobile devices.
  31. f4m_url = data_video['videoStreams']['f4m_stream']
  32. f4m_path = compat_urlparse.urlparse(f4m_url).path
  33. QUALITIES_RE = r'((,\d+)+,?)'
  34. qualities = self._search_regex(QUALITIES_RE, f4m_path, 'qualities').strip(',').split(',')
  35. http_path = f4m_path[1:].split('/', 1)[1]
  36. http_template = re.sub(QUALITIES_RE, r'%s', http_path)
  37. http_template = http_template.replace('.csmil/manifest.f4m', '')
  38. http_template = compat_urlparse.urljoin('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. 'title': compat_urllib_parse.unquote(data_video['title']),
  49. 'formats': formats,
  50. 'description': get_meta_content('description', webpage),
  51. 'thumbnail': self._og_search_thumbnail(webpage),
  52. }