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.

56 lines
2.1 KiB

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