1 from __future__ 
import unicode_literals
 
   5 from .once 
import OnceIE
 
   7     compat_urllib_parse_unquote
, 
  16 class GameSpotIE(OnceIE
): 
  17     _VALID_URL 
= r
'https?://(?:www\.)?gamespot\.com/.*-(?P<id>\d+)/?' 
  19         'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/', 
  20         'md5': 'b2a30deaa8654fcccd43713a6b6a4825', 
  22             'id': 'gs-2300-6410818', 
  24             'title': 'Arma 3 - Community Guide: SITREP I', 
  25             'description': 'Check out this video where some of the basics of Arma 3 is explained.', 
  28         'url': 'http://www.gamespot.com/videos/the-witcher-3-wild-hunt-xbox-one-now-playing/2300-6424837/', 
  30             'id': 'gs-2300-6424837', 
  32             'title': 'Now Playing - The Witcher 3: Wild Hunt', 
  33             'description': 'Join us as we take a look at the early hours of The Witcher 3: Wild Hunt and more.', 
  36             'skip_download': True,  # m3u8 downloads 
  40     def _real_extract(self
, url
): 
  41         page_id 
= self
._match
_id
(url
) 
  42         webpage 
= self
._download
_webpage
(url
, page_id
) 
  43         data_video_json 
= self
._search
_regex
( 
  44             r
'data-video=["\'](.*?
)["\']', webpage, 'data video') 
  45         data_video = self._parse_json(unescapeHTML(data_video_json), page_id) 
  46         streams = data_video['videoStreams'] 
  50         f4m_url = streams.get('f4m_stream') 
  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') 
  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( 
  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) 
  74                     qualities = list(map(lambda q: int(q), qualities.strip(',').split(','))) 
  76                     http_template = re.sub(QUALITIES_RE, r'%d', qualities_basename) 
  77                     http_url_basename = url_basename(progressive_url) 
  79                         self._sort_formats(m3u8_formats) 
  80                         m3u8_formats = list(filter( 
  81                             lambda f: f.get('vcodec') != 'none', m3u8_formats)) 
  82                     if len(qualities) == len(m3u8_formats): 
  83                         for q, m3u8_format in zip(qualities, m3u8_formats): 
  84                             f = m3u8_format.copy() 
  86                                 'url': progressive_url.replace( 
  87                                     http_url_basename, http_template % q), 
  88                                 'format_id': f['format_id'].replace('hls', 'http'), 
  95                                 'url': progressive_url.replace( 
  96                                     http_url_basename, http_template % q), 
  98                                 'format_id': 'http-%d' % q, 
 102         onceux_json = self._search_regex( 
 103             r'data-onceux-options=["\'](.*?
)["\']', webpage, 'data video', default=None) 
 105             onceux_url = self._parse_json(unescapeHTML(onceux_json), page_id).get('metadataUri') 
 107                 formats.extend(self._extract_once_formats(re.sub( 
 108                     r'https?://[^/]+', 'http://once.unicornmedia.com', onceux_url).replace('ads/vmap/', ''))) 
 111             for quality in ['sd', 'hd']: 
 112                 # It's actually a link to a flv file 
 113                 flv_url = streams.get('f4m_{0}'.format(quality)) 
 114                 if flv_url is not None: 
 118                         'format_id': quality, 
 120         self._sort_formats(formats) 
 123             'id': data_video['guid'], 
 124             'display_id': page_id, 
 125             'title': compat_urllib_parse_unquote(data_video['title']), 
 127             'description': self._html_search_meta('description', webpage), 
 128             'thumbnail': self._og_search_thumbnail(webpage),