]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/noovo.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / noovo.py
1 from .brightcove import BrightcoveNewIE
2 from .common import InfoExtractor
3 from ..compat import compat_str
4 from ..utils import (
5 int_or_none,
6 js_to_json,
7 smuggle_url,
8 try_get,
9 )
10
11
12 class NoovoIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:[^/]+\.)?noovo\.ca/videos/(?P<id>[^/]+/[^/?#&]+)'
14 _TESTS = [{
15 # clip
16 'url': 'http://noovo.ca/videos/rpm-plus/chrysler-imperial',
17 'info_dict': {
18 'id': '5386045029001',
19 'ext': 'mp4',
20 'title': 'Chrysler Imperial',
21 'description': 'md5:de3c898d1eb810f3e6243e08c8b4a056',
22 'timestamp': 1491399228,
23 'upload_date': '20170405',
24 'uploader_id': '618566855001',
25 'series': 'RPM+',
26 },
27 'params': {
28 'skip_download': True,
29 },
30 }, {
31 # episode
32 'url': 'http://noovo.ca/videos/l-amour-est-dans-le-pre/episode-13-8',
33 'info_dict': {
34 'id': '5395865725001',
35 'title': 'Épisode 13 : Les retrouvailles',
36 'description': 'md5:888c3330f0c1b4476c5bc99a1c040473',
37 'ext': 'mp4',
38 'timestamp': 1492019320,
39 'upload_date': '20170412',
40 'uploader_id': '618566855001',
41 'series': "L'amour est dans le pré",
42 'season_number': 5,
43 'episode': 'Épisode 13',
44 'episode_number': 13,
45 },
46 'params': {
47 'skip_download': True,
48 },
49 }]
50 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/618566855001/default_default/index.html?videoId=%s'
51
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54
55 webpage = self._download_webpage(url, video_id)
56
57 brightcove_id = self._search_regex(
58 r'data-video-id=["\'](\d+)', webpage, 'brightcove id')
59
60 data = self._parse_json(
61 self._search_regex(
62 r'(?s)dataLayer\.push\(\s*({.+?})\s*\);', webpage, 'data',
63 default='{}'),
64 video_id, transform_source=js_to_json, fatal=False)
65
66 title = try_get(
67 data, lambda x: x['video']['nom'],
68 compat_str) or self._html_search_meta(
69 'dcterms.Title', webpage, 'title', fatal=True)
70
71 description = self._html_search_meta(
72 ('dcterms.Description', 'description'), webpage, 'description')
73
74 series = try_get(
75 data, lambda x: x['emission']['nom']) or self._search_regex(
76 r'<div[^>]+class="banner-card__subtitle h4"[^>]*>([^<]+)',
77 webpage, 'series', default=None)
78
79 season_el = try_get(data, lambda x: x['emission']['saison'], dict) or {}
80 season = try_get(season_el, lambda x: x['nom'], compat_str)
81 season_number = int_or_none(try_get(season_el, lambda x: x['numero']))
82
83 episode_el = try_get(season_el, lambda x: x['episode'], dict) or {}
84 episode = try_get(episode_el, lambda x: x['nom'], compat_str)
85 episode_number = int_or_none(try_get(episode_el, lambda x: x['numero']))
86
87 return {
88 '_type': 'url_transparent',
89 'ie_key': BrightcoveNewIE.ie_key(),
90 'url': smuggle_url(
91 self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
92 {'geo_countries': ['CA']}),
93 'id': brightcove_id,
94 'title': title,
95 'description': description,
96 'series': series,
97 'season': season,
98 'season_number': season_number,
99 'episode': episode,
100 'episode_number': episode_number,
101 }