eitb.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from .common import InfoExtractor
  2. from ..networking import Request
  3. from ..utils import (
  4. float_or_none,
  5. int_or_none,
  6. join_nonempty,
  7. parse_iso8601,
  8. )
  9. class EitbIE(InfoExtractor):
  10. IE_NAME = 'eitb.tv'
  11. _VALID_URL = r'https?://(?:www\.)?eitb\.tv/(?:eu/bideoa|es/video)/[^/]+/\d+/(?P<id>\d+)'
  12. _TEST = {
  13. 'url': 'http://www.eitb.tv/es/video/60-minutos-60-minutos-2013-2014/4104995148001/4090227752001/lasa-y-zabala-30-anos/',
  14. 'md5': 'edf4436247185adee3ea18ce64c47998',
  15. 'info_dict': {
  16. 'id': '4090227752001',
  17. 'ext': 'mp4',
  18. 'title': '60 minutos (Lasa y Zabala, 30 años)',
  19. 'description': 'Programa de reportajes de actualidad.',
  20. 'duration': 3996.76,
  21. 'timestamp': 1381789200,
  22. 'upload_date': '20131014',
  23. 'tags': list,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. video = self._download_json(
  29. f'http://mam.eitb.eus/mam/REST/ServiceMultiweb/Video/MULTIWEBTV/{video_id}/',
  30. video_id, 'Downloading video JSON')
  31. media = video['web_media'][0]
  32. formats = []
  33. for rendition in media['RENDITIONS']:
  34. video_url = rendition.get('PMD_URL')
  35. if not video_url:
  36. continue
  37. tbr = float_or_none(rendition.get('ENCODING_RATE'), 1000)
  38. formats.append({
  39. 'url': rendition['PMD_URL'],
  40. 'format_id': join_nonempty('http', int_or_none(tbr)),
  41. 'width': int_or_none(rendition.get('FRAME_WIDTH')),
  42. 'height': int_or_none(rendition.get('FRAME_HEIGHT')),
  43. 'tbr': tbr,
  44. })
  45. hls_url = media.get('HLS_SURL')
  46. if hls_url:
  47. request = Request(
  48. 'http://mam.eitb.eus/mam/REST/ServiceMultiweb/DomainRestrictedSecurity/TokenAuth/',
  49. headers={'Referer': url})
  50. token_data = self._download_json(
  51. request, video_id, 'Downloading auth token', fatal=False)
  52. if token_data:
  53. token = token_data.get('token')
  54. if token:
  55. formats.extend(self._extract_m3u8_formats(
  56. f'{hls_url}?hdnts={token}', video_id, m3u8_id='hls', fatal=False))
  57. hds_url = media.get('HDS_SURL')
  58. if hds_url:
  59. formats.extend(self._extract_f4m_formats(
  60. '{}?hdcore=3.7.0'.format(hds_url.replace('euskalsvod', 'euskalvod')),
  61. video_id, f4m_id='hds', fatal=False))
  62. return {
  63. 'id': video_id,
  64. 'title': media.get('NAME_ES') or media.get('name') or media['NAME_EU'],
  65. 'description': media.get('SHORT_DESC_ES') or video.get('desc_group') or media.get('SHORT_DESC_EU'),
  66. 'thumbnail': media.get('STILL_URL') or media.get('THUMBNAIL_URL'),
  67. 'duration': float_or_none(media.get('LENGTH'), 1000),
  68. 'timestamp': parse_iso8601(media.get('BROADCST_DATE'), ' '),
  69. 'tags': media.get('TAGS'),
  70. 'formats': formats,
  71. }