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.

74 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_parse_unquote,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. get_element_by_attribute,
  11. parse_duration,
  12. strip_jsonp,
  13. )
  14. class MiTeleIE(InfoExtractor):
  15. IE_NAME = 'mitele.es'
  16. _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
  17. _TESTS = [{
  18. 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
  19. 'info_dict': {
  20. 'id': '0fce117d',
  21. 'ext': 'mp4',
  22. 'title': 'Programa 144 - Tor, la web invisible',
  23. 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
  24. 'display_id': 'programa-144',
  25. 'duration': 2913,
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. }]
  32. def _real_extract(self, url):
  33. episode = self._match_id(url)
  34. webpage = self._download_webpage(url, episode)
  35. embed_data_json = self._search_regex(
  36. r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
  37. ).replace('\'', '"')
  38. embed_data = json.loads(embed_data_json)
  39. domain = embed_data['mediaUrl']
  40. if not domain.startswith('http'):
  41. # only happens in telecinco.es videos
  42. domain = 'http://' + domain
  43. info_url = compat_urlparse.urljoin(
  44. domain,
  45. compat_urllib_parse_unquote(embed_data['flashvars']['host'])
  46. )
  47. info_el = self._download_xml(info_url, episode).find('./video/info')
  48. video_link = info_el.find('videoUrl/link').text
  49. token_query = compat_urllib_parse.urlencode({'id': video_link})
  50. token_info = self._download_json(
  51. embed_data['flashvars']['ov_tk'] + '?' + token_query,
  52. episode,
  53. transform_source=strip_jsonp
  54. )
  55. formats = self._extract_m3u8_formats(
  56. token_info['tokenizedUrl'], episode, ext='mp4')
  57. return {
  58. 'id': embed_data['videoId'],
  59. 'display_id': episode,
  60. 'title': info_el.find('title').text,
  61. 'formats': formats,
  62. 'description': get_element_by_attribute('class', 'text', webpage),
  63. 'thumbnail': info_el.find('thumb').text,
  64. 'duration': parse_duration(info_el.find('duration').text),
  65. }