1 from .common
import InfoExtractor
2 from ..utils
import js_to_json
9 class RTPIE(InfoExtractor
):
10 _VALID_URL
= r
'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
12 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
13 'md5': 'e736ce0c665e459ddb818546220b4ef8',
17 'title': 'Paixões Cruzadas',
18 'description': 'As paixões musicais de António Cartaxo e António Macedo',
19 'thumbnail': r
're:^https?://.*\.jpg',
22 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
23 'only_matching': True,
26 _RX_OBFUSCATION
= re
.compile(r
'''(?xs)
27 atob\s*\(\s*decodeURIComponent\s*\(\s*
28 (\[[0-9A-Za-z%,'"]*\])
29 \s*\.\s*join\(\s*(?:""|'')\s*\)\s*\)\s*\)
32 def __unobfuscate(self
, data
, *, video_id
):
33 if data
.startswith('{'):
34 data
= self
._RX
_OBFUSCATION
.sub(
36 base64
.b64decode(urllib
.parse
.unquote(
37 ''.join(self
._parse
_json
(m
.group(1), video_id
))
38 )).decode('iso-8859-1')),
40 return js_to_json(data
)
42 def _real_extract(self
, url
):
43 video_id
= self
._match
_id
(url
)
45 webpage
= self
._download
_webpage
(url
, video_id
)
46 title
= self
._html
_search
_meta
(
47 'twitter:title', webpage
, display_name
='title', fatal
=True)
49 f
, config
= self
._search
_regex
(
51 var\s+f\s*=\s*(?P<f>".*?"|{[^;]+?});\s*
52 var\s+player1\s+=\s+new\s+RTPPlayer\s*\((?P<config>{(?:(?!\*/).)+?})\);(?!\s*\*/)
54 'player config', group
=('f', 'config'))
58 lambda data
: self
.__unobfuscate
(data
, video_id
=video_id
))
59 config
= self
._parse
_json
(
61 lambda data
: self
.__unobfuscate
(data
, video_id
=video_id
))
64 if isinstance(f
, dict):
67 formats
.extend(self
._extract
_m
3u8_formats
(
68 f_hls
, video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls'))
70 f_dash
= f
.get('dash')
71 if f_dash
is not None:
72 formats
.extend(self
._extract
_mpd
_formats
(f_dash
, video_id
, mpd_id
='dash'))
77 'vcodec': 'none' if config
.get('mediaType') == 'audio' else None,
82 vtt
= config
.get('vtt')
84 for lcode
, lname
, url
in vtt
:
85 subtitles
.setdefault(lcode
, []).append({
94 'description': self
._html
_search
_meta
(['description', 'twitter:description'], webpage
),
95 'thumbnail': config
.get('poster') or self
._og
_search
_thumbnail
(webpage
),
96 'subtitles': subtitles
,