mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-26 23:00:22 +00:00
[franceculture] Rewrite for new HTML scheme (Fixes #4853)
This commit is contained in:
parent
4c1a017e69
commit
23d9ded655
@ -103,6 +103,16 @@ def expect_info_dict(self, got_dict, expected_dict):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
match_rex.match(got),
|
match_rex.match(got),
|
||||||
'field %s (value: %r) should match %r' % (info_field, got, match_str))
|
'field %s (value: %r) should match %r' % (info_field, got, match_str))
|
||||||
|
elif isinstance(expected, compat_str) and expected.startswith('startswith:'):
|
||||||
|
got = got_dict.get(info_field)
|
||||||
|
start_str = expected[len('startswith:'):]
|
||||||
|
self.assertTrue(
|
||||||
|
isinstance(got, compat_str),
|
||||||
|
'Expected a %s object, but got %s for field %s' % (
|
||||||
|
compat_str.__name__, type(got).__name__, info_field))
|
||||||
|
self.assertTrue(
|
||||||
|
got.startswith(start_str),
|
||||||
|
'field %s (value: %r) should start with %r' % (info_field, got, start_str))
|
||||||
elif isinstance(expected, type):
|
elif isinstance(expected, type):
|
||||||
got = got_dict.get(info_field)
|
got = got_dict.get(info_field)
|
||||||
self.assertTrue(isinstance(got, expected),
|
self.assertTrue(isinstance(got, expected),
|
||||||
|
@ -1,77 +1,69 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_parse_qs,
|
|
||||||
compat_urlparse,
|
compat_urlparse,
|
||||||
)
|
)
|
||||||
|
from ..utils import (
|
||||||
|
determine_ext,
|
||||||
|
int_or_none,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class FranceCultureIE(InfoExtractor):
|
class FranceCultureIE(InfoExtractor):
|
||||||
_VALID_URL = r'(?P<baseurl>http://(?:www\.)?franceculture\.fr/)player/reecouter\?play=(?P<id>[0-9]+)'
|
_VALID_URL = r'https?://(?:www\.)?franceculture\.fr/player/reecouter\?play=(?P<id>[0-9]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://www.franceculture.fr/player/reecouter?play=4795174',
|
'url': 'http://www.franceculture.fr/player/reecouter?play=4795174',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '4795174',
|
'id': '4795174',
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
'title': 'Rendez-vous au pays des geeks',
|
'title': 'Rendez-vous au pays des geeks',
|
||||||
|
'alt_title': 'Carnet nomade | 13-14',
|
||||||
'vcodec': 'none',
|
'vcodec': 'none',
|
||||||
'uploader': 'Colette Fellous',
|
|
||||||
'upload_date': '20140301',
|
'upload_date': '20140301',
|
||||||
'duration': 3601,
|
|
||||||
'thumbnail': r're:^http://www\.franceculture\.fr/.*/images/player/Carnet-nomade\.jpg$',
|
'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 ...',
|
'description': 'startswith:Avec :Jean-Baptiste Péretié pour son documentaire sur Arte "La revanche des « geeks », une enquête menée aux Etats',
|
||||||
|
'timestamp': 1393700400,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
video_id = self._match_id(url)
|
||||||
video_id = mobj.group('id')
|
|
||||||
baseurl = mobj.group('baseurl')
|
|
||||||
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
params_code = self._search_regex(
|
|
||||||
r"<param name='movie' value='/sites/all/modules/rf/rf_player/swf/loader.swf\?([^']+)' />",
|
video_path = self._search_regex(
|
||||||
webpage, 'parameter code')
|
r'<a id="player".*?href="([^"]+)"', webpage, 'video path')
|
||||||
params = compat_parse_qs(params_code)
|
video_url = compat_urlparse.urljoin(url, video_path)
|
||||||
video_url = compat_urlparse.urljoin(baseurl, params['urlAOD'][0])
|
timestamp = int_or_none(self._search_regex(
|
||||||
|
r'<a id="player".*?data-date="([0-9]+)"',
|
||||||
|
webpage, 'upload date', fatal=False))
|
||||||
|
thumbnail = self._search_regex(
|
||||||
|
r'<a id="player".*?>\s+<img src="([^"]+)"',
|
||||||
|
webpage, 'thumbnail', fatal=False)
|
||||||
|
|
||||||
title = self._html_search_regex(
|
title = self._html_search_regex(
|
||||||
r'<h1 class="title[^"]+">(.+?)</h1>', webpage, 'title')
|
r'<span class="title-diffusion">(.*?)</span>', webpage, 'title')
|
||||||
|
alt_title = self._html_search_regex(
|
||||||
|
r'<span class="title">(.*?)</span>',
|
||||||
|
webpage, 'alt_title', fatal=False)
|
||||||
|
description = self._html_search_regex(
|
||||||
|
r'<span class="description">(.*?)</span>',
|
||||||
|
webpage, 'description', fatal=False)
|
||||||
|
|
||||||
uploader = self._html_search_regex(
|
uploader = self._html_search_regex(
|
||||||
r'(?s)<div id="emission".*?<span class="author">(.*?)</span>',
|
r'(?s)<div id="emission".*?<span class="author">(.*?)</span>',
|
||||||
webpage, 'uploader', fatal=False)
|
webpage, 'uploader', default=None)
|
||||||
thumbnail_part = self._html_search_regex(
|
vcodec = 'none' if determine_ext(video_url.lower()) == 'mp3' else None
|
||||||
r'(?s)<div id="emission".*?<img src="([^"]+)"', webpage,
|
|
||||||
'thumbnail', fatal=False)
|
|
||||||
if thumbnail_part is None:
|
|
||||||
thumbnail = None
|
|
||||||
else:
|
|
||||||
thumbnail = compat_urlparse.urljoin(baseurl, thumbnail_part)
|
|
||||||
description = self._html_search_regex(
|
|
||||||
r'(?s)<p class="desc">(.*?)</p>', webpage, 'description')
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'vcodec': 'none' if video_url.lower().endswith('.mp3') else None,
|
'vcodec': vcodec,
|
||||||
'duration': duration,
|
|
||||||
'uploader': uploader,
|
'uploader': uploader,
|
||||||
'upload_date': upload_date,
|
'timestamp': timestamp,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
'alt_title': alt_title,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'description': description,
|
'description': description,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user