2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class CuriosityStreamBaseIE(InfoExtractor
):
16 _NETRC_MACHINE
= 'curiositystream'
18 _API_BASE_URL
= 'https://api.curiositystream.com/v1/'
20 def _handle_errors(self
, result
):
21 error
= result
.get('error', {}).get('message')
23 if isinstance(error
, dict):
24 error
= ', '.join(error
.values())
26 '%s said: %s' % (self
.IE_NAME
, error
), expected
=True)
28 def _call_api(self
, path
, video_id
, query
=None):
31 headers
['X-Auth-Token'] = self
._auth
_token
32 result
= self
._download
_json
(
33 self
._API
_BASE
_URL
+ path
, video_id
, headers
=headers
, query
=query
)
34 self
._handle
_errors
(result
)
37 def _real_initialize(self
):
38 email
, password
= self
._get
_login
_info
()
41 result
= self
._download
_json
(
42 self
._API
_BASE
_URL
+ 'login', None, data
=urlencode_postdata({
46 self
._handle
_errors
(result
)
47 self
._auth
_token
= result
['message']['auth_token']
50 class CuriosityStreamIE(CuriosityStreamBaseIE
):
51 IE_NAME
= 'curiositystream'
52 _VALID_URL
= r
'https?://(?:app\.)?curiositystream\.com/video/(?P<id>\d+)'
54 'url': 'https://app.curiositystream.com/video/2',
58 'title': 'How Did You Develop The Internet?',
59 'description': 'Vint Cerf, Google\'s Chief Internet Evangelist, describes how he and Bob Kahn created the internet.',
62 'format': 'bestvideo',
64 'skip_download': True,
68 def _real_extract(self
, url
):
69 video_id
= self
._match
_id
(url
)
72 for encoding_format
in ('m3u8', 'mpd'):
73 media
= self
._call
_api
('media/' + video_id
, video_id
, query
={
74 'encodingsNew': 'true',
75 'encodingsFormat': encoding_format
,
77 for encoding
in media
.get('encodings', []):
78 playlist_url
= encoding
.get('master_playlist_url')
79 if encoding_format
== 'm3u8':
80 # use `m3u8` entry_protocol until EXT-X-MAP is properly supported by `m3u8_native` entry_protocol
81 formats
.extend(self
._extract
_m
3u8_formats
(
82 playlist_url
, video_id
, 'mp4',
83 m3u8_id
='hls', fatal
=False))
84 elif encoding_format
== 'mpd':
85 formats
.extend(self
._extract
_mpd
_formats
(
86 playlist_url
, video_id
, mpd_id
='dash', fatal
=False))
87 encoding_url
= encoding
.get('url')
88 file_url
= encoding
.get('file_url')
89 if not encoding_url
and not file_url
:
92 'width': int_or_none(encoding
.get('width')),
93 'height': int_or_none(encoding
.get('height')),
94 'vbr': int_or_none(encoding
.get('video_bitrate')),
95 'abr': int_or_none(encoding
.get('audio_bitrate')),
96 'filesize': int_or_none(encoding
.get('size_in_bytes')),
97 'vcodec': encoding
.get('video_codec'),
98 'acodec': encoding
.get('audio_codec'),
99 'container': encoding
.get('container_type'),
101 for f_url
in (encoding_url
, file_url
):
105 rtmp
= re
.search(r
'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', f_url
)
108 'url': rtmp
.group('url'),
109 'play_path': rtmp
.group('playpath'),
110 'app': rtmp
.group('app'),
120 self
._sort
_formats
(formats
)
122 title
= media
['title']
125 for closed_caption
in media
.get('closed_captions', []):
126 sub_url
= closed_caption
.get('file')
129 lang
= closed_caption
.get('code') or closed_caption
.get('language') or 'en'
130 subtitles
.setdefault(lang
, []).append({
138 'description': media
.get('description'),
139 'thumbnail': media
.get('image_large') or media
.get('image_medium') or media
.get('image_small'),
140 'duration': int_or_none(media
.get('duration')),
141 'tags': media
.get('tags'),
142 'subtitles': subtitles
,
146 class CuriosityStreamCollectionIE(CuriosityStreamBaseIE
):
147 IE_NAME
= 'curiositystream:collection'
148 _VALID_URL
= r
'https?://(?:app\.)?curiositystream\.com/(?:collections?|series)/(?P<id>\d+)'
149 _API_BASE_URL
= 'https://api.curiositystream.com/v2/collections/'
151 'url': 'https://curiositystream.com/collections/86',
154 'title': 'Staff Picks',
155 'description': 'Wondering where to start? Here are a few of our favorite series and films... from our couch to yours.',
157 'playlist_mincount': 7,
159 'url': 'https://app.curiositystream.com/collection/2',
162 'title': 'Curious Minds: The Internet',
163 'description': 'How is the internet shaping our lives in the 21st Century?',
165 'playlist_mincount': 16,
167 'url': 'https://curiositystream.com/series/2',
168 'only_matching': True,
170 'url': 'https://curiositystream.com/collections/36',
171 'only_matching': True,
174 def _real_extract(self
, url
):
175 collection_id
= self
._match
_id
(url
)
176 collection
= self
._call
_api
(collection_id
, collection_id
)
178 for media
in collection
.get('media', []):
179 media_id
= compat_str(media
.get('id'))
180 media_type
, ie
= ('series', CuriosityStreamCollectionIE
) if media
.get('is_collection') else ('video', CuriosityStreamIE
)
181 entries
.append(self
.url_result(
182 'https://curiositystream.com/%s/%s' % (media_type
, media_id
),
183 ie
=ie
.ie_key(), video_id
=media_id
))
184 return self
.playlist_result(
185 entries
, collection_id
,
186 collection
.get('title'), collection
.get('description'))