]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ign.py
Merge tag 'upstream/2013.08.08'
[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/(?:videos|show_videos)(/.+)?/(?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 webpage = self._download_webpage(url, name_or_id)
45 video_id = self._find_video_id(webpage)
46 result = self._get_video_info(video_id)
47 description = self._html_search_regex(self._DESCRIPTION_RE,
48 webpage, 'video description',
49 flags=re.DOTALL)
50 result['description'] = description
51 return result
52
53 def _get_video_info(self, video_id):
54 config_url = self._CONFIG_URL_TEMPLATE % video_id
55 config = json.loads(self._download_webpage(config_url, video_id,
56 u'Downloading video info'))
57 media = config['playlist']['media']
58 video_url = media['url']
59
60 return {'id': media['metadata']['videoId'],
61 'url': video_url,
62 'ext': determine_ext(video_url),
63 'title': media['metadata']['title'],
64 'thumbnail': media['poster'][0]['url'].replace('{size}', 'grande'),
65 }
66
67
68 class OneUPIE(IGNIE):
69 """Extractor for 1up.com, it uses the ign videos system."""
70
71 _VALID_URL = r'https?://gamevideos.1up.com/video/id/(?P<name_or_id>.+)'
72 IE_NAME = '1up.com'
73
74 _DESCRIPTION_RE = r'<div id="vid_summary">(.+?)</div>'
75
76 _TEST = {
77 u'url': u'http://gamevideos.1up.com/video/id/34976',
78 u'file': u'34976.mp4',
79 u'md5': u'68a54ce4ebc772e4b71e3123d413163d',
80 u'info_dict': {
81 u'title': u'Sniper Elite V2 - Trailer',
82 u'description': u'md5:5d289b722f5a6d940ca3136e9dae89cf',
83 }
84 }
85
86 def _real_extract(self, url):
87 mobj = re.match(self._VALID_URL, url)
88 id = mobj.group('name_or_id')
89 result = super(OneUPIE, self)._real_extract(url)
90 result['id'] = id
91 return result