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.

55 lines
2.1 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. unified_strdate,
  6. compat_urllib_parse,
  7. )
  8. class GameSpotIE(InfoExtractor):
  9. _VALID_URL = r'(?:http://)?(?:www\.)?gamespot\.com/.*-(?P<page_id>\d+)/?'
  10. _TEST = {
  11. u"url": u"http://www.gamespot.com/arma-iii/videos/arma-iii-community-guide-sitrep-i-6410818/",
  12. u"file": u"6410818.mp4",
  13. u"md5": u"b2a30deaa8654fcccd43713a6b6a4825",
  14. u"info_dict": {
  15. u"title": u"Arma III - Community Guide: SITREP I",
  16. u"upload_date": u"20130627",
  17. }
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. page_id = mobj.group('page_id')
  22. webpage = self._download_webpage(url, page_id)
  23. video_id = self._html_search_regex([r'"og:video" content=".*?\?id=(\d+)"',
  24. r'http://www\.gamespot\.com/videoembed/(\d+)'],
  25. webpage, 'video id')
  26. data = compat_urllib_parse.urlencode({'id': video_id, 'newplayer': '1'})
  27. info_url = 'http://www.gamespot.com/pages/video_player/xml.php?' + data
  28. info_xml = self._download_webpage(info_url, video_id)
  29. doc = xml.etree.ElementTree.fromstring(info_xml)
  30. clip_el = doc.find('./playList/clip')
  31. http_urls = [{'url': node.find('filePath').text,
  32. 'rate': int(node.find('rate').text)}
  33. for node in clip_el.find('./httpURI')]
  34. best_quality = sorted(http_urls, key=lambda f: f['rate'])[-1]
  35. video_url = best_quality['url']
  36. title = clip_el.find('./title').text
  37. ext = video_url.rpartition('.')[2]
  38. thumbnail_url = clip_el.find('./screenGrabURI').text
  39. view_count = int(clip_el.find('./views').text)
  40. upload_date = unified_strdate(clip_el.find('./postDate').text)
  41. return [{
  42. 'id' : video_id,
  43. 'url' : video_url,
  44. 'ext' : ext,
  45. 'title' : title,
  46. 'thumbnail' : thumbnail_url,
  47. 'upload_date' : upload_date,
  48. 'view_count' : view_count,
  49. }]