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