telecinco.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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,
  7. compat_urllib_parse_unquote,
  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 and cuatro.es'
  17. _VALID_URL = r'https?://www\.(?:telecinco\.es|cuatro\.com)/(?:[^/]+/)+(?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.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. episode = self._match_id(url)
  45. webpage = self._download_webpage(url, episode)
  46. embed_data_json = self._search_regex(
  47. r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
  48. ).replace('\'', '"')
  49. embed_data = json.loads(embed_data_json)
  50. domain = embed_data['mediaUrl']
  51. if not domain.startswith('http'):
  52. # only happens in telecinco.es videos
  53. domain = 'http://' + domain
  54. info_url = compat_urlparse.urljoin(
  55. domain,
  56. compat_urllib_parse_unquote(embed_data['flashvars']['host'])
  57. )
  58. info_el = self._download_xml(info_url, episode).find('./video/info')
  59. video_link = info_el.find('videoUrl/link').text
  60. token_query = compat_urllib_parse.urlencode({'id': video_link})
  61. token_info = self._download_json(
  62. embed_data['flashvars']['ov_tk'] + '?' + token_query,
  63. episode,
  64. transform_source=strip_jsonp
  65. )
  66. formats = self._extract_m3u8_formats(
  67. token_info['tokenizedUrl'], episode, ext='mp4', entry_protocol='m3u8_native')
  68. return {
  69. 'id': embed_data['videoId'],
  70. 'display_id': episode,
  71. 'title': info_el.find('title').text,
  72. 'formats': formats,
  73. 'description': get_element_by_attribute('class', 'text', webpage),
  74. 'thumbnail': info_el.find('thumb').text,
  75. 'duration': parse_duration(info_el.find('duration').text),
  76. }