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.

68 lines
2.8 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_urllib_parse,
  5. ExtractorError,
  6. )
  7. class GametrailersIE(InfoExtractor):
  8. _VALID_URL = r'http://www.gametrailers.com/(?P<type>videos|reviews|full-episodes)/(?P<id>.*?)/(?P<title>.*)'
  9. _TEST = {
  10. u'url': u'http://www.gametrailers.com/videos/zbvr8i/mirror-s-edge-2-e3-2013--debut-trailer',
  11. u'file': u'zbvr8i.flv',
  12. u'md5': u'c3edbc995ab4081976e16779bd96a878',
  13. u'info_dict': {
  14. u"title": u"E3 2013: Debut Trailer"
  15. },
  16. u'skip': u'Requires rtmpdump'
  17. }
  18. def _real_extract(self, url):
  19. mobj = re.match(self._VALID_URL, url)
  20. if mobj is None:
  21. raise ExtractorError(u'Invalid URL: %s' % url)
  22. video_id = mobj.group('id')
  23. video_type = mobj.group('type')
  24. webpage = self._download_webpage(url, video_id)
  25. if video_type == 'full-episodes':
  26. mgid_re = r'data-video="(?P<mgid>mgid:.*?)"'
  27. else:
  28. mgid_re = r'data-contentId=\'(?P<mgid>mgid:.*?)\''
  29. mgid = self._search_regex(mgid_re, webpage, u'mgid')
  30. data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
  31. info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
  32. video_id, u'Downloading video info')
  33. links_webpage = self._download_webpage('http://www.gametrailers.com/feeds/mediagen/?' + data,
  34. video_id, u'Downloading video urls info')
  35. self.report_extraction(video_id)
  36. info_re = r'''<title><!\[CDATA\[(?P<title>.*?)\]\]></title>.*
  37. <description><!\[CDATA\[(?P<description>.*?)\]\]></description>.*
  38. <image>.*
  39. <url>(?P<thumb>.*?)</url>.*
  40. </image>'''
  41. m_info = re.search(info_re, info_page, re.VERBOSE|re.DOTALL)
  42. if m_info is None:
  43. raise ExtractorError(u'Unable to extract video info')
  44. video_title = m_info.group('title')
  45. video_description = m_info.group('description')
  46. video_thumb = m_info.group('thumb')
  47. m_urls = list(re.finditer(r'<src>(?P<url>.*)</src>', links_webpage))
  48. if m_urls is None or len(m_urls) == 0:
  49. raise ExtractorError(u'Unable to extract video url')
  50. # They are sorted from worst to best quality
  51. video_url = m_urls[-1].group('url')
  52. return {'url': video_url,
  53. 'id': video_id,
  54. 'title': video_title,
  55. # Videos are actually flv not mp4
  56. 'ext': 'flv',
  57. 'thumbnail': video_thumb,
  58. 'description': video_description,
  59. }