[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / webcaster.py
blobb0865e3e684749cf8e6a66d616d03e235561205c
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 determine_ext,
6 join_nonempty,
7 xpath_text,
11 class WebcasterIE(InfoExtractor):
12 _VALID_URL = r'https?://bl\.webcaster\.pro/(?:quote|media)/start/free_(?P<id>[^/]+)'
13 _TESTS = [{
14 # http://video.khl.ru/quotes/393859
15 'url': 'http://bl.webcaster.pro/quote/start/free_c8cefd240aa593681c8d068cff59f407_hd/q393859/eb173f99dd5f558674dae55f4ba6806d/1480289104?sr%3D105%26fa%3D1%26type_id%3D18',
16 'md5': '0c162f67443f30916ff1c89425dcd4cd',
17 'info_dict': {
18 'id': 'c8cefd240aa593681c8d068cff59f407_hd',
19 'ext': 'mp4',
20 'title': 'Сибирь - Нефтехимик. Лучшие моменты первого периода',
21 'thumbnail': r're:^https?://.*\.jpg$',
23 }, {
24 'url': 'http://bl.webcaster.pro/media/start/free_6246c7a4453ac4c42b4398f840d13100_hd/2_2991109016/e8d0d82587ef435480118f9f9c41db41/4635726126',
25 'only_matching': True,
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
31 video = self._download_xml(url, video_id)
33 title = xpath_text(video, './/event_name', 'event name', fatal=True)
35 formats = []
36 for format_id in (None, 'noise'):
37 track_tag = join_nonempty('track', format_id, delim='_')
38 for track in video.findall(f'.//iphone/{track_tag}'):
39 track_url = track.text
40 if not track_url:
41 continue
42 if determine_ext(track_url) == 'm3u8':
43 m3u8_formats = self._extract_m3u8_formats(
44 track_url, video_id, 'mp4',
45 entry_protocol='m3u8_native',
46 m3u8_id=join_nonempty('hls', format_id, delim='-'), fatal=False)
47 for f in m3u8_formats:
48 f.update({
49 'source_preference': 0 if format_id == 'noise' else 1,
50 'format_note': track.get('title'),
52 formats.extend(m3u8_formats)
54 thumbnail = xpath_text(video, './/image', 'thumbnail')
56 return {
57 'id': video_id,
58 'title': title,
59 'thumbnail': thumbnail,
60 'formats': formats,
64 class WebcasterFeedIE(InfoExtractor):
65 _VALID_URL = r'https?://bl\.webcaster\.pro/feed/start/free_(?P<id>[^/]+)'
66 _EMBED_REGEX = [r'<(?:object|a[^>]+class=["\']webcaster-player["\'])[^>]+data(?:-config)?=(["\']).*?config=(?P<url>https?://bl\.webcaster\.pro/feed/start/free_.*?)(?:[?&]|\1)']
67 _TEST = {
68 'url': 'http://bl.webcaster.pro/feed/start/free_c8cefd240aa593681c8d068cff59f407_hd/q393859/eb173f99dd5f558674dae55f4ba6806d/1480289104',
69 'only_matching': True,
72 def _extract_from_webpage(self, url, webpage):
73 yield from super()._extract_from_webpage(url, webpage)
75 for secure in (True, False):
76 video_url = self._og_search_video_url(webpage, secure=secure, default=None)
77 if video_url:
78 mobj = re.search(
79 r'config=(?P<url>https?://bl\.webcaster\.pro/feed/start/free_[^?&=]+)',
80 video_url)
81 if mobj:
82 yield self.url_result(mobj.group('url'), self)
84 def _real_extract(self, url):
85 video_id = self._match_id(url)
87 feed = self._download_xml(url, video_id)
89 video_url = xpath_text(
90 feed, ('video_hd', 'video'), 'video url', fatal=True)
92 return self.url_result(video_url, WebcasterIE.ie_key())