[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / ora.py
blobc6ba4b0d3ea4311f0a050aa5c6668f573d5006eb
1 import re
2 import urllib.parse
4 from .common import InfoExtractor
5 from ..utils import (
6 get_element_by_attribute,
7 qualities,
8 unescapeHTML,
12 class OraTVIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?(?:ora\.tv|unsafespeech\.com)/([^/]+/)*(?P<id>[^/\?#]+)'
14 _TESTS = [{
15 'url': 'https://www.ora.tv/larrykingnow/2015/12/16/vine-youtube-stars-zach-king-king-bach-on-their-viral-videos-0_36jupg6090pq',
16 'md5': 'fa33717591c631ec93b04b0e330df786',
17 'info_dict': {
18 'id': '50178',
19 'ext': 'mp4',
20 'title': 'Vine & YouTube Stars Zach King & King Bach On Their Viral Videos!',
21 'description': 'md5:ebbc5b1424dd5dba7be7538148287ac1',
23 }, {
24 'url': 'http://www.unsafespeech.com/video/2016/5/10/student-self-censorship-and-the-thought-police-on-university-campuses-0_6622bnkppw4d',
25 'only_matching': True,
28 def _real_extract(self, url):
29 display_id = self._match_id(url)
30 webpage = self._download_webpage(url, display_id)
32 video_data = self._search_regex(
33 r'"(?:video|current)"\s*:\s*({[^}]+?})', webpage, 'current video')
34 m3u8_url = self._search_regex(
35 r'hls_stream"?\s*:\s*"([^"]+)', video_data, 'm3u8 url', None)
36 if m3u8_url:
37 formats = self._extract_m3u8_formats(
38 m3u8_url, display_id, 'mp4', 'm3u8_native',
39 m3u8_id='hls', fatal=False)
40 # similar to GameSpotIE
41 m3u8_path = urllib.parse.urlparse(m3u8_url).path
42 QUALITIES_RE = r'((,[a-z]+\d+)+,?)'
43 available_qualities = self._search_regex(
44 QUALITIES_RE, m3u8_path, 'qualities').strip(',').split(',')
45 http_path = m3u8_path[1:].split('/', 1)[1]
46 http_template = re.sub(QUALITIES_RE, r'%s', http_path)
47 http_template = http_template.replace('.csmil/master.m3u8', '')
48 http_template = urllib.parse.urljoin(
49 'http://videocdn-pmd.ora.tv/', http_template)
50 preference = qualities(
51 ['mobile400', 'basic400', 'basic600', 'sd900', 'sd1200', 'sd1500', 'hd720', 'hd1080'])
52 for q in available_qualities:
53 formats.append({
54 'url': http_template % q,
55 'format_id': q,
56 'quality': preference(q),
58 else:
59 return self.url_result(self._search_regex(
60 r'"youtube_id"\s*:\s*"([^"]+)', webpage, 'youtube id'), 'Youtube')
62 return {
63 'id': self._search_regex(
64 r'"id"\s*:\s*(\d+)', video_data, 'video id', default=display_id),
65 'display_id': display_id,
66 'title': unescapeHTML(self._og_search_title(webpage)),
67 'description': get_element_by_attribute(
68 'class', 'video_txt_decription', webpage),
69 'thumbnail': self._proto_relative_url(self._search_regex(
70 r'"thumb"\s*:\s*"([^"]+)', video_data, 'thumbnail', None)),
71 'formats': formats,