elpais.py 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from .common import InfoExtractor
  2. from ..utils import strip_jsonp, unified_strdate
  3. class ElPaisIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:[^.]+\.)?elpais\.com/.*/(?P<id>[^/#?]+)\.html(?:$|[?#])'
  5. IE_DESC = 'El País'
  6. _TESTS = [{
  7. 'url': 'http://blogs.elpais.com/la-voz-de-inaki/2014/02/tiempo-nuevo-recetas-viejas.html',
  8. 'md5': '98406f301f19562170ec071b83433d55',
  9. 'info_dict': {
  10. 'id': 'tiempo-nuevo-recetas-viejas',
  11. 'ext': 'mp4',
  12. 'title': 'Tiempo nuevo, recetas viejas',
  13. 'description': 'De lunes a viernes, a partir de las ocho de la mañana, Iñaki Gabilondo nos cuenta su visión de la actualidad nacional e internacional.',
  14. 'upload_date': '20140206',
  15. },
  16. }, {
  17. 'url': 'http://elcomidista.elpais.com/elcomidista/2016/02/24/articulo/1456340311_668921.html#?id_externo_nwl=newsletter_diaria20160303t',
  18. 'md5': '3bd5b09509f3519d7d9e763179b013de',
  19. 'info_dict': {
  20. 'id': '1456340311_668921',
  21. 'ext': 'mp4',
  22. 'title': 'Cómo hacer el mejor café con cafetera italiana',
  23. 'description': 'Que sí, que las cápsulas son cómodas. Pero si le pides algo más a la vida, quizá deberías aprender a usar bien la cafetera italiana. No tienes más que ver este vídeo y seguir sus siete normas básicas.',
  24. 'upload_date': '20160303',
  25. },
  26. }, {
  27. 'url': 'http://elpais.com/elpais/2017/01/26/ciencia/1485456786_417876.html',
  28. 'md5': '9c79923a118a067e1a45789e1e0b0f9c',
  29. 'info_dict': {
  30. 'id': '1485456786_417876',
  31. 'ext': 'mp4',
  32. 'title': 'Hallado un barco de la antigua Roma que naufragó en Baleares hace 1.800 años',
  33. 'description': 'La nave portaba cientos de ánforas y se hundió cerca de la isla de Cabrera por razones desconocidas',
  34. 'upload_date': '20170127',
  35. },
  36. }, {
  37. 'url': 'http://epv.elpais.com/epv/2017/02/14/programa_la_voz_de_inaki/1487062137_075943.html',
  38. 'info_dict': {
  39. 'id': '1487062137_075943',
  40. 'ext': 'mp4',
  41. 'title': 'Disyuntivas',
  42. 'description': 'md5:a0fb1485c4a6a8a917e6f93878e66218',
  43. 'upload_date': '20170214',
  44. },
  45. 'params': {
  46. 'skip_download': True,
  47. },
  48. }]
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. webpage = self._download_webpage(url, video_id)
  52. prefix = self._html_search_regex(
  53. r'var\s+url_cache\s*=\s*"([^"]+)";', webpage, 'URL prefix')
  54. id_multimedia = self._search_regex(
  55. r"id_multimedia\s*=\s*'([^']+)'", webpage, 'ID multimedia', default=None)
  56. if id_multimedia:
  57. url_info = self._download_json(
  58. 'http://elpais.com/vdpep/1/?pepid=' + id_multimedia, video_id, transform_source=strip_jsonp)
  59. video_suffix = url_info['mp4']
  60. else:
  61. video_suffix = self._search_regex(
  62. r"(?:URLMediaFile|urlVideo_\d+)\s*=\s*url_cache\s*\+\s*'([^']+)'", webpage, 'video URL')
  63. video_url = prefix + video_suffix
  64. thumbnail_suffix = self._search_regex(
  65. r"(?:URLMediaStill|urlFotogramaFijo_\d+)\s*=\s*url_cache\s*\+\s*'([^']+)'",
  66. webpage, 'thumbnail URL', default=None)
  67. thumbnail = (
  68. None if thumbnail_suffix is None
  69. else prefix + thumbnail_suffix) or self._og_search_thumbnail(webpage)
  70. title = self._html_search_regex(
  71. (r"tituloVideo\s*=\s*'([^']+)'",
  72. r'<h2 class="entry-header entry-title.*?>(.*?)</h2>',
  73. r'<h1[^>]+class="titulo"[^>]*>([^<]+)'),
  74. webpage, 'title', default=None) or self._og_search_title(webpage)
  75. upload_date = unified_strdate(self._search_regex(
  76. r'<p class="date-header date-int updated"\s+title="([^"]+)">',
  77. webpage, 'upload date', default=None) or self._html_search_meta(
  78. 'datePublished', webpage, 'timestamp'))
  79. return {
  80. 'id': video_id,
  81. 'url': video_url,
  82. 'title': title,
  83. 'description': self._og_search_description(webpage),
  84. 'thumbnail': thumbnail,
  85. 'upload_date': upload_date,
  86. }