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