2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  22 class OnetBaseIE(InfoExtractor
): 
  23     _URL_BASE_RE 
= r
'https?://(?:(?:www\.)?onet\.tv|onet100\.vod\.pl)/[a-z]/' 
  25     def _search_mvp_id(self
, webpage
): 
  26         return self
._search
_regex
( 
  27             r
'id=(["\'])mvp
:(?P
<id>.+?
)\
1', webpage, 'mvp 
id', group='id') 
  29     def _extract_from_id(self, video_id, webpage=None): 
  30         response = self._download_json( 
  31             'http
://qi
.ckm
.onetapi
.pl
/', video_id, 
  34                 'body
[jsonrpc
]': '2.0', 
  35                 'body
[method
]': 'get_asset_detail
', 
  36                 'body
[params
][ID_Publikacji
]': video_id, 
  37                 'body
[params
][Service
]': 'www
.onet
.pl
', 
  38                 'content
-type': 'application
/jsonp
', 
  39                 'x
-onet
-app
': 'player
.front
.onetapi
.pl
', 
  42         error = response.get('error
') 
  45                 '%s said
: %s' % (self.IE_NAME, error['message
']), expected=True) 
  47         video = response['result
'].get('0') 
  50         for format_type, formats_dict in video['formats
'].items(): 
  51             if not isinstance(formats_dict, dict): 
  53             for format_id, format_list in formats_dict.items(): 
  54                 if not isinstance(format_list, list): 
  57                     video_url = f.get('url
') 
  60                     ext = determine_ext(video_url) 
  61                     if format_id.startswith('ism
'): 
  62                         formats.extend(self._extract_ism_formats( 
  63                             video_url, video_id, 'mss
', fatal=False)) 
  65                         formats.extend(self._extract_mpd_formats( 
  66                             video_url, video_id, mpd_id='dash
', fatal=False)) 
  67                     elif format_id.startswith('hls
'): 
  68                         formats.extend(self._extract_m3u8_formats( 
  69                             video_url, video_id, 'mp4
', 'm3u8_native
', 
  70                             m3u8_id='hls
', fatal=False)) 
  74                             'format_id
': format_id, 
  75                             'abr
': float_or_none(f.get('audio_bitrate
')), 
  77                         if format_type == 'audio
': 
  78                             http_f['vcodec
'] = 'none
' 
  81                                 'height
': int_or_none(f.get('vertical_resolution
')), 
  82                                 'width
': int_or_none(f.get('horizontal_resolution
')), 
  83                                 'vbr
': float_or_none(f.get('video_bitrate
')), 
  85                         formats.append(http_f) 
  86         self._sort_formats(formats) 
  88         meta = video.get('meta
', {}) 
  90         title = (self._og_search_title( 
  91             webpage, default=None) if webpage else None) or meta['title
'] 
  92         description = (self._og_search_description( 
  93             webpage, default=None) if webpage else None) or meta.get('description
') 
  94         duration = meta.get('length
') or meta.get('lenght
') 
  95         timestamp = parse_iso8601(meta.get('addDate
'), ' ') 
 100             'description
': description, 
 101             'duration
': duration, 
 102             'timestamp
': timestamp, 
 107 class OnetMVPIE(OnetBaseIE): 
 108     _VALID_URL = r'onetmvp
:(?P
<id>\d
+\
.\d
+)' 
 111         'url
': 'onetmvp
:381027.1509591944', 
 112         'only_matching
': True, 
 115     def _real_extract(self, url): 
 116         return self._extract_from_id(self._match_id(url)) 
 119 class OnetIE(OnetBaseIE): 
 120     _VALID_URL = OnetBaseIE._URL_BASE_RE + r'[a
-z
]+/(?P
<display_id
>[0-9a
-z
-]+)/(?P
<id>[0-9a
-z
]+)' 
 124         'url
': 'http
://onet
.tv
/k
/openerfestival
/open-er
-festival
-2016-najdziwniejsze
-wymagania
-gwiazd
/qbpyqc
', 
 125         'md5
': '436102770fb095c75b8bb0392d3da9ff
', 
 128             'display_id
': 'open-er
-festival
-2016-najdziwniejsze
-wymagania
-gwiazd
', 
 130             'title
': 'Open
\'er Festival 
2016: najdziwniejsze wymagania gwiazd
', 
 131             'description
': 'Trzy samochody
, których nigdy nie użyto
, prywatne spa
, hotel dekorowany czarnym suknem czy nielegalne używki
. Organizatorzy koncertów i festiwali muszą stawać przed nie lada wyzwaniem zapraszając gwia
...', 
 132             'upload_date
': '20160705', 
 133             'timestamp
': 1467721580, 
 136         'url
': 'https
://onet100
.vod
.pl
/k
/openerfestival
/open-er
-festival
-2016-najdziwniejsze
-wymagania
-gwiazd
/qbpyqc
', 
 137         'only_matching
': True, 
 140     def _real_extract(self, url): 
 141         mobj = re.match(self._VALID_URL, url) 
 142         display_id, video_id = mobj.group('display_id
', 'id') 
 144         webpage = self._download_webpage(url, display_id) 
 146         mvp_id = self._search_mvp_id(webpage) 
 148         info_dict = self._extract_from_id(mvp_id, webpage) 
 151             'display_id
': display_id, 
 157 class OnetChannelIE(OnetBaseIE): 
 158     _VALID_URL = OnetBaseIE._URL_BASE_RE + r'(?P
<id>[a
-z
]+)(?
:[?
#]|$)' 
 159     IE_NAME 
= 'onet.tv:channel' 
 162         'url': 'http://onet.tv/k/openerfestival', 
 164             'id': 'openerfestival', 
 165             'title': "Open'er Festival", 
 166             'description': "Tak było na Open'er Festival 2016! Oglądaj nasze reportaże i wywiady z artystami.", 
 168         'playlist_mincount': 35, 
 170         'url': 'https://onet100.vod.pl/k/openerfestival', 
 171         'only_matching': True, 
 174     def _real_extract(self
, url
): 
 175         channel_id 
= self
._match
_id
(url
) 
 177         webpage 
= self
._download
_webpage
(url
, channel_id
) 
 179         current_clip_info 
= self
._parse
_json
(self
._search
_regex
( 
 180             r
'var\s+currentClip\s*=\s*({[^}]+})', webpage
, 'video info'), channel_id
, 
 181             transform_source
=lambda s
: js_to_json(re
.sub(r
'\'\s
*\
+\s
*\'', '', s))) 
 182         video_id = remove_start(current_clip_info['ckmId
'], 'mvp
:') 
 183         video_name = url_basename(current_clip_info['url
']) 
 185         if self._downloader.params.get('noplaylist
'): 
 187                 'Downloading just video 
%s because of 
--no
-playlist
' % video_name) 
 188             return self._extract_from_id(video_id, webpage) 
 191             'Downloading channel 
%s - add 
--no
-playlist to just download video 
%s' % ( 
 192                 channel_id, video_name)) 
 193         matches = re.findall( 
 194             r'<a
[^
>]+href
=[\'"](%s[a-z]+/[0-9a-z-]+/[0-9a-z]+)' % self._URL_BASE_RE, 
 197             self.url_result(video_link, OnetIE.ie_key()) 
 198             for video_link in matches] 
 200         channel_title = strip_or_none(get_element_by_class('o_channelName', webpage)) 
 201         channel_description = strip_or_none(get_element_by_class('o_channelDesc', webpage)) 
 202         return self.playlist_result(entries, channel_id, channel_title, channel_description) 
 205 class OnetPlIE(InfoExtractor): 
 206     _VALID_URL = r'https?://(?:[^/]+\.)?(?:onet|businessinsider\.com|plejada)\.pl/(?:[^/]+/)+(?P<id>[0-9a-z]+)' 
 210         'url': 'http://eurosport.onet.pl/zimowe/skoki-narciarskie/ziobro-wygral-kwalifikacje-w-pjongczangu/9ckrly', 
 211         'md5': 'b94021eb56214c3969380388b6e73cb0', 
 213             'id': '1561707.1685479', 
 215             'title': 'Ziobro wygrał kwalifikacje w Pjongczangu', 
 216             'description': 'md5:61fb0740084d2d702ea96512a03585b4', 
 217             'upload_date': '20170214', 
 218             'timestamp': 1487078046, 
 221         # embedded via pulsembed 
 222         'url': 'http://film.onet.pl/pensjonat-nad-rozlewiskiem-relacja-z-planu-serialu/y428n0', 
 224             'id': '501235.965429946', 
 226             'title': '"Pensjonat nad rozlewiskiem
": relacja z planu serialu', 
 227             'upload_date': '20170622', 
 228             'timestamp': 1498159955, 
 231             'skip_download': True, 
 234         'url': 'http://film.onet.pl/zwiastuny/ghost-in-the-shell-drugi-zwiastun-pl/5q6yl3', 
 235         'only_matching': True, 
 237         'url': 'http://moto.onet.pl/jak-wybierane-sa-miejsca-na-fotoradary/6rs04e', 
 238         'only_matching': True, 
 240         'url': 'http://businessinsider.com.pl/wideo/scenariusz-na-koniec-swiata-wedlug-nasa/dwnqptk', 
 241         'only_matching': True, 
 243         'url': 'http://plejada.pl/weronika-rosati-o-swoim-domniemanym-slubie/n2bq89', 
 244         'only_matching': True, 
 247     def _search_mvp_id(self, webpage, default=NO_DEFAULT): 
 248         return self._search_regex( 
 249             r'data-(?:params-)?mvp=["\'](\d
+\
.\d
+)', webpage, 'mvp 
id', 
 252     def _real_extract(self, url): 
 253         video_id = self._match_id(url) 
 255         webpage = self._download_webpage(url, video_id) 
 257         mvp_id = self._search_mvp_id(webpage, default=None) 
 260             pulsembed_url = self._search_regex( 
 261                 r'data
-src
=(["\'])(?P<url>(?:https?:)?//pulsembed\.eu/.+?)\1', 
 262                 webpage, 'pulsembed url', group='url') 
 263             webpage = self._download_webpage( 
 264                 pulsembed_url, video_id, 'Downloading pulsembed webpage') 
 265             mvp_id = self._search_mvp_id(webpage) 
 267         return self.url_result( 
 268             'onetmvp:%s' % mvp_id, OnetMVPIE.ie_key(), video_id=mvp_id)