]>
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): |
79d1f8ed | 17 | _VALID_URL = r'https?://(?:www\.)?gamespot\.com/(?:video|article)s/(?:[^/]+/\d+-|embed/)(?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 | }, | |
b0f43310 RA |
38 | }, { |
39 | 'url': 'https://www.gamespot.com/videos/embed/6439218/', | |
40 | 'only_matching': True, | |
388beb86 RA |
41 | }, { |
42 | 'url': 'https://www.gamespot.com/articles/the-last-of-us-2-receives-new-ps4-trailer/1100-6454469/', | |
43 | 'only_matching': True, | |
34fe5a94 | 44 | }] |
bf64ff72 | 45 | |
bf64ff72 | 46 | def _real_extract(self, url): |
a32f2531 | 47 | page_id = self._match_id(url) |
ebdf2af7 | 48 | webpage = self._download_webpage(url, page_id) |
a32f2531 PH |
49 | data_video_json = self._search_regex( |
50 | r'data-video=["\'](.*?)["\']', webpage, 'data video') | |
1ac5705f | 51 | data_video = self._parse_json(unescapeHTML(data_video_json), page_id) |
34fe5a94 | 52 | streams = data_video['videoStreams'] |
bf64ff72 | 53 | |
1ac5705f | 54 | manifest_url = None |
c45aa560 | 55 | formats = [] |
34fe5a94 | 56 | f4m_url = streams.get('f4m_stream') |
1ac5705f RA |
57 | if f4m_url: |
58 | manifest_url = f4m_url | |
59 | formats.extend(self._extract_f4m_formats( | |
60 | f4m_url + '?hdcore=3.7.0', page_id, f4m_id='hds', fatal=False)) | |
b0f43310 | 61 | m3u8_url = dict_get(streams, ('m3u8_stream', 'adaptive_stream')) |
1ac5705f RA |
62 | if m3u8_url: |
63 | manifest_url = m3u8_url | |
64 | m3u8_formats = self._extract_m3u8_formats( | |
65 | m3u8_url, page_id, 'mp4', 'm3u8_native', | |
66 | m3u8_id='hls', fatal=False) | |
67 | formats.extend(m3u8_formats) | |
68 | progressive_url = dict_get( | |
b0f43310 | 69 | streams, ('progressive_hd', 'progressive_high', 'progressive_low', 'other_lr')) |
1ac5705f RA |
70 | if progressive_url and manifest_url: |
71 | qualities_basename = self._search_regex( | |
ec85ded8 | 72 | r'/([^/]+)\.csmil/', |
1ac5705f RA |
73 | manifest_url, 'qualities basename', default=None) |
74 | if qualities_basename: | |
75 | QUALITIES_RE = r'((,\d+)+,?)' | |
76 | qualities = self._search_regex( | |
77 | QUALITIES_RE, qualities_basename, | |
78 | 'qualities', default=None) | |
79 | if qualities: | |
80 | qualities = list(map(lambda q: int(q), qualities.strip(',').split(','))) | |
81 | qualities.sort() | |
82 | http_template = re.sub(QUALITIES_RE, r'%d', qualities_basename) | |
83 | http_url_basename = url_basename(progressive_url) | |
84 | if m3u8_formats: | |
85 | self._sort_formats(m3u8_formats) | |
86 | m3u8_formats = list(filter( | |
ff99fe52 | 87 | lambda f: f.get('vcodec') != 'none', m3u8_formats)) |
1ac5705f RA |
88 | if len(qualities) == len(m3u8_formats): |
89 | for q, m3u8_format in zip(qualities, m3u8_formats): | |
90 | f = m3u8_format.copy() | |
91 | f.update({ | |
92 | 'url': progressive_url.replace( | |
93 | http_url_basename, http_template % q), | |
94 | 'format_id': f['format_id'].replace('hls', 'http'), | |
95 | 'protocol': 'http', | |
96 | }) | |
97 | formats.append(f) | |
98 | else: | |
99 | for q in qualities: | |
100 | formats.append({ | |
101 | 'url': progressive_url.replace( | |
102 | http_url_basename, http_template % q), | |
103 | 'ext': 'mp4', | |
104 | 'format_id': 'http-%d' % q, | |
105 | 'tbr': q, | |
106 | }) | |
107 | ||
108 | onceux_json = self._search_regex( | |
109 | r'data-onceux-options=["\'](.*?)["\']', webpage, 'data video', default=None) | |
110 | if onceux_json: | |
111 | onceux_url = self._parse_json(unescapeHTML(onceux_json), page_id).get('metadataUri') | |
112 | if onceux_url: | |
113 | formats.extend(self._extract_once_formats(re.sub( | |
a5203935 | 114 | r'https?://[^/]+', 'http://once.unicornmedia.com', onceux_url), |
d4e31b72 | 115 | http_formats_preference=-1)) |
1ac5705f RA |
116 | |
117 | if not formats: | |
34fe5a94 JMF |
118 | for quality in ['sd', 'hd']: |
119 | # It's actually a link to a flv file | |
120 | flv_url = streams.get('f4m_{0}'.format(quality)) | |
121 | if flv_url is not None: | |
122 | formats.append({ | |
123 | 'url': flv_url, | |
124 | 'ext': 'flv', | |
125 | 'format_id': quality, | |
126 | }) | |
1ac5705f | 127 | self._sort_formats(formats) |
bf64ff72 | 128 | |
fb7abb31 | 129 | return { |
c45aa560 | 130 | 'id': data_video['guid'], |
a32f2531 | 131 | 'display_id': page_id, |
1f80e360 | 132 | 'title': compat_urllib_parse_unquote(data_video['title']), |
c45aa560 | 133 | 'formats': formats, |
a32f2531 | 134 | 'description': self._html_search_meta('description', webpage), |
c45aa560 JMF |
135 | 'thumbnail': self._og_search_thumbnail(webpage), |
136 | } |