You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
5.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_urlencode,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. get_element_by_attribute,
  11. int_or_none,
  12. remove_start,
  13. extract_attributes,
  14. determine_ext,
  15. )
  16. class MiTeleBaseIE(InfoExtractor):
  17. def _get_player_info(self, url, webpage):
  18. player_data = extract_attributes(self._search_regex(
  19. r'(?s)(<ms-video-player.+?</ms-video-player>)',
  20. webpage, 'ms video player'))
  21. video_id = player_data['data-media-id']
  22. config_url = compat_urlparse.urljoin(url, player_data['data-config'])
  23. config = self._download_json(
  24. config_url, video_id, 'Downloading config JSON')
  25. mmc_url = config['services']['mmc']
  26. duration = None
  27. formats = []
  28. for m_url in (mmc_url, mmc_url.replace('/flash.json', '/html5.json')):
  29. mmc = self._download_json(
  30. m_url, video_id, 'Downloading mmc JSON')
  31. if not duration:
  32. duration = int_or_none(mmc.get('duration'))
  33. for location in mmc['locations']:
  34. gat = self._proto_relative_url(location.get('gat'), 'http:')
  35. bas = location.get('bas')
  36. loc = location.get('loc')
  37. ogn = location.get('ogn')
  38. if None in (gat, bas, loc, ogn):
  39. continue
  40. token_data = {
  41. 'bas': bas,
  42. 'icd': loc,
  43. 'ogn': ogn,
  44. 'sta': '0',
  45. }
  46. media = self._download_json(
  47. '%s/?%s' % (gat, compat_urllib_parse_urlencode(token_data)),
  48. video_id, 'Downloading %s JSON' % location['loc'])
  49. file_ = media.get('file')
  50. if not file_:
  51. continue
  52. ext = determine_ext(file_)
  53. if ext == 'f4m':
  54. formats.extend(self._extract_f4m_formats(
  55. file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  56. video_id, f4m_id='hds', fatal=False))
  57. elif ext == 'm3u8':
  58. formats.extend(self._extract_m3u8_formats(
  59. file_, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  60. self._sort_formats(formats)
  61. return {
  62. 'id': video_id,
  63. 'formats': formats,
  64. 'thumbnail': player_data.get('data-poster') or config.get('poster', {}).get('imageUrl'),
  65. 'duration': duration,
  66. }
  67. class MiTeleIE(MiTeleBaseIE):
  68. IE_DESC = 'mitele.es'
  69. _VALID_URL = r'https?://www\.mitele\.es/(?:[^/]+/){3}(?P<id>[^/]+)/'
  70. _TESTS = [{
  71. 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
  72. # MD5 is unstable
  73. 'info_dict': {
  74. 'id': '0NF1jJnxS1Wu3pHrmvFyw2',
  75. 'display_id': 'programa-144',
  76. 'ext': 'mp4',
  77. 'title': 'Tor, la web invisible',
  78. 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
  79. 'series': 'Diario de',
  80. 'season': 'La redacción',
  81. 'episode': 'Programa 144',
  82. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  83. 'duration': 2913,
  84. },
  85. }, {
  86. # no explicit title
  87. 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/temporada-6/programa-226/',
  88. 'info_dict': {
  89. 'id': 'eLZSwoEd1S3pVyUm8lc6F',
  90. 'display_id': 'programa-226',
  91. 'ext': 'mp4',
  92. 'title': 'Cuarto Milenio - Temporada 6 - Programa 226',
  93. 'description': 'md5:50daf9fadefa4e62d9fc866d0c015701',
  94. 'series': 'Cuarto Milenio',
  95. 'season': 'Temporada 6',
  96. 'episode': 'Programa 226',
  97. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  98. 'duration': 7312,
  99. },
  100. 'params': {
  101. 'skip_download': True,
  102. },
  103. }]
  104. def _real_extract(self, url):
  105. display_id = self._match_id(url)
  106. webpage = self._download_webpage(url, display_id)
  107. info = self._get_player_info(url, webpage)
  108. title = self._search_regex(
  109. r'class="Destacado-text"[^>]*>\s*<strong>([^<]+)</strong>',
  110. webpage, 'title', default=None)
  111. mobj = re.search(r'''(?sx)
  112. class="Destacado-text"[^>]*>.*?<h1>\s*
  113. <span>(?P<series>[^<]+)</span>\s*
  114. <span>(?P<season>[^<]+)</span>\s*
  115. <span>(?P<episode>[^<]+)</span>''', webpage)
  116. series, season, episode = mobj.groups() if mobj else [None] * 3
  117. if not title:
  118. if mobj:
  119. title = '%s - %s - %s' % (series, season, episode)
  120. else:
  121. title = remove_start(self._search_regex(
  122. r'<title>([^<]+)</title>', webpage, 'title'), 'Ver online ')
  123. info.update({
  124. 'display_id': display_id,
  125. 'title': title,
  126. 'description': get_element_by_attribute('class', 'text', webpage),
  127. 'series': series,
  128. 'season': season,
  129. 'episode': episode,
  130. })
  131. return info