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