]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ign.py
[vimeo:watchlater] Fix extraction (Closes #3886)
[yt-dlp.git] / youtube_dl / extractor / ign.py
CommitLineData
40c716d2
JMF
1from __future__ import unicode_literals
2
2ef648d3 3import re
2ef648d3
JMF
4
5from .common import InfoExtractor
2ef648d3 6
a95967f8 7
2ef648d3 8class IGNIE(InfoExtractor):
a95967f8
JMF
9 """
10 Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com.
11 Some videos of it.ign.com are also supported
12 """
13
ee6adb16 14 _VALID_URL = r'https?://.+?\.ign\.com/(?P<type>videos|show_videos|articles|(?:[^/]*/feature))(/.+)?/(?P<name_or_id>.+)'
40c716d2 15 IE_NAME = 'ign.com'
2ef648d3 16
a95967f8 17 _CONFIG_URL_TEMPLATE = 'http://www.ign.com/videos/configs/id/%s.config'
40c716d2
JMF
18 _DESCRIPTION_RE = [
19 r'<span class="page-object-description">(.+?)</span>',
20 r'id="my_show_video">.*?<p>(.*?)</p>',
a204c854 21 r'<meta name="description" content="(.*?)"',
40c716d2 22 ]
a95967f8 23
ee6adb16
JMF
24 _TESTS = [
25 {
40c716d2
JMF
26 'url': 'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
27 'md5': 'eac8bdc1890980122c3b66f14bdd02e9',
28 'info_dict': {
29 'id': '8f862beef863986b2785559b9e1aa599',
30 'ext': 'mp4',
31 'title': 'The Last of Us Review',
32 'description': 'md5:c8946d4260a4d43a00d5ae8ed998870c',
ee6adb16
JMF
33 }
34 },
35 {
40c716d2 36 'url': 'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind',
4d278fde
PH
37 'info_dict': {
38 'id': '100-little-things-in-gta-5-that-will-blow-your-mind',
39 },
40c716d2 40 'playlist': [
ee6adb16 41 {
40c716d2
JMF
42 'info_dict': {
43 'id': '5ebbd138523268b93c9141af17bec937',
44 'ext': 'mp4',
45 'title': 'GTA 5 Video Review',
46 'description': 'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.',
ee6adb16
JMF
47 },
48 },
49 {
40c716d2
JMF
50 'info_dict': {
51 'id': '638672ee848ae4ff108df2a296418ee2',
52 'ext': 'mp4',
53 'title': '26 Twisted Moments from GTA 5 in Slow Motion',
54 'description': 'The twisted beauty of GTA 5 in stunning slow motion.',
ee6adb16
JMF
55 },
56 },
57 ],
40c716d2
JMF
58 'params': {
59 'skip_download': True,
ee6adb16
JMF
60 },
61 },
a204c854
JMF
62 {
63 'url': 'http://www.ign.com/articles/2014/08/15/rewind-theater-wild-trailer-gamescom-2014?watch',
cc36e229 64 'md5': '618fedb9c901fd086f6f093564ef8558',
a204c854
JMF
65 'info_dict': {
66 'id': '078fdd005f6d3c02f63d795faa1b984f',
67 'ext': 'mp4',
68 'title': 'Rewind Theater - Wild Trailer Gamescom 2014',
b74e86f4
PH
69 'description': (
70 'Giant skeletons, bloody hunts, and captivating'
71 ' natural beauty take our breath away.'
72 ),
a204c854
JMF
73 },
74 },
ee6adb16 75 ]
2ef648d3 76
a95967f8 77 def _find_video_id(self, webpage):
40c716d2 78 res_id = [
109a540e 79 r'"video_id"\s*:\s*"(.*?)"',
cc36e229 80 r'class="hero-poster[^"]*?"[^>]*id="(.+?)"',
40c716d2
JMF
81 r'data-video-id="(.+?)"',
82 r'<object id="vid_(.+?)"',
83 r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
84 ]
a95967f8
JMF
85 return self._search_regex(res_id, webpage, 'video id')
86
2ef648d3
JMF
87 def _real_extract(self, url):
88 mobj = re.match(self._VALID_URL, url)
a95967f8 89 name_or_id = mobj.group('name_or_id')
f1fb2d12 90 page_type = mobj.group('type')
a95967f8 91 webpage = self._download_webpage(url, name_or_id)
a204c854 92 if page_type != 'video':
ee6adb16 93 multiple_urls = re.findall(
109a540e 94 '<param name="flashvars"[^>]*value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
ee6adb16
JMF
95 webpage)
96 if multiple_urls:
6043f1df
PH
97 entries = [self.url_result(u, ie='IGN') for u in multiple_urls]
98 return {
99 '_type': 'playlist',
100 'id': name_or_id,
101 'entries': entries,
102 }
ee6adb16 103
a95967f8
JMF
104 video_id = self._find_video_id(webpage)
105 result = self._get_video_info(video_id)
106 description = self._html_search_regex(self._DESCRIPTION_RE,
9e1a5b84 107 webpage, 'video description', flags=re.DOTALL)
a95967f8
JMF
108 result['description'] = description
109 return result
110
111 def _get_video_info(self, video_id):
112 config_url = self._CONFIG_URL_TEMPLATE % video_id
40c716d2 113 config = self._download_json(config_url, video_id)
2ef648d3 114 media = config['playlist']['media']
2ef648d3 115
40c716d2
JMF
116 return {
117 'id': media['metadata']['videoId'],
118 'url': media['url'],
119 'title': media['metadata']['title'],
120 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
121 }
2ef648d3
JMF
122
123
a95967f8 124class OneUPIE(IGNIE):
09b23c90 125 _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)\.html'
a95967f8
JMF
126 IE_NAME = '1up.com'
127
128 _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
129
52fadd5f 130 _TESTS = [{
09b23c90 131 'url': 'http://gamevideos.1up.com/video/id/34976.html',
40c716d2
JMF
132 'md5': '68a54ce4ebc772e4b71e3123d413163d',
133 'info_dict': {
134 'id': '34976',
135 'ext': 'mp4',
136 'title': 'Sniper Elite V2 - Trailer',
137 'description': 'md5:5d289b722f5a6d940ca3136e9dae89cf',
a95967f8 138 }
52fadd5f 139 }]
ee6adb16 140
a95967f8
JMF
141 def _real_extract(self, url):
142 mobj = re.match(self._VALID_URL, url)
a95967f8 143 result = super(OneUPIE, self)._real_extract(url)
40c716d2 144 result['id'] = mobj.group('name_or_id')
a95967f8 145 return result