[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / atresplayer.py
blob0fe95bec5c8d4aeba9e27abeaea925a48ea26d9f
1 from .common import InfoExtractor
2 from ..networking.exceptions import HTTPError
3 from ..utils import (
4 ExtractorError,
5 int_or_none,
6 urlencode_postdata,
10 class AtresPlayerIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/(?P<display_id>.+?)_(?P<id>[0-9a-f]{24})'
12 _NETRC_MACHINE = 'atresplayer'
13 _TESTS = [
15 'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/',
16 'info_dict': {
17 'id': '5d4aa2c57ed1a88fc715a615',
18 'ext': 'mp4',
19 'title': 'CapĂ­tulo 7: Asuntos pendientes',
20 'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc',
21 'duration': 3413,
23 'skip': 'This video is only available for registered users',
26 'url': 'https://www.atresplayer.com/lasexta/programas/el-club-de-la-comedia/temporada-4/capitulo-10-especial-solidario-nochebuena_5ad08edf986b2855ed47adc4/',
27 'only_matching': True,
30 'url': 'https://www.atresplayer.com/antena3/series/el-secreto-de-puente-viejo/el-chico-de-los-tres-lunares/capitulo-977-29-12-14_5ad51046986b2886722ccdea/',
31 'only_matching': True,
34 _API_BASE = 'https://api.atresplayer.com/'
36 def _perform_login(self, username, password):
37 self._request_webpage(
38 self._API_BASE + 'login', None, 'Downloading login page')
40 try:
41 target_url = self._download_json(
42 'https://account.atresmedia.com/api/login', None,
43 'Logging in', headers={
44 'Content-Type': 'application/x-www-form-urlencoded',
45 }, data=urlencode_postdata({
46 'username': username,
47 'password': password,
48 }))['targetUrl']
49 except ExtractorError as e:
50 if isinstance(e.cause, HTTPError) and e.cause.status == 400:
51 raise ExtractorError('Invalid username and/or password', expected=True)
52 raise
54 self._request_webpage(target_url, None, 'Following Target URL')
56 def _real_extract(self, url):
57 display_id, video_id = self._match_valid_url(url).groups()
59 try:
60 episode = self._download_json(
61 self._API_BASE + 'client/v1/player/episode/' + video_id, video_id)
62 except ExtractorError as e:
63 if isinstance(e.cause, HTTPError) and e.cause.status == 403:
64 error = self._parse_json(e.cause.response.read(), None)
65 if error.get('error') == 'required_registered':
66 self.raise_login_required()
67 raise ExtractorError(error['error_description'], expected=True)
68 raise
70 title = episode['titulo']
72 formats = []
73 subtitles = {}
74 for source in episode.get('sources', []):
75 src = source.get('src')
76 if not src:
77 continue
78 src_type = source.get('type')
79 if src_type == 'application/vnd.apple.mpegurl':
80 formats, subtitles = self._extract_m3u8_formats(
81 src, video_id, 'mp4', 'm3u8_native',
82 m3u8_id='hls', fatal=False)
83 elif src_type == 'application/dash+xml':
84 formats, subtitles = self._extract_mpd_formats(
85 src, video_id, mpd_id='dash', fatal=False)
87 heartbeat = episode.get('heartbeat') or {}
88 omniture = episode.get('omniture') or {}
89 get_meta = lambda x: heartbeat.get(x) or omniture.get(x)
91 return {
92 'display_id': display_id,
93 'id': video_id,
94 'title': title,
95 'description': episode.get('descripcion'),
96 'thumbnail': episode.get('imgPoster'),
97 'duration': int_or_none(episode.get('duration')),
98 'formats': formats,
99 'channel': get_meta('channel'),
100 'season': get_meta('season'),
101 'episode_number': int_or_none(get_meta('episodeNumber')),
102 'subtitles': subtitles,