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.

59 lines
2.4 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. def _real_extract(self, url):
  10. mobj = re.match(self._VALID_URL, url)
  11. if mobj is None:
  12. raise ExtractorError(u'Invalid URL: %s' % url)
  13. video_id = mobj.group('id')
  14. video_type = mobj.group('type')
  15. webpage = self._download_webpage(url, video_id)
  16. if video_type == 'full-episodes':
  17. mgid_re = r'data-video="(?P<mgid>mgid:.*?)"'
  18. else:
  19. mgid_re = r'data-contentId=\'(?P<mgid>mgid:.*?)\''
  20. mgid = self._search_regex(mgid_re, webpage, u'mgid')
  21. data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
  22. info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
  23. video_id, u'Downloading video info')
  24. links_webpage = self._download_webpage('http://www.gametrailers.com/feeds/mediagen/?' + data,
  25. video_id, u'Downloading video urls info')
  26. self.report_extraction(video_id)
  27. info_re = r'''<title><!\[CDATA\[(?P<title>.*?)\]\]></title>.*
  28. <description><!\[CDATA\[(?P<description>.*?)\]\]></description>.*
  29. <image>.*
  30. <url>(?P<thumb>.*?)</url>.*
  31. </image>'''
  32. m_info = re.search(info_re, info_page, re.VERBOSE|re.DOTALL)
  33. if m_info is None:
  34. raise ExtractorError(u'Unable to extract video info')
  35. video_title = m_info.group('title')
  36. video_description = m_info.group('description')
  37. video_thumb = m_info.group('thumb')
  38. m_urls = list(re.finditer(r'<src>(?P<url>.*)</src>', links_webpage))
  39. if m_urls is None or len(m_urls) == 0:
  40. raise ExtractorError(u'Unable to extract video url')
  41. # They are sorted from worst to best quality
  42. video_url = m_urls[-1].group('url')
  43. return {'url': video_url,
  44. 'id': video_id,
  45. 'title': video_title,
  46. # Videos are actually flv not mp4
  47. 'ext': 'flv',
  48. 'thumbnail': video_thumb,
  49. 'description': video_description,
  50. }