logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

telecinco.py (6226B)


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