]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ign.py
Update changelog.
[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)(/.+)?/(?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 _TEST = {
25 u'url': u'http://www.ign.com/videos/2013/06/05/the-last-of-us-review',
26 u'file': u'8f862beef863986b2785559b9e1aa599.mp4',
27 u'md5': u'eac8bdc1890980122c3b66f14bdd02e9',
28 u'info_dict': {
29 u'title': u'The Last of Us Review',
30 u'description': u'md5:c8946d4260a4d43a00d5ae8ed998870c',
31 }
32 }
33
34 def _find_video_id(self, webpage):
35 res_id = [r'data-video-id="(.+?)"',
36 r'<object id="vid_(.+?)"',
37 r'<meta name="og:image" content=".*/(.+?)-(.+?)/.+.jpg"',
38 ]
39 return self._search_regex(res_id, webpage, 'video id')
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
43 name_or_id = mobj.group('name_or_id')
44 page_type = mobj.group('type')
45 webpage = self._download_webpage(url, name_or_id)
46 if page_type == 'articles':
47 video_url = self._search_regex(r'var videoUrl = "(.+?)"', webpage, u'video url')
48 return self.url_result(video_url, ie='IGN')
49 video_id = self._find_video_id(webpage)
50 result = self._get_video_info(video_id)
51 description = self._html_search_regex(self._DESCRIPTION_RE,
52 webpage, 'video description',
53 flags=re.DOTALL)
54 result['description'] = description
55 return result
56
57 def _get_video_info(self, video_id):
58 config_url = self._CONFIG_URL_TEMPLATE % video_id
59 config = json.loads(self._download_webpage(config_url, video_id,
60 u'Downloading video info'))
61 media = config['playlist']['media']
62 video_url = media['url']
63
64 return {'id': media['metadata']['videoId'],
65 'url': video_url,
66 'ext': determine_ext(video_url),
67 'title': media['metadata']['title'],
68 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
69 }
70
71
72 class OneUPIE(IGNIE):
73 """Extractor for 1up.com, it uses the ign videos system."""
74
75 _VALID_URL = r'https?://gamevideos.1up.com/(?P<type>video)/id/(?P<name_or_id>.+)'
76 IE_NAME = '1up.com'
77
78 _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
79
80 _TEST = {
81 u'url': u'http://gamevideos.1up.com/video/id/34976',
82 u'file': u'34976.mp4',
83 u'md5': u'68a54ce4ebc772e4b71e3123d413163d',
84 u'info_dict': {
85 u'title': u'Sniper Elite V2 - Trailer',
86 u'description': u'md5:5d289b722f5a6d940ca3136e9dae89cf',
87 }
88 }
89
90 def _real_extract(self, url):
91 mobj = re.match(self._VALID_URL, url)
92 id = mobj.group('name_or_id')
93 result = super(OneUPIE, self)._real_extract(url)
94 result['id'] = id
95 return result