]>
Commit | Line | Data |
---|---|---|
40c716d2 JMF |
1 | from __future__ import unicode_literals |
2 | ||
2ef648d3 | 3 | import re |
2ef648d3 JMF |
4 | |
5 | from .common import InfoExtractor | |
adccf336 | 6 | from ..utils import ( |
7 | int_or_none, | |
8 | parse_iso8601, | |
9 | ) | |
2ef648d3 | 10 | |
a95967f8 | 11 | |
2ef648d3 | 12 | class IGNIE(InfoExtractor): |
a95967f8 JMF |
13 | """ |
14 | Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com. | |
15 | Some videos of it.ign.com are also supported | |
16 | """ | |
17 | ||
adccf336 | 18 | _VALID_URL = r'https?://.+?\.ign\.com/(?:[^/]+/)?(?P<type>videos|show_videos|articles|feature|(?:[^/]+/\d+/video))(/.+)?/(?P<name_or_id>.+)' |
40c716d2 | 19 | IE_NAME = 'ign.com' |
2ef648d3 | 20 | |
adccf336 | 21 | _API_URL_TEMPLATE = 'http://apis.ign.com/video/v3/videos/%s' |
22 | _EMBED_RE = r'<iframe[^>]+?["\']((?:https?:)?//.+?\.ign\.com.+?/embed.+?)["\']' | |
a95967f8 | 23 | |
ee6adb16 JMF |
24 | _TESTS = [ |
25 | { | |
40c716d2 | 26 | 'url': 'http://www.ign.com/videos/2013/06/05/the-last-of-us-review', |
adccf336 | 27 | 'md5': 'febda82c4bafecd2d44b6e1a18a595f8', |
40c716d2 JMF |
28 | 'info_dict': { |
29 | 'id': '8f862beef863986b2785559b9e1aa599', | |
30 | 'ext': 'mp4', | |
31 | 'title': 'The Last of Us Review', | |
32 | 'description': 'md5:c8946d4260a4d43a00d5ae8ed998870c', | |
adccf336 | 33 | 'timestamp': 1370440800, |
34 | 'upload_date': '20130605', | |
e3e166d8 | 35 | 'uploader_id': 'cberidon@ign.com', |
ee6adb16 JMF |
36 | } |
37 | }, | |
38 | { | |
40c716d2 | 39 | 'url': 'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind', |
4d278fde PH |
40 | 'info_dict': { |
41 | 'id': '100-little-things-in-gta-5-that-will-blow-your-mind', | |
42 | }, | |
40c716d2 | 43 | 'playlist': [ |
ee6adb16 | 44 | { |
40c716d2 JMF |
45 | 'info_dict': { |
46 | 'id': '5ebbd138523268b93c9141af17bec937', | |
47 | 'ext': 'mp4', | |
48 | 'title': 'GTA 5 Video Review', | |
49 | 'description': 'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.', | |
adccf336 | 50 | 'timestamp': 1379339880, |
51 | 'upload_date': '20130916', | |
e3e166d8 | 52 | 'uploader_id': 'danieljkrupa@gmail.com', |
ee6adb16 JMF |
53 | }, |
54 | }, | |
55 | { | |
40c716d2 JMF |
56 | 'info_dict': { |
57 | 'id': '638672ee848ae4ff108df2a296418ee2', | |
58 | 'ext': 'mp4', | |
59 | 'title': '26 Twisted Moments from GTA 5 in Slow Motion', | |
60 | 'description': 'The twisted beauty of GTA 5 in stunning slow motion.', | |
adccf336 | 61 | 'timestamp': 1386878820, |
62 | 'upload_date': '20131212', | |
e3e166d8 | 63 | 'uploader_id': 'togilvie@ign.com', |
ee6adb16 JMF |
64 | }, |
65 | }, | |
66 | ], | |
40c716d2 JMF |
67 | 'params': { |
68 | 'skip_download': True, | |
ee6adb16 JMF |
69 | }, |
70 | }, | |
a204c854 JMF |
71 | { |
72 | 'url': 'http://www.ign.com/articles/2014/08/15/rewind-theater-wild-trailer-gamescom-2014?watch', | |
cc36e229 | 73 | 'md5': '618fedb9c901fd086f6f093564ef8558', |
a204c854 JMF |
74 | 'info_dict': { |
75 | 'id': '078fdd005f6d3c02f63d795faa1b984f', | |
76 | 'ext': 'mp4', | |
77 | 'title': 'Rewind Theater - Wild Trailer Gamescom 2014', | |
adccf336 | 78 | 'description': 'Brian and Jared explore Michel Ancel\'s captivating new preview.', |
79 | 'timestamp': 1408047180, | |
80 | 'upload_date': '20140814', | |
e3e166d8 | 81 | 'uploader_id': 'jamesduggan1990@gmail.com', |
a204c854 JMF |
82 | }, |
83 | }, | |
db8e38b8 | 84 | { |
85 | 'url': 'http://me.ign.com/en/videos/112203/video/how-hitman-aims-to-be-different-than-every-other-s', | |
86 | 'only_matching': True, | |
87 | }, | |
88 | { | |
89 | 'url': 'http://me.ign.com/ar/angry-birds-2/106533/video/lrd-ldyy-lwl-lfylm-angry-birds', | |
90 | 'only_matching': True, | |
91 | }, | |
5744cf6c A |
92 | { |
93 | # videoId pattern | |
94 | 'url': 'http://www.ign.com/articles/2017/06/08/new-ducktales-short-donalds-birthday-doesnt-go-as-planned', | |
95 | 'only_matching': True, | |
96 | }, | |
ee6adb16 | 97 | ] |
2ef648d3 | 98 | |
a95967f8 | 99 | def _find_video_id(self, webpage): |
40c716d2 | 100 | res_id = [ |
109a540e | 101 | r'"video_id"\s*:\s*"(.*?)"', |
cc36e229 | 102 | r'class="hero-poster[^"]*?"[^>]*id="(.+?)"', |
40c716d2 JMF |
103 | r'data-video-id="(.+?)"', |
104 | r'<object id="vid_(.+?)"', | |
105 | r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"', | |
5744cf6c A |
106 | r'videoId"\s*:\s*"(.+?)"', |
107 | r'videoId["\']\s*:\s*["\']([^"\']+?)["\']', | |
40c716d2 | 108 | ] |
adccf336 | 109 | return self._search_regex(res_id, webpage, 'video id', default=None) |
a95967f8 | 110 | |
2ef648d3 JMF |
111 | def _real_extract(self, url): |
112 | mobj = re.match(self._VALID_URL, url) | |
a95967f8 | 113 | name_or_id = mobj.group('name_or_id') |
f1fb2d12 | 114 | page_type = mobj.group('type') |
a95967f8 | 115 | webpage = self._download_webpage(url, name_or_id) |
a204c854 | 116 | if page_type != 'video': |
ee6adb16 | 117 | multiple_urls = re.findall( |
e3e166d8 | 118 | r'<param name="flashvars"[^>]*value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]', |
607d65fb | 119 | webpage) |
ee6adb16 | 120 | if multiple_urls: |
6043f1df PH |
121 | entries = [self.url_result(u, ie='IGN') for u in multiple_urls] |
122 | return { | |
123 | '_type': 'playlist', | |
124 | 'id': name_or_id, | |
125 | 'entries': entries, | |
126 | } | |
ee6adb16 | 127 | |
a95967f8 | 128 | video_id = self._find_video_id(webpage) |
adccf336 | 129 | if not video_id: |
f889ac45 | 130 | return self.url_result(self._search_regex( |
131 | self._EMBED_RE, webpage, 'embed url')) | |
adccf336 | 132 | return self._get_video_info(video_id) |
a95967f8 JMF |
133 | |
134 | def _get_video_info(self, video_id): | |
f889ac45 | 135 | api_data = self._download_json( |
136 | self._API_URL_TEMPLATE % video_id, video_id) | |
adccf336 | 137 | |
138 | formats = [] | |
139 | m3u8_url = api_data['refs'].get('m3uUrl') | |
140 | if m3u8_url: | |
f889ac45 | 141 | formats.extend(self._extract_m3u8_formats( |
142 | m3u8_url, video_id, 'mp4', 'm3u8_native', | |
143 | m3u8_id='hls', fatal=False)) | |
adccf336 | 144 | f4m_url = api_data['refs'].get('f4mUrl') |
145 | if f4m_url: | |
f889ac45 | 146 | formats.extend(self._extract_f4m_formats( |
147 | f4m_url, video_id, f4m_id='hds', fatal=False)) | |
adccf336 | 148 | for asset in api_data['assets']: |
149 | formats.append({ | |
150 | 'url': asset['url'], | |
151 | 'tbr': asset.get('actual_bitrate_kbps'), | |
152 | 'fps': asset.get('frame_rate'), | |
153 | 'height': int_or_none(asset.get('height')), | |
154 | 'width': int_or_none(asset.get('width')), | |
155 | }) | |
156 | self._sort_formats(formats) | |
157 | ||
e3e166d8 | 158 | thumbnails = [{ |
159 | 'url': thumbnail['url'] | |
160 | } for thumbnail in api_data.get('thumbnails', [])] | |
adccf336 | 161 | |
162 | metadata = api_data['metadata'] | |
2ef648d3 | 163 | |
40c716d2 | 164 | return { |
adccf336 | 165 | 'id': api_data.get('videoId') or video_id, |
166 | 'title': metadata.get('longTitle') or metadata.get('name') or metadata.get['title'], | |
167 | 'description': metadata.get('description'), | |
168 | 'timestamp': parse_iso8601(metadata.get('publishDate')), | |
169 | 'duration': int_or_none(metadata.get('duration')), | |
170 | 'display_id': metadata.get('slug') or video_id, | |
e3e166d8 | 171 | 'uploader_id': metadata.get('creator'), |
adccf336 | 172 | 'thumbnails': thumbnails, |
173 | 'formats': formats, | |
40c716d2 | 174 | } |
2ef648d3 JMF |
175 | |
176 | ||
a95967f8 | 177 | class OneUPIE(IGNIE): |
09b23c90 | 178 | _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)\.html' |
a95967f8 JMF |
179 | IE_NAME = '1up.com' |
180 | ||
52fadd5f | 181 | _TESTS = [{ |
09b23c90 | 182 | 'url': 'http://gamevideos.1up.com/video/id/34976.html', |
adccf336 | 183 | 'md5': 'c9cc69e07acb675c31a16719f909e347', |
40c716d2 JMF |
184 | 'info_dict': { |
185 | 'id': '34976', | |
186 | 'ext': 'mp4', | |
187 | 'title': 'Sniper Elite V2 - Trailer', | |
adccf336 | 188 | 'description': 'md5:bf0516c5ee32a3217aa703e9b1bc7826', |
189 | 'timestamp': 1313099220, | |
190 | 'upload_date': '20110811', | |
e3e166d8 | 191 | 'uploader_id': 'IGN', |
a95967f8 | 192 | } |
52fadd5f | 193 | }] |
ee6adb16 | 194 | |
a95967f8 JMF |
195 | def _real_extract(self, url): |
196 | mobj = re.match(self._VALID_URL, url) | |
a95967f8 | 197 | result = super(OneUPIE, self)._real_extract(url) |
40c716d2 | 198 | result['id'] = mobj.group('name_or_id') |
a95967f8 | 199 | return result |
adccf336 | 200 | |
201 | ||
202 | class PCMagIE(IGNIE): | |
203 | _VALID_URL = r'https?://(?:www\.)?pcmag\.com/(?P<type>videos|article2)(/.+)?/(?P<name_or_id>.+)' | |
204 | IE_NAME = 'pcmag' | |
205 | ||
197224b7 | 206 | _EMBED_RE = r'iframe\.setAttribute\("src",\s*__util.objToUrlString\("http://widgets\.ign\.com/video/embed/content\.html?[^"]*url=([^"]+)["&]' |
adccf336 | 207 | |
208 | _TESTS = [{ | |
209 | 'url': 'http://www.pcmag.com/videos/2015/01/06/010615-whats-new-now-is-gogo-snooping-on-your-data', | |
210 | 'md5': '212d6154fd0361a2781075f1febbe9ad', | |
211 | 'info_dict': { | |
212 | 'id': 'ee10d774b508c9b8ec07e763b9125b91', | |
213 | 'ext': 'mp4', | |
214 | 'title': '010615_What\'s New Now: Is GoGo Snooping on Your Data?', | |
215 | 'description': 'md5:a7071ae64d2f68cc821c729d4ded6bb3', | |
216 | 'timestamp': 1420571160, | |
217 | 'upload_date': '20150106', | |
e3e166d8 | 218 | 'uploader_id': 'cozzipix@gmail.com', |
adccf336 | 219 | } |
607d65fb | 220 | }, { |
adccf336 | 221 | 'url': 'http://www.pcmag.com/article2/0,2817,2470156,00.asp', |
222 | 'md5': '94130c1ca07ba0adb6088350681f16c1', | |
223 | 'info_dict': { | |
224 | 'id': '042e560ba94823d43afcb12ddf7142ca', | |
225 | 'ext': 'mp4', | |
226 | 'title': 'HTC\'s Weird New Re Camera - What\'s New Now', | |
227 | 'description': 'md5:53433c45df96d2ea5d0fda18be2ca908', | |
228 | 'timestamp': 1412953920, | |
229 | 'upload_date': '20141010', | |
e3e166d8 | 230 | 'uploader_id': 'chris_snyder@pcmag.com', |
adccf336 | 231 | } |
232 | }] |