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.

156 lines
6.1 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from .ooyala import OoyalaIE
  7. from ..utils import (
  8. clean_html,
  9. determine_ext,
  10. int_or_none,
  11. str_or_none,
  12. urljoin,
  13. )
  14. class TelecincoIE(InfoExtractor):
  15. IE_DESC = 'telecinco.es, cuatro.com and mediaset.es'
  16. _VALID_URL = r'https?://(?:www\.)?(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html'
  17. _TESTS = [{
  18. 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html',
  19. 'info_dict': {
  20. 'id': '1876350223',
  21. 'title': 'Bacalao con kokotxas al pil-pil',
  22. 'description': 'md5:1382dacd32dd4592d478cbdca458e5bb',
  23. },
  24. 'playlist': [{
  25. 'md5': 'adb28c37238b675dad0f042292f209a7',
  26. 'info_dict': {
  27. 'id': 'JEA5ijCnF6p5W08A1rNKn7',
  28. 'ext': 'mp4',
  29. 'title': 'Con Martín Berasategui, hacer un bacalao al pil-pil es fácil y divertido',
  30. 'duration': 662,
  31. },
  32. }]
  33. }, {
  34. 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html',
  35. 'md5': '9468140ebc300fbb8b9d65dc6e5c4b43',
  36. 'info_dict': {
  37. 'id': 'jn24Od1zGLG4XUZcnUnZB6',
  38. 'ext': 'mp4',
  39. 'title': '¿Quién es este ex futbolista con el que hablan Leo Messi y Luis Suárez?',
  40. 'description': 'md5:a62ecb5f1934fc787107d7b9a2262805',
  41. 'duration': 79,
  42. },
  43. }, {
  44. 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html',
  45. 'md5': 'ae2dc6b7b50b2392076a51c0f70e01f6',
  46. 'info_dict': {
  47. 'id': 'aywerkD2Sv1vGNqq9b85Q2',
  48. 'ext': 'mp4',
  49. 'title': '#DOYLACARA. Con la trata no hay trato',
  50. 'description': 'md5:2771356ff7bfad9179c5f5cd954f1477',
  51. 'duration': 50,
  52. },
  53. }, {
  54. 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
  58. 'only_matching': True,
  59. }, {
  60. # ooyala video
  61. 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html',
  62. 'only_matching': True,
  63. }]
  64. def _parse_content(self, content, url):
  65. video_id = content['dataMediaId']
  66. if content.get('dataCmsId') == 'ooyala':
  67. return self.url_result(
  68. 'ooyala:%s' % video_id, OoyalaIE.ie_key(), video_id)
  69. config_url = urljoin(url, content['dataConfig'])
  70. config = self._download_json(
  71. config_url, video_id, 'Downloading config JSON')
  72. title = config['info']['title']
  73. def mmc_url(mmc_type):
  74. return re.sub(
  75. r'/(?:flash|html5)\.json', '/%s.json' % mmc_type,
  76. config['services']['mmc'])
  77. duration = None
  78. formats = []
  79. for mmc_type in ('flash', 'html5'):
  80. mmc = self._download_json(
  81. mmc_url(mmc_type), video_id,
  82. 'Downloading %s mmc JSON' % mmc_type, fatal=False)
  83. if not mmc:
  84. continue
  85. if not duration:
  86. duration = int_or_none(mmc.get('duration'))
  87. for location in mmc['locations']:
  88. gat = self._proto_relative_url(location.get('gat'), 'http:')
  89. gcp = location.get('gcp')
  90. ogn = location.get('ogn')
  91. if None in (gat, gcp, ogn):
  92. continue
  93. token_data = {
  94. 'gcp': gcp,
  95. 'ogn': ogn,
  96. 'sta': 0,
  97. }
  98. media = self._download_json(
  99. gat, video_id, data=json.dumps(token_data).encode('utf-8'),
  100. headers={
  101. 'Content-Type': 'application/json;charset=utf-8',
  102. 'Referer': url,
  103. }, fatal=False) or {}
  104. stream = media.get('stream') or media.get('file')
  105. if not stream:
  106. continue
  107. ext = determine_ext(stream)
  108. if ext == 'f4m':
  109. formats.extend(self._extract_f4m_formats(
  110. stream + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  111. video_id, f4m_id='hds', fatal=False))
  112. elif ext == 'm3u8':
  113. formats.extend(self._extract_m3u8_formats(
  114. stream, video_id, 'mp4', 'm3u8_native',
  115. m3u8_id='hls', fatal=False))
  116. self._sort_formats(formats)
  117. return {
  118. 'id': video_id,
  119. 'title': title,
  120. 'formats': formats,
  121. 'thumbnail': content.get('dataPoster') or config.get('poster', {}).get('imageUrl'),
  122. 'duration': duration,
  123. }
  124. def _real_extract(self, url):
  125. display_id = self._match_id(url)
  126. webpage = self._download_webpage(url, display_id)
  127. article = self._parse_json(self._search_regex(
  128. r'window\.\$REACTBASE_STATE\.article\s*=\s*({.+})',
  129. webpage, 'article'), display_id)['article']
  130. title = article.get('title')
  131. description = clean_html(article.get('leadParagraph'))
  132. if article.get('editorialType') != 'VID':
  133. entries = []
  134. for p in article.get('body', []):
  135. content = p.get('content')
  136. if p.get('type') != 'video' or not content:
  137. continue
  138. entries.append(self._parse_content(content, url))
  139. return self.playlist_result(
  140. entries, str_or_none(article.get('id')), title, description)
  141. content = article['opening']['content']
  142. info = self._parse_content(content, url)
  143. info.update({
  144. 'description': description,
  145. })
  146. return info