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.

68 lines
2.2 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_urlparse,
  7. )
  8. from ..utils import (
  9. get_element_by_attribute,
  10. parse_duration,
  11. strip_jsonp,
  12. )
  13. class MiTeleIE(InfoExtractor):
  14. IE_NAME = 'mitele.es'
  15. _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
  16. _TEST = {
  17. 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
  18. 'md5': '6a75fe9d0d3275bead0cb683c616fddb',
  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. }
  28. def _real_extract(self, url):
  29. episode = self._match_id(url)
  30. webpage = self._download_webpage(url, episode)
  31. embed_data_json = self._search_regex(
  32. r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
  33. ).replace('\'', '"')
  34. embed_data = json.loads(embed_data_json)
  35. domain = embed_data['mediaUrl']
  36. if not domain.startswith('http'):
  37. # only happens in telecinco.es videos
  38. domain = 'http://' + domain
  39. info_url = compat_urlparse.urljoin(
  40. domain,
  41. compat_urllib_parse.unquote(embed_data['flashvars']['host'])
  42. )
  43. info_el = self._download_xml(info_url, episode).find('./video/info')
  44. video_link = info_el.find('videoUrl/link').text
  45. token_query = compat_urllib_parse.urlencode({'id': video_link})
  46. token_info = self._download_json(
  47. embed_data['flashvars']['ov_tk'] + '?' + token_query,
  48. episode,
  49. transform_source=strip_jsonp
  50. )
  51. return {
  52. 'id': embed_data['videoId'],
  53. 'display_id': episode,
  54. 'title': info_el.find('title').text,
  55. 'url': token_info['tokenizedUrl'],
  56. 'description': get_element_by_attribute('class', 'text', webpage),
  57. 'thumbnail': info_el.find('thumb').text,
  58. 'duration': parse_duration(info_el.find('duration').text),
  59. }