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.

58 lines
2.1 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/arma-iii/videos/arma-iii-community-guide-sitrep-i-6410818/",
  15. "file": "gs-2300-6410818.mp4",
  16. "md5": "b2a30deaa8654fcccd43713a6b6a4825",
  17. "info_dict": {
  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. mobj = re.match(self._VALID_URL, url)
  24. page_id = mobj.group('page_id')
  25. webpage = self._download_webpage(url, page_id)
  26. data_video_json = self._search_regex(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('http://video.gamespotcdn.com/', http_template)
  38. formats = []
  39. for q in qualities:
  40. formats.append({
  41. 'url': http_template % q,
  42. 'ext': 'mp4',
  43. 'format_id': q,
  44. })
  45. return {
  46. 'id': data_video['guid'],
  47. 'title': compat_urllib_parse.unquote(data_video['title']),
  48. 'formats': formats,
  49. 'description': get_meta_content('description', webpage),
  50. 'thumbnail': self._og_search_thumbnail(webpage),
  51. }