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.

85 lines
2.9 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_urllib_parse
  4. from ..utils import (
  5. encode_dict,
  6. get_element_by_attribute,
  7. int_or_none,
  8. )
  9. class MiTeleIE(InfoExtractor):
  10. IE_DESC = 'mitele.es'
  11. _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
  12. _TESTS = [{
  13. 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
  14. 'md5': '757b0b66cbd7e0a97226d7d3156cb3e9',
  15. 'info_dict': {
  16. 'id': '0NF1jJnxS1Wu3pHrmvFyw2',
  17. 'display_id': 'programa-144',
  18. 'ext': 'flv',
  19. 'title': 'Tor, la web invisible',
  20. 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
  21. 'thumbnail': 're:(?i)^https?://.*\.jpg$',
  22. 'duration': 2913,
  23. },
  24. }]
  25. def _real_extract(self, url):
  26. display_id = self._match_id(url)
  27. webpage = self._download_webpage(url, display_id)
  28. config_url = self._search_regex(
  29. r'data-config\s*=\s*"([^"]+)"', webpage, 'data config url')
  30. config = self._download_json(
  31. config_url, display_id, 'Downloading config JSON')
  32. mmc = self._download_json(
  33. config['services']['mmc'], display_id, 'Downloading mmc JSON')
  34. formats = []
  35. for location in mmc['locations']:
  36. gat = self._proto_relative_url(location.get('gat'), 'http:')
  37. bas = location.get('bas')
  38. loc = location.get('loc')
  39. ogn = location.get('ogn')
  40. if None in (gat, bas, loc, ogn):
  41. continue
  42. token_data = {
  43. 'bas': bas,
  44. 'icd': loc,
  45. 'ogn': ogn,
  46. 'sta': '0',
  47. }
  48. media = self._download_json(
  49. '%s/?%s' % (gat, compat_urllib_parse.urlencode(encode_dict(token_data))),
  50. display_id, 'Downloading %s JSON' % location['loc'])
  51. file_ = media.get('file')
  52. if not file_:
  53. continue
  54. formats.extend(self._extract_f4m_formats(
  55. file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  56. display_id, f4m_id=loc))
  57. title = self._search_regex(
  58. r'class="Destacado-text"[^>]*>\s*<strong>([^<]+)</strong>', webpage, 'title')
  59. video_id = self._search_regex(
  60. r'data-media-id\s*=\s*"([^"]+)"', webpage,
  61. 'data media id', default=None) or display_id
  62. thumbnail = config.get('poster', {}).get('imageUrl')
  63. duration = int_or_none(mmc.get('duration'))
  64. return {
  65. 'id': video_id,
  66. 'display_id': display_id,
  67. 'title': title,
  68. 'description': get_element_by_attribute('class', 'text', webpage),
  69. 'thumbnail': thumbnail,
  70. 'duration': duration,
  71. 'formats': formats,
  72. }