]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rtp.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..utils
import js_to_json
12 class RTPIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
15 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
16 'md5': 'e736ce0c665e459ddb818546220b4ef8',
20 'title': 'Paixões Cruzadas',
21 'description': 'As paixões musicais de António Cartaxo e António Macedo',
22 'thumbnail': r
're:^https?://.*\.jpg',
25 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
26 'only_matching': True,
29 _RX_OBFUSCATION
= re
.compile(r
'''(?xs)
30 atob\s*\(\s*decodeURIComponent\s*\(\s*
31 (\[[0-9A-Za-z%,'"]*\])
32 \s*\.\s*join\(\s*(?:""|'')\s*\)\s*\)\s*\)
35 def __unobfuscate(self
, data
, *, video_id
):
36 if data
.startswith('{'):
37 data
= self
._RX
_OBFUSCATION
.sub(
39 base64
.b64decode(urllib
.parse
.unquote(
40 ''.join(self
._parse
_json
(m
.group(1), video_id
))
41 )).decode('iso-8859-1')),
43 return js_to_json(data
)
45 def _real_extract(self
, url
):
46 video_id
= self
._match
_id
(url
)
48 webpage
= self
._download
_webpage
(url
, video_id
)
49 title
= self
._html
_search
_meta
(
50 'twitter:title', webpage
, display_name
='title', fatal
=True)
52 f
, config
= self
._search
_regex
(
54 var\s+f\s*=\s*(?P<f>".*?"|{[^;]+?});\s*
55 var\s+player1\s+=\s+new\s+RTPPlayer\s*\((?P<config>{(?:(?!\*/).)+?})\);(?!\s*\*/)
57 'player config', group
=('f', 'config'))
61 lambda data
: self
.__unobfuscate
(data
, video_id
=video_id
))
62 config
= self
._parse
_json
(
64 lambda data
: self
.__unobfuscate
(data
, video_id
=video_id
))
67 if isinstance(f
, dict):
70 formats
.extend(self
._extract
_m
3u8_formats
(
71 f_hls
, video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls'))
73 f_dash
= f
.get('dash')
74 if f_dash
is not None:
75 formats
.extend(self
._extract
_mpd
_formats
(f_dash
, video_id
, mpd_id
='dash'))
80 'vcodec': 'none' if config
.get('mediaType') == 'audio' else None,
85 vtt
= config
.get('vtt')
87 for lcode
, lname
, url
in vtt
:
88 subtitles
.setdefault(lcode
, []).append({
97 'description': self
._html
_search
_meta
(['description', 'twitter:description'], webpage
),
98 'thumbnail': config
.get('poster') or self
._og
_search
_thumbnail
(webpage
),
99 'subtitles': subtitles
,