]>
Commit | Line | Data |
---|---|---|
c1195541 PH |
1 | from __future__ import unicode_literals |
2 | ||
bf64ff72 | 3 | import re |
bf64ff72 | 4 | |
1ac5705f | 5 | from .once import OnceIE |
1cc79574 | 6 | from ..compat import ( |
1f80e360 | 7 | compat_urllib_parse_unquote, |
1cc79574 PH |
8 | ) |
9 | from ..utils import ( | |
c45aa560 | 10 | unescapeHTML, |
1ac5705f RA |
11 | url_basename, |
12 | dict_get, | |
bf64ff72 YK |
13 | ) |
14 | ||
c45aa560 | 15 | |
1ac5705f | 16 | class GameSpotIE(OnceIE): |
5886b38d | 17 | _VALID_URL = r'https?://(?:www\.)?gamespot\.com/.*-(?P<id>\d+)/?' |
34fe5a94 | 18 | _TESTS = [{ |
a2d5a4ee S |
19 | 'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/', |
20 | 'md5': 'b2a30deaa8654fcccd43713a6b6a4825', | |
21 | 'info_dict': { | |
22 | 'id': 'gs-2300-6410818', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'Arma 3 - Community Guide: SITREP I', | |
c1195541 | 25 | 'description': 'Check out this video where some of the basics of Arma 3 is explained.', |
34fe5a94 JMF |
26 | }, |
27 | }, { | |
28 | 'url': 'http://www.gamespot.com/videos/the-witcher-3-wild-hunt-xbox-one-now-playing/2300-6424837/', | |
29 | 'info_dict': { | |
30 | 'id': 'gs-2300-6424837', | |
7b0d333a NP |
31 | 'ext': 'mp4', |
32 | 'title': 'Now Playing - The Witcher 3: Wild Hunt', | |
34fe5a94 JMF |
33 | 'description': 'Join us as we take a look at the early hours of The Witcher 3: Wild Hunt and more.', |
34 | }, | |
7b0d333a NP |
35 | 'params': { |
36 | 'skip_download': True, # m3u8 downloads | |
37 | }, | |
34fe5a94 | 38 | }] |
bf64ff72 | 39 | |
bf64ff72 | 40 | def _real_extract(self, url): |
a32f2531 | 41 | page_id = self._match_id(url) |
ebdf2af7 | 42 | webpage = self._download_webpage(url, page_id) |
a32f2531 PH |
43 | data_video_json = self._search_regex( |
44 | r'data-video=["\'](.*?)["\']', webpage, 'data video') | |
1ac5705f | 45 | data_video = self._parse_json(unescapeHTML(data_video_json), page_id) |
34fe5a94 | 46 | streams = data_video['videoStreams'] |
bf64ff72 | 47 | |
1ac5705f | 48 | manifest_url = None |
c45aa560 | 49 | formats = [] |
34fe5a94 | 50 | f4m_url = streams.get('f4m_stream') |
1ac5705f RA |
51 | if f4m_url: |
52 | manifest_url = f4m_url | |
53 | formats.extend(self._extract_f4m_formats( | |
54 | f4m_url + '?hdcore=3.7.0', page_id, f4m_id='hds', fatal=False)) | |
55 | m3u8_url = streams.get('m3u8_stream') | |
56 | if m3u8_url: | |
57 | manifest_url = m3u8_url | |
58 | m3u8_formats = self._extract_m3u8_formats( | |
59 | m3u8_url, page_id, 'mp4', 'm3u8_native', | |
60 | m3u8_id='hls', fatal=False) | |
61 | formats.extend(m3u8_formats) | |
62 | progressive_url = dict_get( | |
63 | streams, ('progressive_hd', 'progressive_high', 'progressive_low')) | |
64 | if progressive_url and manifest_url: | |
65 | qualities_basename = self._search_regex( | |
ec85ded8 | 66 | r'/([^/]+)\.csmil/', |
1ac5705f RA |
67 | manifest_url, 'qualities basename', default=None) |
68 | if qualities_basename: | |
69 | QUALITIES_RE = r'((,\d+)+,?)' | |
70 | qualities = self._search_regex( | |
71 | QUALITIES_RE, qualities_basename, | |
72 | 'qualities', default=None) | |
73 | if qualities: | |
74 | qualities = list(map(lambda q: int(q), qualities.strip(',').split(','))) | |
75 | qualities.sort() | |
76 | http_template = re.sub(QUALITIES_RE, r'%d', qualities_basename) | |
77 | http_url_basename = url_basename(progressive_url) | |
78 | if m3u8_formats: | |
79 | self._sort_formats(m3u8_formats) | |
80 | m3u8_formats = list(filter( | |
81 | lambda f: f.get('vcodec') != 'none' and f.get('resolution') != 'multiple', | |
82 | m3u8_formats)) | |
83 | if len(qualities) == len(m3u8_formats): | |
84 | for q, m3u8_format in zip(qualities, m3u8_formats): | |
85 | f = m3u8_format.copy() | |
86 | f.update({ | |
87 | 'url': progressive_url.replace( | |
88 | http_url_basename, http_template % q), | |
89 | 'format_id': f['format_id'].replace('hls', 'http'), | |
90 | 'protocol': 'http', | |
91 | }) | |
92 | formats.append(f) | |
93 | else: | |
94 | for q in qualities: | |
95 | formats.append({ | |
96 | 'url': progressive_url.replace( | |
97 | http_url_basename, http_template % q), | |
98 | 'ext': 'mp4', | |
99 | 'format_id': 'http-%d' % q, | |
100 | 'tbr': q, | |
101 | }) | |
102 | ||
103 | onceux_json = self._search_regex( | |
104 | r'data-onceux-options=["\'](.*?)["\']', webpage, 'data video', default=None) | |
105 | if onceux_json: | |
106 | onceux_url = self._parse_json(unescapeHTML(onceux_json), page_id).get('metadataUri') | |
107 | if onceux_url: | |
108 | formats.extend(self._extract_once_formats(re.sub( | |
109 | r'https?://[^/]+', 'http://once.unicornmedia.com', onceux_url).replace('ads/vmap/', ''))) | |
110 | ||
111 | if not formats: | |
34fe5a94 JMF |
112 | for quality in ['sd', 'hd']: |
113 | # It's actually a link to a flv file | |
114 | flv_url = streams.get('f4m_{0}'.format(quality)) | |
115 | if flv_url is not None: | |
116 | formats.append({ | |
117 | 'url': flv_url, | |
118 | 'ext': 'flv', | |
119 | 'format_id': quality, | |
120 | }) | |
1ac5705f | 121 | self._sort_formats(formats) |
bf64ff72 | 122 | |
fb7abb31 | 123 | return { |
c45aa560 | 124 | 'id': data_video['guid'], |
a32f2531 | 125 | 'display_id': page_id, |
1f80e360 | 126 | 'title': compat_urllib_parse_unquote(data_video['title']), |
c45aa560 | 127 | 'formats': formats, |
a32f2531 | 128 | 'description': self._html_search_meta('description', webpage), |
c45aa560 JMF |
129 | 'thumbnail': self._og_search_thumbnail(webpage), |
130 | } |