]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tva.py
Prepare to upload
[youtubedl] / youtube_dl / extractor / tva.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 float_or_none,
7 smuggle_url,
8 )
9
10
11 class TVAIE(InfoExtractor):
12 _VALID_URL = r'https?://videos?\.tva\.ca/details/_(?P<id>\d+)'
13 _TESTS = [{
14 'url': 'https://videos.tva.ca/details/_5596811470001',
15 'info_dict': {
16 'id': '5596811470001',
17 'ext': 'mp4',
18 'title': 'Un extrait de l\'épisode du dimanche 8 octobre 2017 !',
19 'uploader_id': '5481942443001',
20 'upload_date': '20171003',
21 'timestamp': 1507064617,
22 },
23 'params': {
24 # m3u8 download
25 'skip_download': True,
26 }
27 }, {
28 'url': 'https://video.tva.ca/details/_5596811470001',
29 'only_matching': True,
30 }]
31 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5481942443001/default_default/index.html?videoId=%s'
32
33 def _real_extract(self, url):
34 video_id = self._match_id(url)
35 video_data = self._download_json(
36 'https://videos.tva.ca/proxy/item/_' + video_id, video_id, headers={
37 'Accept': 'application/json',
38 }, query={
39 'appId': '5955fc5f23eec60006c951f1',
40 })
41
42 def get_attribute(key):
43 for attribute in video_data.get('attributes', []):
44 if attribute.get('key') == key:
45 return attribute.get('value')
46 return None
47
48 return {
49 '_type': 'url_transparent',
50 'id': video_id,
51 'title': get_attribute('title'),
52 'url': smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % video_id, {'geo_countries': ['CA']}),
53 'description': get_attribute('description'),
54 'thumbnail': get_attribute('image-background') or get_attribute('image-landscape'),
55 'duration': float_or_none(get_attribute('video-duration'), 1000),
56 'ie_key': 'BrightcoveNew',
57 }