]>
Commit | Line | Data |
---|---|---|
59cc5bd8 ZB |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | ExtractorError, | |
1a8f0773 S |
4 | float_or_none, |
5 | int_or_none, | |
fee3f44f | 6 | try_get, |
7 | parse_codecs, | |
59cc5bd8 ZB |
8 | ) |
9 | ||
10 | ||
11 | class StreamableIE(InfoExtractor): | |
e8bfe2a9 | 12 | _VALID_URL = r'https?://streamable\.com/(?:[es]/)?(?P<id>\w+)' |
bfd973ec | 13 | _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(?P<q1>[\'"])(?P<url>(?:https?:)?//streamable\.com/.+?)(?P=q1)'] |
59cc5bd8 ZB |
14 | _TESTS = [ |
15 | { | |
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', | |
ec85ded8 | 22 | 'thumbnail': r're:https?://.*\.jpg$', |
1a8f0773 S |
23 | 'uploader': 'teabaker', |
24 | 'timestamp': 1454964157.35115, | |
25 | 'upload_date': '20160208', | |
26 | 'duration': 61.516, | |
27 | 'view_count': int, | |
59cc5bd8 ZB |
28 | } |
29 | }, | |
fee3f44f | 30 | # older video without bitrate, width/height, codecs, etc. info |
59cc5bd8 ZB |
31 | { |
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!"', | |
ec85ded8 | 38 | 'thumbnail': r're:https?://.*\.jpg$', |
1a8f0773 S |
39 | 'timestamp': 1426115495, |
40 | 'upload_date': '20150311', | |
41 | 'duration': 12, | |
42 | 'view_count': int, | |
59cc5bd8 | 43 | } |
1a8f0773 S |
44 | }, |
45 | { | |
46 | 'url': 'https://streamable.com/e/dnd1', | |
47 | 'only_matching': True, | |
e8bfe2a9 L |
48 | }, |
49 | { | |
50 | 'url': 'https://streamable.com/s/okkqk/drxjds', | |
51 | 'only_matching': True, | |
59cc5bd8 ZB |
52 | } |
53 | ] | |
54 | ||
55 | def _real_extract(self, url): | |
56 | video_id = self._match_id(url) | |
57 | ||
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( | |
c1795ca6 | 62 | 'https://ajax.streamable.com/videos/%s' % video_id, video_id) |
59cc5bd8 ZB |
63 | |
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) | |
74 | ||
1a8f0773 S |
75 | title = video.get('reddit_title') or video['title'] |
76 | ||
59cc5bd8 | 77 | formats = [] |
1a8f0773 S |
78 | for key, info in video['files'].items(): |
79 | if not info.get('url'): | |
80 | continue | |
59cc5bd8 ZB |
81 | formats.append({ |
82 | 'format_id': key, | |
1a8f0773 S |
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')), | |
fee3f44f | 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'), | |
59cc5bd8 | 91 | }) |
59cc5bd8 ZB |
92 | |
93 | return { | |
94 | 'id': video_id, | |
1a8f0773 S |
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')), | |
59cc5bd8 ZB |
102 | 'formats': formats |
103 | } |