atresplayer.py 4.1 KB

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