[franceculture] fix extraction(closes #12547)
[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 ..utils import (
6     determine_ext,
7     extract_attributes,
8     int_or_none,
9     unified_strdate,
10 )
11
12
13 class FranceCultureIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emissions/(?:[^/]+/)*(?P<id>[^/?#&]+)'
15     _TEST = {
16         'url': 'http://www.franceculture.fr/emissions/carnet-nomade/rendez-vous-au-pays-des-geeks',
17         'info_dict': {
18             'id': 'rendez-vous-au-pays-des-geeks',
19             'display_id': 'rendez-vous-au-pays-des-geeks',
20             'ext': 'mp3',
21             'title': 'Rendez-vous au pays des geeks',
22             'thumbnail': r're:^https?://.*\.jpg$',
23             'upload_date': '20140301',
24             'timestamp': 1393642916,
25             'vcodec': 'none',
26         }
27     }
28
29     def _real_extract(self, url):
30         display_id = self._match_id(url)
31
32         webpage = self._download_webpage(url, display_id)
33
34         video_data = extract_attributes(self._search_regex(
35             r'(?s)<div[^>]+class="[^"]*?(?:title-zone-diffusion|heading-zone-(?:wrapper|player-button))[^"]*?"[^>]*>.*?(<button[^>]+data-asset-source="[^"]+"[^>]+>)',
36             webpage, 'video data'))
37
38         video_url = video_data['data-asset-source']
39         title = video_data.get('data-asset-title') or self._og_search_title(webpage)
40
41         description = self._html_search_regex(
42             r'(?s)<div[^>]+class="intro"[^>]*>.*?<h2>(.+?)</h2>',
43             webpage, 'description', default=None)
44         thumbnail = self._search_regex(
45             r'(?s)<figure[^>]+itemtype="https://schema.org/ImageObject"[^>]*>.*?<img[^>]+(?:data-dejavu-)?src="([^"]+)"',
46             webpage, 'thumbnail', fatal=False)
47         uploader = self._html_search_regex(
48             r'(?s)<span class="author">(.*?)</span>',
49             webpage, 'uploader', default=None)
50         ext = determine_ext(video_url.lower())
51
52         return {
53             'id': display_id,
54             'display_id': display_id,
55             'url': video_url,
56             'title': title,
57             'description': description,
58             'thumbnail': thumbnail,
59             'ext': ext,
60             'vcodec': 'none' if ext == 'mp3' else None,
61             'uploader': uploader,
62             'timestamp': int_or_none(video_data.get('data-asset-created-date')),
63             'duration': int_or_none(video_data.get('data-duration')),
64         }