[noovo] Improve extraction (closes #12792)

pull/2/head
Sergey M․ 8 years ago
parent 1c7c76e4fb
commit b5c39537be
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

@ -1,52 +1,97 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from .brightcove import BrightcoveNewIE
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import (
int_or_none,
smuggle_url,
try_get,
)
class NoovoIE(InfoExtractor): class NoovoIE(InfoExtractor):
IE_NAME = 'Noovo' _VALID_URL = r'https?://(?:[^/]+\.)?noovo\.ca/videos/(?P<id>[^/]+/[^/?#&]+)'
IE_DESC = 'VTele, Max, MusiquePlus'
_VALID_URL = r'https?://(?:[a-z0-9-]+\.)?noovo\.ca/videos/(?P<id>[a-z0-9-]+/[a-z0-9-]+)'
_TESTS = [{ _TESTS = [{
# clip
'url': 'http://noovo.ca/videos/rpm-plus/chrysler-imperial', 'url': 'http://noovo.ca/videos/rpm-plus/chrysler-imperial',
'md5': '2fcc04d0a8f4a853fad91233c2fdd121',
'info_dict': { 'info_dict': {
'id': '5386045029001', 'id': '5386045029001',
'description': 'Antoine présente des véhicules qu\'il aperçoit sur la rue.',
'ext': 'mp4', 'ext': 'mp4',
'timestamp': 1491399228,
'title': 'Chrysler Imperial', 'title': 'Chrysler Imperial',
'description': 'md5:de3c898d1eb810f3e6243e08c8b4a056',
'timestamp': 1491399228,
'upload_date': '20170405', 'upload_date': '20170405',
'uploader_id': '618566855001' 'uploader_id': '618566855001',
} 'creator': 'vtele',
'view_count': int,
'series': 'RPM+',
},
'params': {
'skip_download': True,
},
}, { }, {
# episode
'url': 'http://noovo.ca/videos/l-amour-est-dans-le-pre/episode-13-8', 'url': 'http://noovo.ca/videos/l-amour-est-dans-le-pre/episode-13-8',
'md5': '1199e96fbb93f2d42717115f72097b6b',
'info_dict': { 'info_dict': {
'id': '5395865725001', 'id': '5395865725001',
'title': 'Épisode 13 : Les retrouvailles',
'description': 'md5:336d5ebc5436534e61d16e63ddfca327', 'description': 'md5:336d5ebc5436534e61d16e63ddfca327',
'ext': 'mp4', 'ext': 'mp4',
'timestamp': 1492019320, 'timestamp': 1492019320,
'title': 'md5:2895fdc124639be0ef64ea0d06f5e493',
'upload_date': '20170412', 'upload_date': '20170412',
'uploader_id': '618566855001' 'uploader_id': '618566855001',
} 'creator': 'vtele',
}, { 'view_count': int,
'url': 'http://interventions.noovo.ca/911/video/intoxication-aux-drogues-dures/?autoplay=1', 'series': "L'amour est dans le pré",
'only_matching': True 'season_number': 5,
'episode': 'Épisode 13',
'episode_number': 13,
},
'params': {
'skip_download': True,
},
}] }]
API_URL_TEMPLATE = 'http://api.noovo.ca/api/v1/pages/single-episode/%s'
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/618566855001/default_default/index.html?videoId=%s' BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/618566855001/default_default/index.html?videoId=%s'
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
api_url = self.API_URL_TEMPLATE % video_id
api_content = self._download_json(api_url, video_id)
brightcove_id = api_content.get('data').get('brightcoveId') data = self._download_json(
if not brightcove_id: 'http://api.noovo.ca/api/v1/pages/single-episode/%s' % video_id,
brightcove_id = api_content.get('data').get('contents')[0].get('brightcoveId') video_id)['data']
return self.url_result( content = try_get(data, lambda x: x['contents'][0])
self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id, 'BrightcoveNew', brightcove_id
) brightcove_id = data.get('brightcoveId') or content['brightcoveId']
series = try_get(
data, (
lambda x: x['show']['title'],
lambda x: x['season']['show']['title']),
compat_str)
episode = None
og = data.get('og')
if isinstance(og, dict) and og.get('type') == 'video.episode':
episode = og.get('title')
video = content or data
return {
'_type': 'url_transparent',
'ie_key': BrightcoveNewIE.ie_key(),
'url': smuggle_url(
self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
{'geo_countries': ['CA']}),
'id': brightcove_id,
'title': video.get('title'),
'creator': video.get('source'),
'view_count': int_or_none(video.get('viewsCount')),
'series': series,
'season_number': int_or_none(try_get(
data, lambda x: x['season']['seasonNumber'])),
'episode': episode,
'episode_number': int_or_none(data.get('episodeNumber')),
}

Loading…
Cancel
Save