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.

132 lines
4.5 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. )
  14. class MiTeleIE(InfoExtractor):
  15. IE_DESC = 'mitele.es'
  16. _VALID_URL = r'https?://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
  17. _TESTS = [{
  18. 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
  19. # MD5 is unstable
  20. 'info_dict': {
  21. 'id': '0NF1jJnxS1Wu3pHrmvFyw2',
  22. 'display_id': 'programa-144',
  23. 'ext': 'flv',
  24. 'title': 'Tor, la web invisible',
  25. 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
  26. 'series': 'Diario de',
  27. 'season': 'La redacción',
  28. 'episode': 'Programa 144',
  29. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  30. 'duration': 2913,
  31. },
  32. }, {
  33. # no explicit title
  34. 'url': 'http://www.mitele.es/programas-tv/cuarto-milenio/temporada-6/programa-226/',
  35. 'info_dict': {
  36. 'id': 'eLZSwoEd1S3pVyUm8lc6F',
  37. 'display_id': 'programa-226',
  38. 'ext': 'flv',
  39. 'title': 'Cuarto Milenio - Temporada 6 - Programa 226',
  40. 'description': 'md5:50daf9fadefa4e62d9fc866d0c015701',
  41. 'series': 'Cuarto Milenio',
  42. 'season': 'Temporada 6',
  43. 'episode': 'Programa 226',
  44. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  45. 'duration': 7312,
  46. },
  47. 'params': {
  48. 'skip_download': True,
  49. },
  50. }]
  51. def _real_extract(self, url):
  52. display_id = self._match_id(url)
  53. webpage = self._download_webpage(url, display_id)
  54. config_url = self._search_regex(
  55. r'data-config\s*=\s*"([^"]+)"', webpage, 'data config url')
  56. config_url = compat_urlparse.urljoin(url, config_url)
  57. config = self._download_json(
  58. config_url, display_id, 'Downloading config JSON')
  59. mmc = self._download_json(
  60. config['services']['mmc'], display_id, 'Downloading mmc JSON')
  61. formats = []
  62. for location in mmc['locations']:
  63. gat = self._proto_relative_url(location.get('gat'), 'http:')
  64. bas = location.get('bas')
  65. loc = location.get('loc')
  66. ogn = location.get('ogn')
  67. if None in (gat, bas, loc, ogn):
  68. continue
  69. token_data = {
  70. 'bas': bas,
  71. 'icd': loc,
  72. 'ogn': ogn,
  73. 'sta': '0',
  74. }
  75. media = self._download_json(
  76. '%s/?%s' % (gat, compat_urllib_parse_urlencode(token_data)),
  77. display_id, 'Downloading %s JSON' % location['loc'])
  78. file_ = media.get('file')
  79. if not file_:
  80. continue
  81. formats.extend(self._extract_f4m_formats(
  82. file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  83. display_id, f4m_id=loc))
  84. self._sort_formats(formats)
  85. title = self._search_regex(
  86. r'class="Destacado-text"[^>]*>\s*<strong>([^<]+)</strong>',
  87. webpage, 'title', default=None)
  88. mobj = re.search(r'''(?sx)
  89. class="Destacado-text"[^>]*>.*?<h1>\s*
  90. <span>(?P<series>[^<]+)</span>\s*
  91. <span>(?P<season>[^<]+)</span>\s*
  92. <span>(?P<episode>[^<]+)</span>''', webpage)
  93. series, season, episode = mobj.groups() if mobj else [None] * 3
  94. if not title:
  95. if mobj:
  96. title = '%s - %s - %s' % (series, season, episode)
  97. else:
  98. title = remove_start(self._search_regex(
  99. r'<title>([^<]+)</title>', webpage, 'title'), 'Ver online ')
  100. video_id = self._search_regex(
  101. r'data-media-id\s*=\s*"([^"]+)"', webpage,
  102. 'data media id', default=None) or display_id
  103. thumbnail = config.get('poster', {}).get('imageUrl')
  104. duration = int_or_none(mmc.get('duration'))
  105. return {
  106. 'id': video_id,
  107. 'display_id': display_id,
  108. 'title': title,
  109. 'description': get_element_by_attribute('class', 'text', webpage),
  110. 'series': series,
  111. 'season': season,
  112. 'episode': episode,
  113. 'thumbnail': thumbnail,
  114. 'duration': duration,
  115. 'formats': formats,
  116. }