]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/noovo.py
[ie/youtube] Extract upload timestamp if available (#9856)
[yt-dlp.git] / yt_dlp / extractor / noovo.py
CommitLineData
b5c39537 1from .brightcove import BrightcoveNewIE
1c7c76e4 2from .common import InfoExtractor
b5c39537
S
3from ..compat import compat_str
4from ..utils import (
5 int_or_none,
a4245ace 6 js_to_json,
b5c39537
S
7 smuggle_url,
8 try_get,
9)
1c7c76e4
FB
10
11
12class NoovoIE(InfoExtractor):
b5c39537 13 _VALID_URL = r'https?://(?:[^/]+\.)?noovo\.ca/videos/(?P<id>[^/]+/[^/?#&]+)'
1c7c76e4 14 _TESTS = [{
b5c39537 15 # clip
1c7c76e4 16 'url': 'http://noovo.ca/videos/rpm-plus/chrysler-imperial',
1c7c76e4
FB
17 'info_dict': {
18 'id': '5386045029001',
1c7c76e4 19 'ext': 'mp4',
1c7c76e4 20 'title': 'Chrysler Imperial',
b5c39537
S
21 'description': 'md5:de3c898d1eb810f3e6243e08c8b4a056',
22 'timestamp': 1491399228,
1c7c76e4 23 'upload_date': '20170405',
b5c39537 24 'uploader_id': '618566855001',
b5c39537
S
25 'series': 'RPM+',
26 },
27 'params': {
28 'skip_download': True,
29 },
1c7c76e4 30 }, {
b5c39537 31 # episode
1c7c76e4 32 'url': 'http://noovo.ca/videos/l-amour-est-dans-le-pre/episode-13-8',
1c7c76e4
FB
33 'info_dict': {
34 'id': '5395865725001',
b5c39537 35 'title': 'Épisode 13 : Les retrouvailles',
a4245ace 36 'description': 'md5:888c3330f0c1b4476c5bc99a1c040473',
1c7c76e4
FB
37 'ext': 'mp4',
38 'timestamp': 1492019320,
1c7c76e4 39 'upload_date': '20170412',
b5c39537 40 'uploader_id': '618566855001',
b5c39537
S
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 },
1c7c76e4 49 }]
1c7c76e4
FB
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)
1c7c76e4 54
a4245ace 55 webpage = self._download_webpage(url, video_id)
1c7c76e4 56
ba2e3730
S
57 brightcove_id = self._search_regex(
58 r'data-video-id=["\'](\d+)', webpage, 'brightcove id')
b5c39537 59
a4245ace
S
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')
b5c39537
S
73
74 series = try_get(
a4245ace
S
75 data, lambda x: x['emission']['nom']) or self._search_regex(
76 r'<div[^>]+class="banner-card__subtitle h4"[^>]*>([^<]+)',
77 webpage, 'series', default=None)
b5c39537 78
a4245ace
S
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']))
b5c39537 82
a4245ace
S
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']))
b5c39537
S
86
87 return {
88 '_type': 'url_transparent',
89 'ie_key': BrightcoveNewIE.ie_key(),
ba2e3730
S
90 'url': smuggle_url(
91 self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
92 {'geo_countries': ['CA']}),
93 'id': brightcove_id,
a4245ace
S
94 'title': title,
95 'description': description,
b5c39537 96 'series': series,
a4245ace
S
97 'season': season,
98 'season_number': season_number,
b5c39537 99 'episode': episode,
a4245ace 100 'episode_number': episode_number,
b5c39537 101 }