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.

73 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_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. _TESTS = [{
  17. 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
  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. 'params': {
  27. # m3u8 download
  28. 'skip_download': True,
  29. },
  30. }]
  31. def _real_extract(self, url):
  32. episode = self._match_id(url)
  33. webpage = self._download_webpage(url, episode)
  34. embed_data_json = self._search_regex(
  35. r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
  36. ).replace('\'', '"')
  37. embed_data = json.loads(embed_data_json)
  38. domain = embed_data['mediaUrl']
  39. if not domain.startswith('http'):
  40. # only happens in telecinco.es videos
  41. domain = 'http://' + domain
  42. info_url = compat_urlparse.urljoin(
  43. domain,
  44. compat_urllib_parse.unquote(embed_data['flashvars']['host'])
  45. )
  46. info_el = self._download_xml(info_url, episode).find('./video/info')
  47. video_link = info_el.find('videoUrl/link').text
  48. token_query = compat_urllib_parse.urlencode({'id': video_link})
  49. token_info = self._download_json(
  50. embed_data['flashvars']['ov_tk'] + '?' + token_query,
  51. episode,
  52. transform_source=strip_jsonp
  53. )
  54. formats = self._extract_m3u8_formats(
  55. token_info['tokenizedUrl'], episode, ext='mp4')
  56. return {
  57. 'id': embed_data['videoId'],
  58. 'display_id': episode,
  59. 'title': info_el.find('title').text,
  60. 'formats': formats,
  61. 'description': get_element_by_attribute('class', 'text', webpage),
  62. 'thumbnail': info_el.find('thumb').text,
  63. 'duration': parse_duration(info_el.find('duration').text),
  64. }