4 from .common
import InfoExtractor
5 from ..compat
import compat_urllib_parse_urlparse
20 class RuutuIE(InfoExtractor
):
24 (?:www\.)?(?:ruutu|supla)\.fi/(?:video|supla|audio)/|
25 static\.nelonenmedia\.fi/player/misc/embed_player\.html\?.*?\bnid=
31 'url': 'http://www.ruutu.fi/video/2058907',
32 'md5': 'ab2093f39be1ca8581963451b3c0234f',
36 'title': 'Oletko aina halunnut tietää mitä tapahtuu vain hetki ennen lähetystä? - Nyt se selvisi!',
37 'description': 'md5:cfc6ccf0e57a814360df464a91ff67d6',
38 'thumbnail': r
're:^https?://.*\.jpg$',
44 'url': 'http://www.ruutu.fi/video/2057306',
45 'md5': '065a10ae4d5b8cfd9d0c3d332465e3d9',
49 'title': 'Superpesis: katso koko kausi Ruudussa',
50 'description': 'md5:bfb7336df2a12dc21d18fa696c9f8f23',
51 'thumbnail': r
're:^https?://.*\.jpg$',
57 'url': 'http://www.supla.fi/supla/2231370',
58 'md5': 'df14e782d49a2c0df03d3be2a54ef949',
62 'title': 'Osa 1: Mikael Jungner',
63 'description': 'md5:7d90f358c47542e3072ff65d7b1bcffe',
64 'thumbnail': r
're:^https?://.*\.jpg$',
68 # Episode where <SourceFile> is "NOT-USED", but has other
69 # downloadable sources available.
71 'url': 'http://www.ruutu.fi/video/3193728',
72 'only_matching': True,
76 'url': 'https://www.supla.fi/supla/3382410',
77 'md5': 'b9d7155fed37b2ebf6021d74c4b8e908',
81 'title': 'Mikä ihmeen poltergeist?',
82 'description': 'md5:bbb6963df17dfd0ecd9eb9a61bf14b52',
83 'thumbnail': r
're:^https?://.*\.jpg$',
86 'expected_warnings': [
87 'HTTP Error 502: Bad Gateway',
88 'Failed to download m3u8 information',
92 'url': 'http://www.supla.fi/audio/2231370',
93 'only_matching': True,
96 'url': 'https://static.nelonenmedia.fi/player/misc/embed_player.html?nid=3618790',
97 'only_matching': True,
101 'url': 'https://www.ruutu.fi/video/3401964',
105 'title': 'Temptation Island Suomi - Kausi 5 - Jakso 17',
106 'description': 'md5:87cf01d5e1e88adf0c8a2937d2bd42ba',
107 'thumbnail': r
're:^https?://.*\.jpg$',
110 'upload_date': '20190508',
111 'series': 'Temptation Island Suomi',
113 'episode_number': 17,
114 'categories': ['Reality ja tositapahtumat', 'Kotimaiset suosikit', 'Romantiikka ja parisuhde'],
117 'skip_download': True,
122 'url': 'https://www.ruutu.fi/video/3618715',
123 'only_matching': True,
126 _API_BASE
= 'https://gatling.nelonenmedia.fi'
129 def _extract_url(cls
, webpage
):
131 lambda: json
.loads(re
.search(
132 r
'jQuery\.extend\(Drupal\.settings, ({.+?})\);', webpage
).group(1), strict
=False))
133 video_id
= traverse_obj(settings
, (
134 'mediaCrossbowSettings', 'file', 'field_crossbow_video_id', 'und', 0, 'value'))
136 return f
'http://www.ruutu.fi/video/{video_id}'
138 def _real_extract(self
, url
):
139 video_id
= self
._match
_id
(url
)
141 video_xml
= self
._download
_xml
(
142 '%s/media-xml-cache' % self
._API
_BASE
, video_id
,
143 query
={'id': video_id}
)
148 def extract_formats(node
):
150 if child
.tag
.endswith('Files'):
151 extract_formats(child
)
152 elif child
.tag
.endswith('File'):
153 video_url
= child
.text
154 if (not video_url
or video_url
in processed_urls
155 or any(p
in video_url
for p
in ('NOT_USED', 'NOT-USED'))):
157 processed_urls
.append(video_url
)
158 ext
= determine_ext(video_url
)
159 auth_video_url
= url_or_none(self
._download
_webpage
(
160 '%s/auth/access/v2' % self
._API
_BASE
, video_id
,
161 note
='Downloading authenticated %s stream URL' % ext
,
162 fatal
=False, query
={'stream': video_url}
))
164 processed_urls
.append(auth_video_url
)
165 video_url
= auth_video_url
167 formats
.extend(self
._extract
_m
3u8_formats
(
168 video_url
, video_id
, 'mp4',
169 entry_protocol
='m3u8_native', m3u8_id
='hls',
172 formats
.extend(self
._extract
_f
4m
_formats
(
173 video_url
, video_id
, f4m_id
='hds', fatal
=False))
175 # video-only and audio-only streams are of different
176 # duration resulting in out of sync issue
178 formats
.extend(self
._extract
_mpd
_formats
(
179 video_url
, video_id
, mpd_id
='dash', fatal
=False))
180 elif ext
== 'mp3' or child
.tag
== 'AudioMediaFile':
182 'format_id': 'audio',
187 proto
= compat_urllib_parse_urlparse(video_url
).scheme
188 if not child
.tag
.startswith('HTTP') and proto
!= 'rtmp':
190 preference
= -1 if proto
== 'rtmp' else 1
191 label
= child
.get('label')
192 tbr
= int_or_none(child
.get('bitrate'))
193 format_id
= '%s-%s' % (proto
, label
if label
else tbr
) if label
or tbr
else proto
194 if not self
._is
_valid
_url
(video_url
, video_id
, format_id
):
196 width
, height
= [int_or_none(x
) for x
in child
.get('resolution', 'x').split('x')[:2]]
198 'format_id': format_id
,
203 'preference': preference
,
206 extract_formats(video_xml
.find('./Clip'))
209 node
= find_xpath_attr(
210 video_xml
, './Clip/PassthroughVariables/variable', 'name', name
)
212 return node
.get('value')
215 if (not self
.get_param('allow_unplayable_formats')
216 and xpath_text(video_xml
, './Clip/DRM', default
=None)):
217 self
.report_drm(video_id
)
218 ns_st_cds
= pv('ns_st_cds')
219 if ns_st_cds
!= 'free':
220 raise ExtractorError('This video is %s.' % ns_st_cds
, expected
=True)
222 self
._sort
_formats
(formats
)
224 themes
= pv('themes')
228 'title': xpath_attr(video_xml
, './/Behavior/Program', 'program_name', 'title', fatal
=True),
229 'description': xpath_attr(video_xml
, './/Behavior/Program', 'description', 'description'),
230 'thumbnail': xpath_attr(video_xml
, './/Behavior/Startpicture', 'href', 'thumbnail'),
231 'duration': int_or_none(xpath_text(video_xml
, './/Runtime', 'duration')) or int_or_none(pv('runtime')),
232 'age_limit': int_or_none(xpath_text(video_xml
, './/AgeLimit', 'age limit')),
233 'upload_date': unified_strdate(pv('date_start')),
234 'series': pv('series_name'),
235 'season_number': int_or_none(pv('season_number')),
236 'episode_number': int_or_none(pv('episode_number')),
237 'categories': themes
.split(',') if themes
else [],