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