]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/curiositystream.py
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
):
31 headers
['X-Auth-Token'] = self
._auth
_token
32 result
= self
._download
_json
(
33 self
._API
_BASE
_URL
+ path
, video_id
, headers
=headers
)
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']
49 def _extract_media_info(self
, media
):
50 video_id
= compat_str(media
['id'])
51 title
= media
['title']
54 for encoding
in media
.get('encodings', []):
55 m3u8_url
= encoding
.get('master_playlist_url')
57 formats
.extend(self
._extract
_m
3u8_formats
(
58 m3u8_url
, video_id
, 'mp4', 'm3u8_native',
59 m3u8_id
='hls', fatal
=False))
60 encoding_url
= encoding
.get('url')
61 file_url
= encoding
.get('file_url')
62 if not encoding_url
and not file_url
:
65 'width': int_or_none(encoding
.get('width')),
66 'height': int_or_none(encoding
.get('height')),
67 'vbr': int_or_none(encoding
.get('video_bitrate')),
68 'abr': int_or_none(encoding
.get('audio_bitrate')),
69 'filesize': int_or_none(encoding
.get('size_in_bytes')),
70 'vcodec': encoding
.get('video_codec'),
71 'acodec': encoding
.get('audio_codec'),
72 'container': encoding
.get('container_type'),
74 for f_url
in (encoding_url
, file_url
):
78 rtmp
= re
.search(r
'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', f_url
)
81 'url': rtmp
.group('url'),
82 'play_path': rtmp
.group('playpath'),
83 'app': rtmp
.group('app'),
93 self
._sort
_formats
(formats
)
96 for closed_caption
in media
.get('closed_captions', []):
97 sub_url
= closed_caption
.get('file')
100 lang
= closed_caption
.get('code') or closed_caption
.get('language') or 'en'
101 subtitles
.setdefault(lang
, []).append({
109 'description': media
.get('description'),
110 'thumbnail': media
.get('image_large') or media
.get('image_medium') or media
.get('image_small'),
111 'duration': int_or_none(media
.get('duration')),
112 'tags': media
.get('tags'),
113 'subtitles': subtitles
,
117 class CuriosityStreamIE(CuriosityStreamBaseIE
):
118 IE_NAME
= 'curiositystream'
119 _VALID_URL
= r
'https?://app\.curiositystream\.com/video/(?P<id>\d+)'
121 'url': 'https://app.curiositystream.com/video/2',
122 'md5': '262bb2f257ff301115f1973540de8983',
126 'title': 'How Did You Develop The Internet?',
127 'description': 'Vint Cerf, Google\'s Chief Internet Evangelist, describes how he and Bob Kahn created the internet.',
131 def _real_extract(self
, url
):
132 video_id
= self
._match
_id
(url
)
133 media
= self
._call
_api
('media/' + video_id
, video_id
)
134 return self
._extract
_media
_info
(media
)
137 class CuriosityStreamCollectionIE(CuriosityStreamBaseIE
):
138 IE_NAME
= 'curiositystream:collection'
139 _VALID_URL
= r
'https?://app\.curiositystream\.com/collection/(?P<id>\d+)'
141 'url': 'https://app.curiositystream.com/collection/2',
144 'title': 'Curious Minds: The Internet',
145 'description': 'How is the internet shaping our lives in the 21st Century?',
147 'playlist_mincount': 12,
150 def _real_extract(self
, url
):
151 collection_id
= self
._match
_id
(url
)
152 collection
= self
._call
_api
(
153 'collections/' + collection_id
, collection_id
)
155 for media
in collection
.get('media', []):
156 entries
.append(self
._extract
_media
_info
(media
))
157 return self
.playlist_result(
158 entries
, collection_id
,
159 collection
.get('title'), collection
.get('description'))