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.

188 lines
7.4 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. try_get,
  13. urljoin,
  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. 'info_dict': {
  21. 'id': '1876350223',
  22. 'title': 'Bacalao con kokotxas al pil-pil',
  23. 'description': 'md5:716caf5601e25c3c5ab6605b1ae71529',
  24. },
  25. 'playlist': [{
  26. 'md5': 'adb28c37238b675dad0f042292f209a7',
  27. 'info_dict': {
  28. 'id': 'JEA5ijCnF6p5W08A1rNKn7',
  29. 'ext': 'mp4',
  30. 'title': 'Con Martín Berasategui, hacer un bacalao al pil-pil es fácil y divertido',
  31. 'duration': 662,
  32. },
  33. }]
  34. }, {
  35. 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html',
  36. 'md5': '9468140ebc300fbb8b9d65dc6e5c4b43',
  37. 'info_dict': {
  38. 'id': 'jn24Od1zGLG4XUZcnUnZB6',
  39. 'ext': 'mp4',
  40. 'title': '¿Quién es este ex futbolista con el que hablan Leo Messi y Luis Suárez?',
  41. 'description': 'md5:a62ecb5f1934fc787107d7b9a2262805',
  42. 'duration': 79,
  43. },
  44. }, {
  45. 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html',
  46. 'md5': 'ae2dc6b7b50b2392076a51c0f70e01f6',
  47. 'info_dict': {
  48. 'id': 'aywerkD2Sv1vGNqq9b85Q2',
  49. 'ext': 'mp4',
  50. 'title': '#DOYLACARA. Con la trata no hay trato',
  51. 'description': 'md5:2771356ff7bfad9179c5f5cd954f1477',
  52. 'duration': 50,
  53. },
  54. }, {
  55. # video in opening's content
  56. 'url': 'https://www.telecinco.es/vivalavida/fiorella-sobrina-edmundo-arrocet-entrevista_18_2907195140.html',
  57. 'info_dict': {
  58. 'id': '2907195140',
  59. 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
  60. 'description': 'md5:73f340a7320143d37ab895375b2bf13a',
  61. },
  62. 'playlist': [{
  63. 'md5': 'adb28c37238b675dad0f042292f209a7',
  64. 'info_dict': {
  65. 'id': 'TpI2EttSDAReWpJ1o0NVh2',
  66. 'ext': 'mp4',
  67. 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
  68. 'duration': 1015,
  69. },
  70. }],
  71. 'params': {
  72. 'skip_download': True,
  73. },
  74. }, {
  75. 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
  76. 'only_matching': True,
  77. }, {
  78. 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
  79. 'only_matching': True,
  80. }, {
  81. # ooyala video
  82. 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html',
  83. 'only_matching': True,
  84. }]
  85. def _parse_content(self, content, url):
  86. video_id = content['dataMediaId']
  87. if content.get('dataCmsId') == 'ooyala':
  88. return self.url_result(
  89. 'ooyala:%s' % video_id, OoyalaIE.ie_key(), video_id)
  90. config_url = urljoin(url, content['dataConfig'])
  91. config = self._download_json(
  92. config_url, video_id, 'Downloading config JSON')
  93. title = config['info']['title']
  94. def mmc_url(mmc_type):
  95. return re.sub(
  96. r'/(?:flash|html5)\.json', '/%s.json' % mmc_type,
  97. config['services']['mmc'])
  98. duration = None
  99. formats = []
  100. for mmc_type in ('flash', 'html5'):
  101. mmc = self._download_json(
  102. mmc_url(mmc_type), video_id,
  103. 'Downloading %s mmc JSON' % mmc_type, fatal=False)
  104. if not mmc:
  105. continue
  106. if not duration:
  107. duration = int_or_none(mmc.get('duration'))
  108. for location in mmc['locations']:
  109. gat = self._proto_relative_url(location.get('gat'), 'http:')
  110. gcp = location.get('gcp')
  111. ogn = location.get('ogn')
  112. if None in (gat, gcp, ogn):
  113. continue
  114. token_data = {
  115. 'gcp': gcp,
  116. 'ogn': ogn,
  117. 'sta': 0,
  118. }
  119. media = self._download_json(
  120. gat, video_id, data=json.dumps(token_data).encode('utf-8'),
  121. headers={
  122. 'Content-Type': 'application/json;charset=utf-8',
  123. 'Referer': url,
  124. }, fatal=False) or {}
  125. stream = media.get('stream') or media.get('file')
  126. if not stream:
  127. continue
  128. ext = determine_ext(stream)
  129. if ext == 'f4m':
  130. formats.extend(self._extract_f4m_formats(
  131. stream + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
  132. video_id, f4m_id='hds', fatal=False))
  133. elif ext == 'm3u8':
  134. formats.extend(self._extract_m3u8_formats(
  135. stream, video_id, 'mp4', 'm3u8_native',
  136. m3u8_id='hls', fatal=False))
  137. self._sort_formats(formats)
  138. return {
  139. 'id': video_id,
  140. 'title': title,
  141. 'formats': formats,
  142. 'thumbnail': content.get('dataPoster') or config.get('poster', {}).get('imageUrl'),
  143. 'duration': duration,
  144. }
  145. def _real_extract(self, url):
  146. display_id = self._match_id(url)
  147. webpage = self._download_webpage(url, display_id)
  148. article = self._parse_json(self._search_regex(
  149. r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=\s*({.+})',
  150. webpage, 'article'), display_id)['article']
  151. title = article.get('title')
  152. description = clean_html(article.get('leadParagraph')) or ''
  153. if article.get('editorialType') != 'VID':
  154. entries = []
  155. body = [article.get('opening')]
  156. body.extend(try_get(article, lambda x: x['body'], list) or [])
  157. for p in body:
  158. if not isinstance(p, dict):
  159. continue
  160. content = p.get('content')
  161. if not content:
  162. continue
  163. type_ = p.get('type')
  164. if type_ == 'paragraph':
  165. content_str = str_or_none(content)
  166. if content_str:
  167. description += content_str
  168. continue
  169. if type_ == 'video' and isinstance(content, dict):
  170. entries.append(self._parse_content(content, url))
  171. return self.playlist_result(
  172. entries, str_or_none(article.get('id')), title, description)
  173. content = article['opening']['content']
  174. info = self._parse_content(content, url)
  175. info.update({
  176. 'description': description,
  177. })
  178. return info