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.

69 lines
2.3 KiB

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