]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/ign.py
Merge branch 'ustream-embed-recorded2' of https://github.com/anovicecodemonkey/youtub...
[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     ]
22
23     _TESTS = [
24         {
25             'url': 'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
26             'md5': 'eac8bdc1890980122c3b66f14bdd02e9',
27             'info_dict': {
28                 'id': '8f862beef863986b2785559b9e1aa599',
29                 'ext': 'mp4',
30                 'title': 'The Last of Us Review',
31                 'description': 'md5:c8946d4260a4d43a00d5ae8ed998870c',
32             }
33         },
34         {
35             'url': 'http://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mind',
36             'playlist': [
37                 {
38                     'info_dict': {
39                         'id': '5ebbd138523268b93c9141af17bec937',
40                         'ext': 'mp4',
41                         'title': 'GTA 5 Video Review',
42                         'description': 'Rockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.',
43                     },
44                 },
45                 {
46                     'info_dict': {
47                         'id': '638672ee848ae4ff108df2a296418ee2',
48                         'ext': 'mp4',
49                         'title': '26 Twisted Moments from GTA 5 in Slow Motion',
50                         'description': 'The twisted beauty of GTA 5 in stunning slow motion.',
51                     },
52                 },
53             ],
54             'params': {
55                 'skip_download': True,
56             },
57         },
58     ]
59
60     def _find_video_id(self, webpage):
61         res_id = [
62             r'data-video-id="(.+?)"',
63             r'<object id="vid_(.+?)"',
64             r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
65         ]
66         return self._search_regex(res_id, webpage, 'video id')
67
68     def _real_extract(self, url):
69         mobj = re.match(self._VALID_URL, url)
70         name_or_id = mobj.group('name_or_id')
71         page_type = mobj.group('type')
72         webpage = self._download_webpage(url, name_or_id)
73         if page_type == 'articles':
74             video_url = self._search_regex(r'var videoUrl = "(.+?)"', webpage, 'video url')
75             return self.url_result(video_url, ie='IGN')
76         elif page_type != 'video':
77             multiple_urls = re.findall(
78                 '<param name="flashvars" value="[^"]*?url=(https?://www\.ign\.com/videos/.*?)["&]',
79                 webpage)
80             if multiple_urls:
81                 return [self.url_result(u, ie='IGN') for u in multiple_urls]
82
83         video_id = self._find_video_id(webpage)
84         result = self._get_video_info(video_id)
85         description = self._html_search_regex(self._DESCRIPTION_RE,
86             webpage, 'video description', flags=re.DOTALL)
87         result['description'] = description
88         return result
89
90     def _get_video_info(self, video_id):
91         config_url = self._CONFIG_URL_TEMPLATE % video_id
92         config = self._download_json(config_url, video_id)
93         media = config['playlist']['media']
94
95         return {
96             'id': media['metadata']['videoId'],
97             'url': media['url'],
98             'title': media['metadata']['title'],
99             'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
100         }
101
102
103 class OneUPIE(IGNIE):
104     _VALID_URL = r'https?://gamevideos\.1up\.com/(?P<type>video)/id/(?P<name_or_id>.+)'
105     IE_NAME = '1up.com'
106
107     _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
108
109     _TESTS = [{
110         'url': 'http://gamevideos.1up.com/video/id/34976',
111         'md5': '68a54ce4ebc772e4b71e3123d413163d',
112         'info_dict': {
113             'id': '34976',
114             'ext': 'mp4',
115             'title': 'Sniper Elite V2 - Trailer',
116             'description': 'md5:5d289b722f5a6d940ca3136e9dae89cf',
117         }
118     }]
119
120     def _real_extract(self, url):
121         mobj = re.match(self._VALID_URL, url)
122         result = super(OneUPIE, self)._real_extract(url)
123         result['id'] = mobj.group('name_or_id')
124         return result