[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / streamable.py
blob62ae0ee46cb19cc82e361399f65dbecdb82edf9f
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 float_or_none,
5 int_or_none,
6 parse_codecs,
7 try_get,
11 class StreamableIE(InfoExtractor):
12 _VALID_URL = r'https?://streamable\.com/(?:[es]/)?(?P<id>\w+)'
13 _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(?P<q1>[\'"])(?P<url>(?:https?:)?//streamable\.com/.+?)(?P=q1)']
14 _TESTS = [
16 'url': 'https://streamable.com/dnd1',
17 'md5': '3e3bc5ca088b48c2d436529b64397fef',
18 'info_dict': {
19 'id': 'dnd1',
20 'ext': 'mp4',
21 'title': 'Mikel Oiarzabal scores to make it 0-3 for La Real against Espanyol',
22 'thumbnail': r're:https?://.*\.jpg$',
23 'uploader': 'teabaker',
24 'timestamp': 1454964157.35115,
25 'upload_date': '20160208',
26 'duration': 61.516,
27 'view_count': int,
30 # older video without bitrate, width/height, codecs, etc. info
32 'url': 'https://streamable.com/moo',
33 'md5': '2cf6923639b87fba3279ad0df3a64e73',
34 'info_dict': {
35 'id': 'moo',
36 'ext': 'mp4',
37 'title': '"Please don\'t eat me!"',
38 'thumbnail': r're:https?://.*\.jpg$',
39 'timestamp': 1426115495,
40 'upload_date': '20150311',
41 'duration': 12,
42 'view_count': int,
46 'url': 'https://streamable.com/e/dnd1',
47 'only_matching': True,
50 'url': 'https://streamable.com/s/okkqk/drxjds',
51 'only_matching': True,
55 def _real_extract(self, url):
56 video_id = self._match_id(url)
58 # Note: Using the ajax API, as the public Streamable API doesn't seem
59 # to return video info like the title properly sometimes, and doesn't
60 # include info like the video duration
61 video = self._download_json(
62 f'https://ajax.streamable.com/videos/{video_id}', video_id)
64 # Format IDs:
65 # 0 The video is being uploaded
66 # 1 The video is being processed
67 # 2 The video has at least one file ready
68 # 3 The video is unavailable due to an error
69 status = video.get('status')
70 if status != 2:
71 raise ExtractorError(
72 'This video is currently unavailable. It may still be uploading or processing.',
73 expected=True)
75 title = video.get('reddit_title') or video['title']
77 formats = []
78 for key, info in video['files'].items():
79 if not info.get('url'):
80 continue
81 formats.append({
82 'format_id': key,
83 'url': self._proto_relative_url(info['url']),
84 'width': int_or_none(info.get('width')),
85 'height': int_or_none(info.get('height')),
86 'filesize': int_or_none(info.get('size')),
87 'fps': int_or_none(info.get('framerate')),
88 'vbr': float_or_none(info.get('bitrate'), 1000),
89 'vcodec': parse_codecs(try_get(info, lambda x: x['input_metadata']['video_codec_name'])).get('vcodec'),
90 'acodec': parse_codecs(try_get(info, lambda x: x['input_metadata']['audio_codec_name'])).get('acodec'),
93 return {
94 'id': video_id,
95 'title': title,
96 'description': video.get('description'),
97 'thumbnail': self._proto_relative_url(video.get('thumbnail_url')),
98 'uploader': video.get('owner', {}).get('user_name'),
99 'timestamp': float_or_none(video.get('date_added')),
100 'duration': float_or_none(video.get('duration')),
101 'view_count': int_or_none(video.get('plays')),
102 'formats': formats,