logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

telecinco.py (7044B)


  1. import json
  2. import re
  3. from .common import InfoExtractor
  4. from ..networking.exceptions import HTTPError
  5. from ..utils import (
  6. ExtractorError,
  7. clean_html,
  8. int_or_none,
  9. join_nonempty,
  10. str_or_none,
  11. traverse_obj,
  12. update_url,
  13. url_or_none,
  14. )
  15. class TelecincoBaseIE(InfoExtractor):
  16. def _parse_content(self, content, url):
  17. video_id = content['dataMediaId']
  18. config = self._download_json(
  19. content['dataConfig'], video_id, 'Downloading config JSON')
  20. services = config['services']
  21. caronte = self._download_json(services['caronte'], video_id)
  22. if traverse_obj(caronte, ('dls', 0, 'drm', {bool})):
  23. self.report_drm(video_id)
  24. stream = caronte['dls'][0]['stream']
  25. headers = {
  26. 'Referer': url,
  27. 'Origin': re.match(r'https?://[^/]+', url).group(0),
  28. }
  29. geo_headers = {**headers, **self.geo_verification_headers()}
  30. try:
  31. cdn = self._download_json(
  32. caronte['cerbero'], video_id, data=json.dumps({
  33. 'bbx': caronte['bbx'],
  34. 'gbx': self._download_json(services['gbx'], video_id)['gbx'],
  35. }).encode(), headers={
  36. 'Content-Type': 'application/json',
  37. **geo_headers,
  38. })['tokens']['1']['cdn']
  39. except ExtractorError as error:
  40. if isinstance(error.cause, HTTPError) and error.cause.status == 403:
  41. error_code = traverse_obj(
  42. self._webpage_read_content(error.cause.response, caronte['cerbero'], video_id, fatal=False),
  43. ({json.loads}, 'code', {int}))
  44. if error_code == 4038:
  45. self.raise_geo_restricted(countries=['ES'])
  46. raise
  47. formats = self._extract_m3u8_formats(
  48. update_url(stream, query=cdn), video_id, 'mp4', m3u8_id='hls', headers=geo_headers)
  49. return {
  50. 'id': video_id,
  51. 'title': traverse_obj(config, ('info', 'title', {str})),
  52. 'formats': formats,
  53. 'thumbnail': (traverse_obj(content, ('dataPoster', {url_or_none}))
  54. or traverse_obj(config, 'poster', 'imageUrl', expected_type=url_or_none)),
  55. 'duration': traverse_obj(content, ('dataDuration', {int_or_none})),
  56. 'http_headers': headers,
  57. }
  58. class TelecincoIE(TelecincoBaseIE):
  59. IE_DESC = 'telecinco.es, cuatro.com and mediaset.es'
  60. _VALID_URL = r'https?://(?:www\.)?(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html'
  61. _TESTS = [{
  62. 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html',
  63. 'info_dict': {
  64. 'id': '1876350223',
  65. 'title': 'Bacalao con kokotxas al pil-pil',
  66. 'description': 'md5:716caf5601e25c3c5ab6605b1ae71529',
  67. },
  68. 'playlist': [{
  69. 'md5': '7ee56d665cfd241c0e6d80fd175068b0',
  70. 'info_dict': {
  71. 'id': 'JEA5ijCnF6p5W08A1rNKn7',
  72. 'ext': 'mp4',
  73. 'title': 'Con Martín Berasategui, hacer un bacalao al pil-pil es fácil y divertido',
  74. 'duration': 662,
  75. },
  76. }],
  77. 'skip': 'HTTP Error 410 Gone',
  78. }, {
  79. 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html',
  80. 'md5': 'c86fe0d99e3bdb46b7950d38bf6ef12a',
  81. 'info_dict': {
  82. 'id': 'jn24Od1zGLG4XUZcnUnZB6',
  83. 'ext': 'mp4',
  84. 'title': '¿Quién es este ex futbolista con el que hablan Leo Messi y Luis Suárez?',
  85. 'description': 'md5:a62ecb5f1934fc787107d7b9a2262805',
  86. 'duration': 79,
  87. },
  88. 'skip': 'Redirects to main page',
  89. }, {
  90. 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html',
  91. 'md5': '5ce057f43f30b634fbaf0f18c71a140a',
  92. 'info_dict': {
  93. 'id': 'aywerkD2Sv1vGNqq9b85Q2',
  94. 'ext': 'mp4',
  95. 'title': '#DOYLACARA. Con la trata no hay trato',
  96. 'duration': 50,
  97. 'thumbnail': 'https://album.mediaset.es/eimg/2017/11/02/1tlQLO5Q3mtKT24f3EaC24.jpg',
  98. },
  99. }, {
  100. # video in opening's content
  101. 'url': 'https://www.telecinco.es/vivalavida/fiorella-sobrina-edmundo-arrocet-entrevista_18_2907195140.html',
  102. 'info_dict': {
  103. 'id': '1691427',
  104. 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
  105. 'description': r're:Fiorella, la sobrina de Edmundo Arrocet, concedió .{727}',
  106. },
  107. 'playlist': [{
  108. 'md5': 'adb28c37238b675dad0f042292f209a7',
  109. 'info_dict': {
  110. 'id': 'TpI2EttSDAReWpJ1o0NVh2',
  111. 'ext': 'mp4',
  112. 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
  113. 'duration': 1015,
  114. 'thumbnail': 'https://album.mediaset.es/eimg/2020/02/29/5opaC37lUhKlZ7FoDhiVC.jpg',
  115. },
  116. }],
  117. 'params': {
  118. 'skip_download': True,
  119. },
  120. }, {
  121. 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
  122. 'only_matching': True,
  123. }, {
  124. 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
  125. 'only_matching': True,
  126. }, {
  127. 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html',
  128. 'only_matching': True,
  129. }]
  130. def _real_extract(self, url):
  131. display_id = self._match_id(url)
  132. webpage = self._download_webpage(url, display_id)
  133. article = self._search_json(
  134. r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=',
  135. webpage, 'article', display_id)['article']
  136. description = traverse_obj(article, ('leadParagraph', {clean_html}, filter))
  137. if article.get('editorialType') != 'VID':
  138. entries = []
  139. for p in traverse_obj(article, ((('opening', all), 'body'), lambda _, v: v['content'])):
  140. content = p['content']
  141. type_ = p.get('type')
  142. if type_ == 'paragraph' and isinstance(content, str):
  143. description = join_nonempty(description, content, delim='')
  144. elif type_ == 'video' and isinstance(content, dict):
  145. entries.append(self._parse_content(content, url))
  146. return self.playlist_result(
  147. entries, str_or_none(article.get('id')),
  148. traverse_obj(article, ('title', {str})), clean_html(description))
  149. info = self._parse_content(article['opening']['content'], url)
  150. info['description'] = description
  151. return info