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.

63 lines
2.7 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse,
  6. ExtractorError,
  7. )
  8. class GametrailersIE(InfoExtractor):
  9. _VALID_URL = r'http://www.gametrailers.com/(?P<type>videos|reviews|full-episodes)/(?P<id>.*?)/(?P<title>.*)'
  10. _TEST = {
  11. u'url': u'http://www.gametrailers.com/videos/zbvr8i/mirror-s-edge-2-e3-2013--debut-trailer',
  12. u'file': u'70e9a5d7-cf25-4a10-9104-6f3e7342ae0d.flv',
  13. u'md5': u'c3edbc995ab4081976e16779bd96a878',
  14. u'info_dict': {
  15. u"title": u"E3 2013: Debut Trailer"
  16. },
  17. u'skip': u'Requires rtmpdump'
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. if mobj is None:
  22. raise ExtractorError(u'Invalid URL: %s' % url)
  23. video_id = mobj.group('id')
  24. webpage = self._download_webpage(url, video_id)
  25. mgid = self._search_regex([r'data-video="(?P<mgid>mgid:.*?)"',
  26. r'data-contentId=\'(?P<mgid>mgid:.*?)\''],
  27. webpage, u'mgid')
  28. data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
  29. info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
  30. video_id, u'Downloading video info')
  31. doc = xml.etree.ElementTree.fromstring(info_page.encode('utf-8'))
  32. default_thumb = doc.find('./channel/image/url').text
  33. media_namespace = {'media': 'http://search.yahoo.com/mrss/'}
  34. parts = [{
  35. 'title': video_doc.find('title').text,
  36. 'ext': 'flv',
  37. 'id': video_doc.find('guid').text.rpartition(':')[2],
  38. # Videos are actually flv not mp4
  39. 'url': self._get_video_url(video_doc.find('media:group/media:content', media_namespace).attrib['url'], video_id),
  40. # The thumbnail may not be defined, it would be ''
  41. 'thumbnail': video_doc.find('media:group/media:thumbnail', media_namespace).attrib['url'] or default_thumb,
  42. 'description': video_doc.find('description').text,
  43. } for video_doc in doc.findall('./channel/item')]
  44. return parts
  45. def _get_video_url(self, mediagen_url, video_id):
  46. if 'acceptMethods' not in mediagen_url:
  47. mediagen_url += '&acceptMethods=fms'
  48. links_webpage = self._download_webpage(mediagen_url,
  49. video_id, u'Downloading video urls info')
  50. doc = xml.etree.ElementTree.fromstring(links_webpage)
  51. urls = list(doc.iter('src'))
  52. if len(urls) == 0:
  53. raise ExtractorError(u'Unable to extract video url')
  54. # They are sorted from worst to best quality
  55. return urls[-1].text