Merge branch 'vgtv' of https://github.com/mrkolby/youtube-dl into mrkolby-vgtv
[youtube-dl] / youtube_dl / extractor / ign.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6
7
8 class IGNIE(InfoExtractor):
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
14     _VALID_URL = r'https?://.+?\.ign\.com/(?P<type>videos|show_videos|articles|(?:[^/]*/feature))(/.+)?/(?P<name_or_id>.+)'
15     IE_NAME = 'ign.com'
16
17     _CONFIG_URL_TEMPLATE = 'http://www.ign.com/videos/configs/id/%s.config'
18     _DESCRIPTION_RE = [
19         r'<span class="page-object-description">(.+?)</span>',
20         r'id="my_show_video">.*?<p>(.*?)</p>',
21         r'<meta name="description" content="(.*?)"',
22     ]
23
24     _TESTS = [
25         {
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',
33             }
34         },
35         {
36             'url': 'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind',
37             'playlist': [
38                 {
39                     'info_dict': {
40                         'id': '5ebbd138523268b93c9141af17bec937',
41                         'ext': 'mp4',
42                         'title': 'GTA 5 Video Review',
43                         'description': 'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.',
44                     },
45                 },
46                 {
47                     'info_dict': {
48                         'id': '638672ee848ae4ff108df2a296418ee2',
49                         'ext': 'mp4',
50                         'title': '26 Twisted Moments from GTA 5 in Slow Motion',
51                         'description': 'The twisted beauty of GTA 5 in stunning slow motion.',
52                     },
53                 },
54             ],
55             'params': {
56                 'skip_download': True,
57             },
58         },
59         {
60             'url': 'http://www.ign.com/articles/2014/08/15/rewind-theater-wild-trailer-gamescom-2014?watch',
61             'md5': '4e9a0bda1e5eebd31ddcf86ec0b9b3c7',
62             'info_dict': {
63                 'id': '078fdd005f6d3c02f63d795faa1b984f',
64                 'ext': 'mp4',
65                 'title': 'Rewind Theater - Wild Trailer Gamescom 2014',
66                 'description': 'Giant skeletons, bloody hunts, and captivating'
67                     ' natural beauty take our breath away.',
68             },
69         },
70     ]
71
72     def _find_video_id(self, webpage):
73         res_id = [
74             r'data-video-id="(.+?)"',
75             r'<object id="vid_(.+?)"',
76             r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
77             r'class="hero-poster[^"]*?"[^>]*id="(.+?)"',
78         ]
79         return self._search_regex(res_id, webpage, 'video id')
80
81     def _real_extract(self, url):
82         mobj = re.match(self._VALID_URL, url)
83         name_or_id = mobj.group('name_or_id')
84         page_type = mobj.group('type')
85         webpage = self._download_webpage(url, name_or_id)
86         if page_type != 'video':
87             multiple_urls = re.findall(
88                 '<param name="flashvars" value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
89                 webpage)
90             if multiple_urls:
91                 return [self.url_result(u, ie='IGN') for u in multiple_urls]
92
93         video_id = self._find_video_id(webpage)
94         result = self._get_video_info(video_id)
95         description = self._html_search_regex(self._DESCRIPTION_RE,
96             webpage, 'video description', flags=re.DOTALL)
97         result['description'] = description
98         return result
99
100     def _get_video_info(self, video_id):
101         config_url = self._CONFIG_URL_TEMPLATE % video_id
102         config = self._download_json(config_url, video_id)
103         media = config['playlist']['media']
104
105         return {
106             'id': media['metadata']['videoId'],
107             'url': media['url'],
108             'title': media['metadata']['title'],
109             'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
110         }
111
112
113 class OneUPIE(IGNIE):
114     _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)'
115     IE_NAME = '1up.com'
116
117     _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
118
119     _TESTS = [{
120         'url': 'http://gamevideos.1up.com/video/id/34976',
121         'md5': '68a54ce4ebc772e4b71e3123d413163d',
122         'info_dict': {
123             'id': '34976',
124             'ext': 'mp4',
125             'title': 'Sniper Elite V2 - Trailer',
126             'description': 'md5:5d289b722f5a6d940ca3136e9dae89cf',
127         }
128     }]
129
130     def _real_extract(self, url):
131         mobj = re.match(self._VALID_URL, url)
132         result = super(OneUPIE, self)._real_extract(url)
133         result['id'] = mobj.group('name_or_id')
134         return result