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