[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / peertv.py
blob726d5e14c34fc8dd35a863758301ee3cec856177
1 from .common import InfoExtractor
2 from ..utils import js_to_json
5 class PeerTVIE(InfoExtractor):
6 IE_NAME = 'peer.tv'
7 _VALID_URL = r'https?://(?:www\.)?peer\.tv/(?:de|it|en)/(?P<id>\d+)'
8 _TESTS = [{
9 'url': 'https://www.peer.tv/de/841',
10 'info_dict': {
11 'id': '841',
12 'ext': 'mp4',
13 'title': 'Die Brunnenburg',
14 'description': 'md5:4395f6142b090338340ab88a3aae24ed',
16 }, {
17 'url': 'https://www.peer.tv/it/404',
18 'info_dict': {
19 'id': '404',
20 'ext': 'mp4',
21 'title': 'Cascate di ghiaccio in Val Gardena',
22 'description': 'md5:e8e5907f236171842674e8090e3577b8',
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id)
30 video_key = self._html_search_regex(r'player\.peer\.tv/js/([a-zA-Z0-9]+)', webpage, 'video key')
32 js = self._download_webpage(f'https://player.peer.tv/js/{video_key}/', video_id,
33 headers={'Referer': 'https://www.peer.tv/'}, note='Downloading session id')
35 session_id = self._search_regex(r'["\']session_id["\']:\s*["\']([a-zA-Z0-9]+)["\']', js, 'session id')
37 player_webpage = self._download_webpage(
38 f'https://player.peer.tv/jsc/{video_key}/{session_id}?jsr=aHR0cHM6Ly93d3cucGVlci50di9kZS84NDE=&cs=UTF-8&mq=2&ua=0&webm=p&mp4=p&hls=1',
39 video_id, note='Downloading player webpage')
41 m3u8_url = self._search_regex(r'["\']playlist_url["\']:\s*(["\'][^"\']+["\'])', player_webpage, 'm3u8 url')
42 m3u8_url = self._parse_json(m3u8_url, video_id, transform_source=js_to_json)
44 formats = self._extract_m3u8_formats(m3u8_url, video_id, m3u8_id='hls')
46 return {
47 'id': video_id,
48 'title': self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title').replace('\xa0', ' '),
49 'formats': formats,
50 'description': self._html_search_meta(('og:description', 'description'), webpage),
51 'thumbnail': self._html_search_meta(('og:image', 'image'), webpage),