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.

105 lines
4.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urlparse,
  6. )
  7. from ..utils import (
  8. determine_ext,
  9. int_or_none,
  10. ExtractorError,
  11. )
  12. class FranceCultureIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/player/reecouter\?play=(?P<id>[0-9]+)'
  14. _TEST = {
  15. 'url': 'http://www.franceculture.fr/player/reecouter?play=4795174',
  16. 'info_dict': {
  17. 'id': '4795174',
  18. 'ext': 'mp3',
  19. 'title': 'Rendez-vous au pays des geeks',
  20. 'alt_title': 'Carnet nomade | 13-14',
  21. 'vcodec': 'none',
  22. 'upload_date': '20140301',
  23. 'thumbnail': r're:^http://static\.franceculture\.fr/.*/images/player/Carnet-nomade\.jpg$',
  24. 'description': 'startswith:Avec :Jean-Baptiste Péretié pour son documentaire sur Arte "La revanche',
  25. 'timestamp': 1393700400,
  26. }
  27. }
  28. def _extract_from_player(self, url, video_id):
  29. webpage = self._download_webpage(url, video_id)
  30. video_path = self._search_regex(
  31. r'<a id="player".*?href="([^"]+)"', webpage, 'video path')
  32. video_url = compat_urlparse.urljoin(url, video_path)
  33. timestamp = int_or_none(self._search_regex(
  34. r'<a id="player".*?data-date="([0-9]+)"',
  35. webpage, 'upload date', fatal=False))
  36. thumbnail = self._search_regex(
  37. r'<a id="player".*?>\s+<img src="([^"]+)"',
  38. webpage, 'thumbnail', fatal=False)
  39. display_id = self._search_regex(
  40. r'<span class="path-diffusion">emission-(.*?)</span>', webpage, 'display_id')
  41. title = self._html_search_regex(
  42. r'<span class="title-diffusion">(.*?)</span>', webpage, 'title')
  43. alt_title = self._html_search_regex(
  44. r'<span class="title">(.*?)</span>',
  45. webpage, 'alt_title', fatal=False)
  46. description = self._html_search_regex(
  47. r'<span class="description">(.*?)</span>',
  48. webpage, 'description', fatal=False)
  49. uploader = self._html_search_regex(
  50. r'(?s)<div id="emission".*?<span class="author">(.*?)</span>',
  51. webpage, 'uploader', default=None)
  52. vcodec = 'none' if determine_ext(video_url.lower()) == 'mp3' else None
  53. return {
  54. 'id': video_id,
  55. 'url': video_url,
  56. 'vcodec': vcodec,
  57. 'uploader': uploader,
  58. 'timestamp': timestamp,
  59. 'title': title,
  60. 'alt_title': alt_title,
  61. 'thumbnail': thumbnail,
  62. 'description': description,
  63. 'display_id': display_id,
  64. }
  65. def _real_extract(self, url):
  66. video_id = self._match_id(url)
  67. return self._extract_from_player(url, video_id)
  68. class FranceCultureEmissionIE(FranceCultureIE):
  69. _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emission-(?P<id>[^?#]+)'
  70. _TEST = {
  71. 'url': 'http://www.franceculture.fr/emission-les-carnets-de-la-creation-jean-gabriel-periot-cineaste-2015-10-13',
  72. 'info_dict': {
  73. 'title': 'Jean-Gabriel Périot, cinéaste',
  74. 'alt_title': 'Les Carnets de la création',
  75. 'id': '5093239',
  76. 'display_id': 'les-carnets-de-la-creation-jean-gabriel-periot-cineaste-2015-10-13',
  77. 'ext': 'mp3',
  78. 'timestamp': 1444762500,
  79. 'upload_date': '20151013',
  80. 'description': 'startswith:Aujourd\'hui dans "Les carnets de la création", le cinéaste',
  81. },
  82. }
  83. def _real_extract(self, url):
  84. video_id = self._match_id(url)
  85. webpage = self._download_webpage(url, video_id)
  86. video_path = self._html_search_regex(
  87. r'<a class="rf-player-open".*?href="([^"]+)"', webpage, 'video path', 'no_path_player')
  88. if video_path == 'no_path_player':
  89. raise ExtractorError('no player : no sound in this page.', expected=True)
  90. new_id = self._search_regex('play=(?P<id>[0-9]+)', video_path, 'new_id', group='id')
  91. video_url = compat_urlparse.urljoin(url, video_path)
  92. return self._extract_from_player(video_url, new_id)