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