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