- mobj = re.match(self._VALID_URL, url)
- if mobj is None:
- raise ExtractorError(u'Invalid URL: %s' % url)
- video_id = mobj.group('id')
- webpage = self._download_webpage(url, video_id)
- mgid = self._search_regex([r'data-video="(?P<mgid>mgid:.*?)"',
- r'data-contentId=\'(?P<mgid>mgid:.*?)\''],
- webpage, u'mgid')
-
- data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
- info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
- video_id, u'Downloading video info')
- doc = xml.etree.ElementTree.fromstring(info_page.encode('utf-8'))
- default_thumb = doc.find('./channel/image/url').text
-
- media_namespace = {'media': 'http://search.yahoo.com/mrss/'}
- parts = [{
- 'title': video_doc.find('title').text,
- 'ext': 'flv',
- 'id': video_doc.find('guid').text.rpartition(':')[2],
- # Videos are actually flv not mp4
- 'url': self._get_video_url(video_doc.find('media:group/media:content', media_namespace).attrib['url'], video_id),
- # The thumbnail may not be defined, it would be ''
- 'thumbnail': video_doc.find('media:group/media:thumbnail', media_namespace).attrib['url'] or default_thumb,
- 'description': video_doc.find('description').text,
- } for video_doc in doc.findall('./channel/item')]
- return parts
-
- def _get_video_url(self, mediagen_url, video_id):
- if 'acceptMethods' not in mediagen_url:
- mediagen_url += '&acceptMethods=fms'
- links_webpage = self._download_webpage(mediagen_url,
- video_id, u'Downloading video urls info')
- doc = xml.etree.ElementTree.fromstring(links_webpage)
- urls = list(doc.iter('src'))
- if len(urls) == 0:
- raise ExtractorError(u'Unable to extract video url')
- # They are sorted from worst to best quality
- return urls[-1].text
-
+ display_id = self._match_id(url)
+ webpage = self._download_webpage(url, display_id)
+ title = self._html_search_regex(
+ r'<title>(.+?)\|', webpage, 'title').strip()
+ embed_url = self._proto_relative_url(
+ self._search_regex(
+ r'src=\'(//embed.gametrailers.com/embed/[^\']+)\'', webpage,
+ 'embed url'),
+ scheme='http:')
+ video_id = url_basename(embed_url)
+ embed_page = self._download_webpage(embed_url, video_id)
+ embed_vars_json = self._search_regex(
+ r'(?s)var embedVars = (\{.*?\})\s*</script>', embed_page,
+ 'embed vars')
+ info = self._parse_json(embed_vars_json, video_id)
+
+ formats = []
+ for media in info['media']:
+ if media['mediaPurpose'] == 'play':
+ formats.append({
+ 'url': media['uri'],
+ 'height': media['height'],
+ 'width:': media['width'],
+ })
+ self._sort_formats(formats)
+
+ return {
+ 'id': video_id,
+ 'display_id': display_id,
+ 'title': title,
+ 'formats': formats,
+ 'thumbnail': info.get('thumbUri'),
+ 'description': self._og_search_description(webpage),
+ 'duration': int_or_none(info.get('videoLengthInSeconds')),
+ 'age_limit': parse_age_limit(info.get('audienceRating')),
+ }