Release 2024.12.03
[yt-dlp3.git] / yt_dlp / extractor / tva.py
blob48c4e9cba681366946ee3dce7624e38e86e642c2
1 import re
3 from .brightcove import BrightcoveNewIE
4 from .common import InfoExtractor
5 from ..utils import float_or_none, int_or_none, smuggle_url, strip_or_none
6 from ..utils.traversal import traverse_obj
9 class TVAIE(InfoExtractor):
10 IE_NAME = 'tvaplus'
11 IE_DESC = 'TVA+'
12 _VALID_URL = r'https?://(?:www\.)?tvaplus\.ca/(?:[^/?#]+/)*[\w-]+-(?P<id>\d+)(?:$|[#?])'
13 _TESTS = [{
14 'url': 'https://www.tvaplus.ca/tva/alerte-amber/saison-1/episode-01-1000036619',
15 'md5': '949490fd0e7aee11d0543777611fbd53',
16 'info_dict': {
17 'id': '6084352463001',
18 'ext': 'mp4',
19 'title': 'Mon dernier jour',
20 'uploader_id': '5481942443001',
21 'upload_date': '20190907',
22 'timestamp': 1567899756,
23 'description': 'md5:9c0d7fbb90939420c651fd977df90145',
24 'thumbnail': r're:https://.+\.jpg',
25 'episode': 'Mon dernier jour',
26 'episode_number': 1,
27 'tags': ['alerte amber', 'alerte amber saison 1', 'surdemande'],
28 'duration': 2625.963,
29 'season': 'Season 1',
30 'season_number': 1,
31 'series': 'Alerte Amber',
32 'channel': 'TVA',
34 }, {
35 'url': 'https://www.tvaplus.ca/tva/le-baiser-du-barbu/le-baiser-du-barbu-886644190',
36 'info_dict': {
37 'id': '6354448043112',
38 'ext': 'mp4',
39 'title': 'Le Baiser du barbu',
40 'uploader_id': '5481942443001',
41 'upload_date': '20240606',
42 'timestamp': 1717694023,
43 'description': 'md5:025b1219086c1cbf4bc27e4e034e8b57',
44 'thumbnail': r're:https://.+\.jpg',
45 'episode': 'Le Baiser du barbu',
46 'tags': ['fullepisode', 'films'],
47 'duration': 6053.504,
48 'series': 'Le Baiser du barbu',
49 'channel': 'TVA',
52 _BC_URL_TMPL = 'https://players.brightcove.net/5481942443001/default_default/index.html?videoId={}'
54 def _real_extract(self, url):
55 entity_id = self._match_id(url)
56 webpage = self._download_webpage(url, entity_id)
57 entity = self._search_nextjs_data(webpage, entity_id)['props']['pageProps']['staticEntity']
58 video_id = entity['videoId']
59 episode = strip_or_none(entity.get('name'))
61 return {
62 '_type': 'url_transparent',
63 'url': smuggle_url(self._BC_URL_TMPL.format(video_id), {'geo_countries': ['CA']}),
64 'ie_key': BrightcoveNewIE.ie_key(),
65 'id': video_id,
66 'title': episode,
67 'episode': episode,
68 **traverse_obj(entity, {
69 'description': ('longDescription', {str}),
70 'duration': ('durationMillis', {float_or_none(scale=1000)}),
71 'channel': ('knownEntities', 'channel', 'name', {str}),
72 'series': ('knownEntities', 'videoShow', 'name', {str}),
73 'season_number': ('slug', {lambda x: re.search(r'/s(?:ai|ea)son-(\d+)/', x)}, 1, {int_or_none}),
74 'episode_number': ('episodeNumber', {int_or_none}),
75 }),