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