]>
Commit | Line | Data |
---|---|---|
2ef648d3 JMF |
1 | import re |
2 | import json | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | determine_ext, | |
7 | ) | |
8 | ||
a95967f8 | 9 | |
2ef648d3 | 10 | class IGNIE(InfoExtractor): |
a95967f8 JMF |
11 | """ |
12 | Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com. | |
13 | Some videos of it.ign.com are also supported | |
14 | """ | |
15 | ||
f1fb2d12 | 16 | _VALID_URL = r'https?://.+?\.ign\.com/(?P<type>videos|show_videos|articles)(/.+)?/(?P<name_or_id>.+)' |
2ef648d3 JMF |
17 | IE_NAME = u'ign.com' |
18 | ||
a95967f8 JMF |
19 | _CONFIG_URL_TEMPLATE = 'http://www.ign.com/videos/configs/id/%s.config' |
20 | _DESCRIPTION_RE = [r'<span class="page-object-description">(.+?)</span>', | |
21 | r'id="my_show_video">.*?<p>(.*?)</p>', | |
22 | ] | |
23 | ||
2ef648d3 JMF |
24 | _TEST = { |
25 | u'url': u'http://www.ign.com/videos/2013/06/05/the-last-of-us-review', | |
26 | u'file': u'8f862beef863986b2785559b9e1aa599.mp4', | |
27 | u'md5': u'eac8bdc1890980122c3b66f14bdd02e9', | |
28 | u'info_dict': { | |
29 | u'title': u'The Last of Us Review', | |
30 | u'description': u'md5:c8946d4260a4d43a00d5ae8ed998870c', | |
31 | } | |
32 | } | |
33 | ||
a95967f8 JMF |
34 | def _find_video_id(self, webpage): |
35 | res_id = [r'data-video-id="(.+?)"', | |
36 | r'<object id="vid_(.+?)"', | |
37 | r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"', | |
38 | ] | |
39 | return self._search_regex(res_id, webpage, 'video id') | |
40 | ||
2ef648d3 JMF |
41 | def _real_extract(self, url): |
42 | mobj = re.match(self._VALID_URL, url) | |
a95967f8 | 43 | name_or_id = mobj.group('name_or_id') |
f1fb2d12 | 44 | page_type = mobj.group('type') |
a95967f8 | 45 | webpage = self._download_webpage(url, name_or_id) |
f1fb2d12 JMF |
46 | if page_type == 'articles': |
47 | video_url = self._search_regex(r'var videoUrl = "(.+?)"', webpage, u'video url') | |
48 | return self.url_result(video_url, ie='IGN') | |
a95967f8 JMF |
49 | video_id = self._find_video_id(webpage) |
50 | result = self._get_video_info(video_id) | |
51 | description = self._html_search_regex(self._DESCRIPTION_RE, | |
52 | webpage, 'video description', | |
53 | flags=re.DOTALL) | |
54 | result['description'] = description | |
55 | return result | |
56 | ||
57 | def _get_video_info(self, video_id): | |
58 | config_url = self._CONFIG_URL_TEMPLATE % video_id | |
59 | config = json.loads(self._download_webpage(config_url, video_id, | |
60 | u'Downloading video info')) | |
2ef648d3 JMF |
61 | media = config['playlist']['media'] |
62 | video_url = media['url'] | |
63 | ||
64 | return {'id': media['metadata']['videoId'], | |
65 | 'url': video_url, | |
66 | 'ext': determine_ext(video_url), | |
67 | 'title': media['metadata']['title'], | |
a95967f8 | 68 | 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'), |
2ef648d3 | 69 | } |
2ef648d3 JMF |
70 | |
71 | ||
a95967f8 JMF |
72 | class OneUPIE(IGNIE): |
73 | """Extractor for 1up.com, it uses the ign videos system.""" | |
74 | ||
ee80d667 | 75 | _VALID_URL = r'https?://gamevideos.1up.com/(?P<type>video)/id/(?P<name_or_id>.+)' |
a95967f8 JMF |
76 | IE_NAME = '1up.com' |
77 | ||
78 | _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>' | |
79 | ||
80 | _TEST = { | |
81 | u'url': u'http://gamevideos.1up.com/video/id/34976', | |
82 | u'file': u'34976.mp4', | |
83 | u'md5': u'68a54ce4ebc772e4b71e3123d413163d', | |
84 | u'info_dict': { | |
85 | u'title': u'Sniper Elite V2 - Trailer', | |
86 | u'description': u'md5:5d289b722f5a6d940ca3136e9dae89cf', | |
87 | } | |
88 | } | |
89 | ||
90 | def _real_extract(self, url): | |
91 | mobj = re.match(self._VALID_URL, url) | |
92 | id = mobj.group('name_or_id') | |
93 | result = super(OneUPIE, self)._real_extract(url) | |
94 | result['id'] = id | |
95 | return result |