X-Git-Url: https://git.rapsys.eu/youtubedl/blobdiff_plain/453698570f26bebd37b39df8537d993b57d77b8b..d1d8237037fb87a57bd1d073c3b9e642d4a75016:/youtube_dl/extractor/franceculture.py diff --git a/youtube_dl/extractor/franceculture.py b/youtube_dl/extractor/franceculture.py index 0c29721..e2ca962 100644 --- a/youtube_dl/extractor/franceculture.py +++ b/youtube_dl/extractor/franceculture.py @@ -1,77 +1,105 @@ # coding: utf-8 from __future__ import unicode_literals -import json -import re - from .common import InfoExtractor from ..compat import ( - compat_parse_qs, compat_urlparse, ) +from ..utils import ( + determine_ext, + int_or_none, + ExtractorError, +) class FranceCultureIE(InfoExtractor): - _VALID_URL = r'(?Phttp://(?:www\.)?franceculture\.fr/)player/reecouter\?play=(?P[0-9]+)' + _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/player/reecouter\?play=(?P[0-9]+)' _TEST = { 'url': 'http://www.franceculture.fr/player/reecouter?play=4795174', 'info_dict': { 'id': '4795174', 'ext': 'mp3', 'title': 'Rendez-vous au pays des geeks', + 'alt_title': 'Carnet nomade | 13-14', 'vcodec': 'none', - 'uploader': 'Colette Fellous', 'upload_date': '20140301', - 'duration': 3601, - 'thumbnail': r're:^http://www\.franceculture\.fr/.*/images/player/Carnet-nomade\.jpg$', - 'description': 'Avec :Jean-Baptiste Péretié pour son documentaire sur Arte "La revanche des « geeks », une enquête menée aux Etats-Unis dans la S ...', + 'thumbnail': r're:^http://static\.franceculture\.fr/.*/images/player/Carnet-nomade\.jpg$', + 'description': 'startswith:Avec :Jean-Baptiste Péretié pour son documentaire sur Arte "La revanche', + 'timestamp': 1393700400, } } - def _real_extract(self, url): - mobj = re.match(self._VALID_URL, url) - video_id = mobj.group('id') - baseurl = mobj.group('baseurl') - + def _extract_from_player(self, url, video_id): webpage = self._download_webpage(url, video_id) - params_code = self._search_regex( - r"", - webpage, 'parameter code') - params = compat_parse_qs(params_code) - video_url = compat_urlparse.urljoin(baseurl, params['urlAOD'][0]) + + video_path = self._search_regex( + r'\s+emission-(.*?)', webpage, 'display_id') title = self._html_search_regex( - r'

(.+?)

', webpage, 'title') - uploader = self._html_search_regex( - r'(?s)
(.*?)', - webpage, 'uploader', fatal=False) - thumbnail_part = self._html_search_regex( - r'(?s)
(.*?)', webpage, 'title') + alt_title = self._html_search_regex( + r'(.*?)', + webpage, 'alt_title', fatal=False) description = self._html_search_regex( - r'(?s)

(.*?)

', webpage, 'description') + r'(.*?)', + webpage, 'description', fatal=False) - info = json.loads(params['infoData'][0])[0] - duration = info.get('media_length') - upload_date_candidate = info.get('media_section5') - upload_date = ( - upload_date_candidate - if (upload_date_candidate is not None and - re.match(r'[0-9]{8}$', upload_date_candidate)) - else None) + uploader = self._html_search_regex( + r'(?s)
(.*?)', + webpage, 'uploader', default=None) + vcodec = 'none' if determine_ext(video_url.lower()) == 'mp3' else None return { 'id': video_id, 'url': video_url, - 'vcodec': 'none' if video_url.lower().endswith('.mp3') else None, - 'duration': duration, + 'vcodec': vcodec, 'uploader': uploader, - 'upload_date': upload_date, + 'timestamp': timestamp, 'title': title, + 'alt_title': alt_title, 'thumbnail': thumbnail, 'description': description, + 'display_id': display_id, } + + def _real_extract(self, url): + video_id = self._match_id(url) + return self._extract_from_player(url, video_id) + + +class FranceCultureEmissionIE(FranceCultureIE): + _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emission-(?P[^?#]+)' + _TEST = { + 'url': 'http://www.franceculture.fr/emission-les-carnets-de-la-creation-jean-gabriel-periot-cineaste-2015-10-13', + 'info_dict': { + 'title': 'Jean-Gabriel Périot, cinéaste', + 'alt_title': 'Les Carnets de la création', + 'id': '5093239', + 'display_id': 'les-carnets-de-la-creation-jean-gabriel-periot-cineaste-2015-10-13', + 'ext': 'mp3', + 'timestamp': 1444762500, + 'upload_date': '20151013', + 'description': 'startswith:Aujourd\'hui dans "Les carnets de la création", le cinéaste', + }, + } + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + video_path = self._html_search_regex( + r'[0-9]+)', video_path, 'new_id', group='id') + video_url = compat_urlparse.urljoin(url, video_path) + return self._extract_from_player(video_url, new_id)