telecinco.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import json
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. int_or_none,
  7. str_or_none,
  8. try_get,
  9. )
  10. class TelecincoIE(InfoExtractor):
  11. IE_DESC = 'telecinco.es, cuatro.com and mediaset.es'
  12. _VALID_URL = r'https?://(?:www\.)?(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html'
  13. _TESTS = [{
  14. 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html',
  15. 'info_dict': {
  16. 'id': '1876350223',
  17. 'title': 'Bacalao con kokotxas al pil-pil',
  18. 'description': 'md5:716caf5601e25c3c5ab6605b1ae71529',
  19. },
  20. 'playlist': [{
  21. 'md5': '7ee56d665cfd241c0e6d80fd175068b0',
  22. 'info_dict': {
  23. 'id': 'JEA5ijCnF6p5W08A1rNKn7',
  24. 'ext': 'mp4',
  25. 'title': 'Con Martín Berasategui, hacer un bacalao al pil-pil es fácil y divertido',
  26. 'duration': 662,
  27. },
  28. }],
  29. }, {
  30. 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html',
  31. 'md5': 'c86fe0d99e3bdb46b7950d38bf6ef12a',
  32. 'info_dict': {
  33. 'id': 'jn24Od1zGLG4XUZcnUnZB6',
  34. 'ext': 'mp4',
  35. 'title': '¿Quién es este ex futbolista con el que hablan Leo Messi y Luis Suárez?',
  36. 'description': 'md5:a62ecb5f1934fc787107d7b9a2262805',
  37. 'duration': 79,
  38. },
  39. }, {
  40. 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html',
  41. 'md5': 'eddb50291df704ce23c74821b995bcac',
  42. 'info_dict': {
  43. 'id': 'aywerkD2Sv1vGNqq9b85Q2',
  44. 'ext': 'mp4',
  45. 'title': '#DOYLACARA. Con la trata no hay trato',
  46. 'description': 'md5:2771356ff7bfad9179c5f5cd954f1477',
  47. 'duration': 50,
  48. },
  49. }, {
  50. # video in opening's content
  51. 'url': 'https://www.telecinco.es/vivalavida/fiorella-sobrina-edmundo-arrocet-entrevista_18_2907195140.html',
  52. 'info_dict': {
  53. 'id': '2907195140',
  54. 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
  55. 'description': 'md5:73f340a7320143d37ab895375b2bf13a',
  56. },
  57. 'playlist': [{
  58. 'md5': 'adb28c37238b675dad0f042292f209a7',
  59. 'info_dict': {
  60. 'id': 'TpI2EttSDAReWpJ1o0NVh2',
  61. 'ext': 'mp4',
  62. 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
  63. 'duration': 1015,
  64. },
  65. }],
  66. 'params': {
  67. 'skip_download': True,
  68. },
  69. }, {
  70. 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
  74. 'only_matching': True,
  75. }, {
  76. 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html',
  77. 'only_matching': True,
  78. }]
  79. def _parse_content(self, content, url):
  80. video_id = content['dataMediaId']
  81. config = self._download_json(
  82. content['dataConfig'], video_id, 'Downloading config JSON')
  83. title = config['info']['title']
  84. services = config['services']
  85. caronte = self._download_json(services['caronte'], video_id)
  86. stream = caronte['dls'][0]['stream']
  87. headers = self.geo_verification_headers()
  88. headers.update({
  89. 'Content-Type': 'application/json;charset=UTF-8',
  90. 'Origin': re.match(r'https?://[^/]+', url).group(0),
  91. })
  92. cdn = self._download_json(
  93. caronte['cerbero'], video_id, data=json.dumps({
  94. 'bbx': caronte['bbx'],
  95. 'gbx': self._download_json(services['gbx'], video_id)['gbx'],
  96. }).encode(), headers=headers)['tokens']['1']['cdn']
  97. formats = self._extract_m3u8_formats(
  98. stream + '?' + cdn, video_id, 'mp4', 'm3u8_native', m3u8_id='hls')
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'formats': formats,
  103. 'thumbnail': content.get('dataPoster') or config.get('poster', {}).get('imageUrl'),
  104. 'duration': int_or_none(content.get('dataDuration')),
  105. }
  106. def _real_extract(self, url):
  107. display_id = self._match_id(url)
  108. webpage = self._download_webpage(url, display_id)
  109. article = self._parse_json(self._search_regex(
  110. r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=\s*({.+})',
  111. webpage, 'article'), display_id)['article']
  112. title = article.get('title')
  113. description = clean_html(article.get('leadParagraph')) or ''
  114. if article.get('editorialType') != 'VID':
  115. entries = []
  116. body = [article.get('opening')]
  117. body.extend(try_get(article, lambda x: x['body'], list) or [])
  118. for p in body:
  119. if not isinstance(p, dict):
  120. continue
  121. content = p.get('content')
  122. if not content:
  123. continue
  124. type_ = p.get('type')
  125. if type_ == 'paragraph':
  126. content_str = str_or_none(content)
  127. if content_str:
  128. description += content_str
  129. continue
  130. if type_ == 'video' and isinstance(content, dict):
  131. entries.append(self._parse_content(content, url))
  132. return self.playlist_result(
  133. entries, str_or_none(article.get('id')), title, description)
  134. content = article['opening']['content']
  135. info = self._parse_content(content, url)
  136. info.update({
  137. 'description': description,
  138. })
  139. return info