]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/atresplayer.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / atresplayer.py
CommitLineData
6b597516 1from .common import InfoExtractor
3d2623a8 2from ..networking.exceptions import HTTPError
c8dfe360 3from ..utils import (
6e6bc8da 4 ExtractorError,
6e6bc8da 5 int_or_none,
6e6bc8da 6 urlencode_postdata,
a3498732
S
7)
8
9
6b597516 10class AtresPlayerIE(InfoExtractor):
6d394a66 11 _VALID_URL = r'https?://(?:www\.)?atresplayer\.com/[^/]+/[^/]+/[^/]+/[^/]+/(?P<display_id>.+?)_(?P<id>[0-9a-f]{24})'
499bfcbf 12 _NETRC_MACHINE = 'atresplayer'
a3498732
S
13 _TESTS = [
14 {
6d394a66 15 'url': 'https://www.atresplayer.com/antena3/series/pequenas-coincidencias/temporada-1/capitulo-7-asuntos-pendientes_5d4aa2c57ed1a88fc715a615/',
a3498732 16 'info_dict': {
6d394a66 17 'id': '5d4aa2c57ed1a88fc715a615',
a3498732 18 'ext': 'mp4',
6d394a66
RA
19 'title': 'Capítulo 7: Asuntos pendientes',
20 'description': 'md5:7634cdcb4d50d5381bedf93efb537fbc',
21 'duration': 3413,
22 },
add96eb9 23 'skip': 'This video is only available for registered users',
61ebb401 24 },
25 {
6d394a66
RA
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,
a3498732
S
28 },
29 {
6d394a66 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/',
a3498732
S
31 'only_matching': True,
32 },
33 ]
6d394a66 34 _API_BASE = 'https://api.atresplayer.com/'
61ebb401 35
52efa4b3 36 def _perform_login(self, username, password):
6d394a66
RA
37 self._request_webpage(
38 self._API_BASE + 'login', None, 'Downloading login page')
c8dfe360 39
6d394a66
RA
40 try:
41 target_url = self._download_json(
42 'https://account.atresmedia.com/api/login', None,
43 'Logging in', headers={
add96eb9 44 'Content-Type': 'application/x-www-form-urlencoded',
6d394a66
RA
45 }, data=urlencode_postdata({
46 'username': username,
47 'password': password,
48 }))['targetUrl']
49 except ExtractorError as e:
7814c509 50 if isinstance(e.cause, HTTPError) and e.cause.status == 400:
51 raise ExtractorError('Invalid username and/or password', expected=True)
52 raise
c8dfe360 53
6d394a66 54 self._request_webpage(target_url, None, 'Following Target URL')
c8dfe360 55
a3498732 56 def _real_extract(self, url):
5ad28e7f 57 display_id, video_id = self._match_valid_url(url).groups()
a3498732 58
6d394a66
RA
59 try:
60 episode = self._download_json(
61 self._API_BASE + 'client/v1/player/episode/' + video_id, video_id)
62 except ExtractorError as e:
7814c509 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
a3498732 69
6d394a66 70 title = episode['titulo']
61ebb401 71
72 formats = []
c811e8d8 73 subtitles = {}
6d394a66
RA
74 for source in episode.get('sources', []):
75 src = source.get('src')
76 if not src:
61ebb401 77 continue
6d394a66
RA
78 src_type = source.get('type')
79 if src_type == 'application/vnd.apple.mpegurl':
c811e8d8 80 formats, subtitles = self._extract_m3u8_formats(
6d394a66 81 src, video_id, 'mp4', 'm3u8_native',
c811e8d8 82 m3u8_id='hls', fatal=False)
6d394a66 83 elif src_type == 'application/dash+xml':
c811e8d8
F
84 formats, subtitles = self._extract_mpd_formats(
85 src, video_id, mpd_id='dash', fatal=False)
a3498732 86
6d394a66
RA
87 heartbeat = episode.get('heartbeat') or {}
88 omniture = episode.get('omniture') or {}
89 get_meta = lambda x: heartbeat.get(x) or omniture.get(x)
0c172788 90
a3498732 91 return {
6d394a66 92 'display_id': display_id,
a3498732
S
93 'id': video_id,
94 'title': title,
6d394a66
RA
95 'description': episode.get('descripcion'),
96 'thumbnail': episode.get('imgPoster'),
97 'duration': int_or_none(episode.get('duration')),
a3498732 98 'formats': formats,
6d394a66
RA
99 'channel': get_meta('channel'),
100 'season': get_meta('season'),
101 'episode_number': int_or_none(get_meta('episodeNumber')),
c811e8d8 102 'subtitles': subtitles,
a3498732 103 }