]> asedeno.scripts.mit.edu Git - youtube-dl.git/blob - youtube_dl/extractor/franceculture.py
[eroprofile] Skip test
[youtube-dl.git] / 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     _TESTS = [{
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': 1393700400,
24             'vcodec': 'none',
25         }
26     }, {
27         # no thumbnail
28         'url': 'https://www.franceculture.fr/emissions/la-recherche-montre-en-main/la-recherche-montre-en-main-du-mercredi-10-octobre-2018',
29         'only_matching': True,
30     }]
31
32     def _real_extract(self, url):
33         display_id = self._match_id(url)
34
35         webpage = self._download_webpage(url, display_id)
36
37         video_data = extract_attributes(self._search_regex(
38             r'''(?sx)
39                 (?:
40                     </h1>|
41                     <div[^>]+class="[^"]*?(?:title-zone-diffusion|heading-zone-(?:wrapper|player-button))[^"]*?"[^>]*>
42                 ).*?
43                 (<button[^>]+data-(?:url|asset-source)="[^"]+"[^>]+>)
44             ''',
45             webpage, 'video data'))
46
47         video_url = video_data.get('data-url') or video_data['data-asset-source']
48         title = video_data.get('data-asset-title') or video_data.get('data-diffusion-title') or self._og_search_title(webpage)
49
50         description = self._html_search_regex(
51             r'(?s)<div[^>]+class="intro"[^>]*>.*?<h2>(.+?)</h2>',
52             webpage, 'description', default=None)
53         thumbnail = self._search_regex(
54             r'(?s)<figure[^>]+itemtype="https://schema.org/ImageObject"[^>]*>.*?<img[^>]+(?:data-dejavu-)?src="([^"]+)"',
55             webpage, 'thumbnail', default=None)
56         uploader = self._html_search_regex(
57             r'(?s)<span class="author">(.*?)</span>',
58             webpage, 'uploader', default=None)
59         ext = determine_ext(video_url.lower())
60
61         return {
62             'id': display_id,
63             'display_id': display_id,
64             'url': video_url,
65             'title': title,
66             'description': description,
67             'thumbnail': thumbnail,
68             'ext': ext,
69             'vcodec': 'none' if ext == 'mp3' else None,
70             'uploader': uploader,
71             'timestamp': int_or_none(video_data.get('data-start-time')) or int_or_none(video_data.get('data-asset-created-date')),
72             'duration': int_or_none(video_data.get('data-duration')),
73         }