]>
Commit | Line | Data |
---|---|---|
c1195541 PH |
1 | from __future__ import unicode_literals |
2 | ||
bf64ff72 | 3 | import re |
c45aa560 | 4 | import json |
bf64ff72 YK |
5 | |
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
ebdf2af7 | 8 | compat_urllib_parse, |
c45aa560 JMF |
9 | compat_urlparse, |
10 | unescapeHTML, | |
11 | get_meta_content, | |
bf64ff72 YK |
12 | ) |
13 | ||
c45aa560 | 14 | |
bf64ff72 | 15 | class GameSpotIE(InfoExtractor): |
ebdf2af7 | 16 | _VALID_URL = r'(?:http://)?(?:www\.)?gamespot\.com/.*-(?P<page_id>\d+)/?' |
bf64ff72 | 17 | _TEST = { |
c1195541 PH |
18 | "url": "http://www.gamespot.com/arma-iii/videos/arma-iii-community-guide-sitrep-i-6410818/", |
19 | "file": "gs-2300-6410818.mp4", | |
20 | "md5": "b2a30deaa8654fcccd43713a6b6a4825", | |
21 | "info_dict": { | |
22 | "title": "Arma 3 - Community Guide: SITREP I", | |
23 | 'description': 'Check out this video where some of the basics of Arma 3 is explained.', | |
bf64ff72 YK |
24 | } |
25 | } | |
26 | ||
bf64ff72 YK |
27 | def _real_extract(self, url): |
28 | mobj = re.match(self._VALID_URL, url) | |
f3682997 | 29 | page_id = mobj.group('page_id') |
ebdf2af7 | 30 | webpage = self._download_webpage(url, page_id) |
12ed5741 | 31 | data_video_json = self._search_regex(r'data-video=["\'](.*?)["\']', webpage, 'data video') |
c45aa560 | 32 | data_video = json.loads(unescapeHTML(data_video_json)) |
bf64ff72 | 33 | |
c45aa560 JMF |
34 | # Transform the manifest url to a link to the mp4 files |
35 | # they are used in mobile devices. | |
36 | f4m_url = data_video['videoStreams']['f4m_stream'] | |
37 | f4m_path = compat_urlparse.urlparse(f4m_url).path | |
38 | QUALITIES_RE = r'((,\d+)+,?)' | |
12ed5741 | 39 | qualities = self._search_regex(QUALITIES_RE, f4m_path, 'qualities').strip(',').split(',') |
c45aa560 JMF |
40 | http_path = f4m_path[1:].split('/', 1)[1] |
41 | http_template = re.sub(QUALITIES_RE, r'%s', http_path) | |
42 | http_template = http_template.replace('.csmil/manifest.f4m', '') | |
43 | http_template = compat_urlparse.urljoin('http://video.gamespotcdn.com/', http_template) | |
44 | formats = [] | |
45 | for q in qualities: | |
46 | formats.append({ | |
47 | 'url': http_template % q, | |
48 | 'ext': 'mp4', | |
49 | 'format_id': q, | |
50 | }) | |
bf64ff72 | 51 | |
fb7abb31 | 52 | return { |
c45aa560 JMF |
53 | 'id': data_video['guid'], |
54 | 'title': compat_urllib_parse.unquote(data_video['title']), | |
55 | 'formats': formats, | |
56 | 'description': get_meta_content('description', webpage), | |
57 | 'thumbnail': self._og_search_thumbnail(webpage), | |
58 | } |