[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / alsace20tv.py
blobc315e4f2170401f4f2442d05d0bba1671d2e8d6f
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 dict_get,
5 get_element_by_class,
6 int_or_none,
7 unified_strdate,
8 url_or_none,
12 class Alsace20TVBaseIE(InfoExtractor):
13 def _extract_video(self, video_id, url=None):
14 info = self._download_json(
15 f'https://www.alsace20.tv/visionneuse/visio_v9_js.php?key={video_id}&habillage=0&mode=html',
16 video_id) or {}
17 title = info.get('titre')
19 formats = []
20 for res, fmt_url in (info.get('files') or {}).items():
21 formats.extend(
22 self._extract_smil_formats(fmt_url, video_id, fatal=False)
23 if '/smil:_' in fmt_url
24 else self._extract_mpd_formats(fmt_url, video_id, mpd_id=res, fatal=False))
26 webpage = (url and self._download_webpage(url, video_id, fatal=False)) or ''
27 thumbnail = url_or_none(dict_get(info, ('image', 'preview')) or self._og_search_thumbnail(webpage))
28 upload_date = self._search_regex(r'/(\d{6})_', thumbnail, 'upload_date', default=None)
29 upload_date = unified_strdate(f'20{upload_date[:2]}-{upload_date[2:4]}-{upload_date[4:]}') if upload_date else None
30 return {
31 'id': video_id,
32 'title': title,
33 'formats': formats,
34 'description': clean_html(get_element_by_class('wysiwyg', webpage)),
35 'upload_date': upload_date,
36 'thumbnail': thumbnail,
37 'duration': int_or_none(self._og_search_property('video:duration', webpage) if webpage else None),
38 'view_count': int_or_none(info.get('nb_vues')),
42 class Alsace20TVIE(Alsace20TVBaseIE):
43 _VALID_URL = r'https?://(?:www\.)?alsace20\.tv/(?:[\w-]+/)+[\w-]+-(?P<id>[\w]+)'
44 _TESTS = [{
45 'url': 'https://www.alsace20.tv/VOD/Actu/JT/Votre-JT-jeudi-3-fevrier-lyNHCXpYJh.html',
46 'info_dict': {
47 'id': 'lyNHCXpYJh',
48 'ext': 'mp4',
49 'description': 'md5:fc0bc4a0692d3d2dba4524053de4c7b7',
50 'title': 'Votre JT du jeudi 3 février',
51 'upload_date': '20220203',
52 'thumbnail': r're:https?://.+\.jpg',
53 'duration': 1073,
54 'view_count': int,
58 def _real_extract(self, url):
59 video_id = self._match_id(url)
60 return self._extract_video(video_id, url)
63 class Alsace20TVEmbedIE(Alsace20TVBaseIE):
64 _VALID_URL = r'https?://(?:www\.)?alsace20\.tv/emb/(?P<id>[\w]+)'
65 _TESTS = [{
66 'url': 'https://www.alsace20.tv/emb/lyNHCXpYJh',
67 # 'md5': 'd91851bf9af73c0ad9b2cdf76c127fbb',
68 'info_dict': {
69 'id': 'lyNHCXpYJh',
70 'ext': 'mp4',
71 'title': 'Votre JT du jeudi 3 février',
72 'upload_date': '20220203',
73 'thumbnail': r're:https?://.+\.jpg',
74 'view_count': int,
76 'params': {
77 'format': 'bestvideo',
81 def _real_extract(self, url):
82 video_id = self._match_id(url)
83 return self._extract_video(video_id)