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.

95 lines
3.5 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_unquote,
  7. compat_urllib_parse_urlencode,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. get_element_by_attribute,
  12. parse_duration,
  13. strip_jsonp,
  14. )
  15. class TelecincoIE(InfoExtractor):
  16. IE_DESC = 'telecinco.es, cuatro.com and mediaset.es'
  17. _VALID_URL = r'https?://www\.(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html'
  18. _TESTS = [{
  19. 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html',
  20. 'md5': '5cbef3ad5ef17bf0d21570332d140729',
  21. 'info_dict': {
  22. 'id': 'MDSVID20141015_0058',
  23. 'ext': 'mp4',
  24. 'title': 'Con Martín Berasategui, hacer un bacalao al ...',
  25. 'duration': 662,
  26. },
  27. }, {
  28. 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html',
  29. 'md5': '0a5b9f3cc8b074f50a0578f823a12694',
  30. 'info_dict': {
  31. 'id': 'MDSVID20150916_0128',
  32. 'ext': 'mp4',
  33. 'title': '¿Quién es este ex futbolista con el que hablan ...',
  34. 'duration': 79,
  35. },
  36. }, {
  37. 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html',
  38. 'md5': 'ad1bfaaba922dd4a295724b05b68f86a',
  39. 'info_dict': {
  40. 'id': 'MDSVID20150513_0220',
  41. 'ext': 'mp4',
  42. 'title': '#DOYLACARA. Con la trata no hay trato',
  43. 'duration': 50,
  44. },
  45. }, {
  46. 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
  50. 'only_matching': True,
  51. }]
  52. def _real_extract(self, url):
  53. episode = self._match_id(url)
  54. webpage = self._download_webpage(url, episode)
  55. embed_data_json = self._search_regex(
  56. r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
  57. ).replace('\'', '"')
  58. embed_data = json.loads(embed_data_json)
  59. domain = embed_data['mediaUrl']
  60. if not domain.startswith('http'):
  61. # only happens in telecinco.es videos
  62. domain = 'http://' + domain
  63. info_url = compat_urlparse.urljoin(
  64. domain,
  65. compat_urllib_parse_unquote(embed_data['flashvars']['host'])
  66. )
  67. info_el = self._download_xml(info_url, episode).find('./video/info')
  68. video_link = info_el.find('videoUrl/link').text
  69. token_query = compat_urllib_parse_urlencode({'id': video_link})
  70. token_info = self._download_json(
  71. embed_data['flashvars']['ov_tk'] + '?' + token_query,
  72. episode,
  73. transform_source=strip_jsonp
  74. )
  75. formats = self._extract_m3u8_formats(
  76. token_info['tokenizedUrl'], episode, ext='mp4', entry_protocol='m3u8_native')
  77. self._sort_formats(formats)
  78. return {
  79. 'id': embed_data['videoId'],
  80. 'display_id': episode,
  81. 'title': info_el.find('title').text,
  82. 'formats': formats,
  83. 'description': get_element_by_attribute('class', 'text', webpage),
  84. 'thumbnail': info_el.find('thumb').text,
  85. 'duration': parse_duration(info_el.find('duration').text),
  86. }