]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/curiositystream.py
e3c99468c1ce26d34063e140c59f5479bfafb363
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
13 class CuriosityStreamBaseIE(InfoExtractor
):
14 _NETRC_MACHINE
= 'curiositystream'
16 _API_BASE_URL
= 'https://api.curiositystream.com/v1/'
18 def _handle_errors(self
, result
):
19 error
= result
.get('error', {}).get('message')
21 if isinstance(error
, dict):
22 error
= ', '.join(error
.values())
24 '%s said: %s' % (self
.IE_NAME
, error
), expected
=True)
26 def _call_api(self
, path
, video_id
):
29 headers
['X-Auth-Token'] = self
._auth
_token
30 result
= self
._download
_json
(
31 self
._API
_BASE
_URL
+ path
, video_id
, headers
=headers
)
32 self
._handle
_errors
(result
)
35 def _real_initialize(self
):
36 (email
, password
) = self
._get
_login
_info
()
39 result
= self
._download
_json
(
40 self
._API
_BASE
_URL
+ 'login', None, data
=urlencode_postdata({
44 self
._handle
_errors
(result
)
45 self
._auth
_token
= result
['message']['auth_token']
47 def _extract_media_info(self
, media
):
48 video_id
= compat_str(media
['id'])
49 limelight_media_id
= media
['limelight_media_id']
50 title
= media
['title']
53 for closed_caption
in media
.get('closed_captions', []):
54 sub_url
= closed_caption
.get('file')
57 lang
= closed_caption
.get('code') or closed_caption
.get('language') or 'en'
58 subtitles
.setdefault(lang
, []).append({
63 '_type': 'url_transparent',
65 'url': 'limelight:media:' + limelight_media_id
,
67 'description': media
.get('description'),
68 'thumbnail': media
.get('image_large') or media
.get('image_medium') or media
.get('image_small'),
69 'duration': int_or_none(media
.get('duration')),
70 'tags': media
.get('tags'),
71 'subtitles': subtitles
,
72 'ie_key': 'LimelightMedia',
76 class CuriosityStreamIE(CuriosityStreamBaseIE
):
77 IE_NAME
= 'curiositystream'
78 _VALID_URL
= r
'https?://app\.curiositystream\.com/video/(?P<id>\d+)'
80 'url': 'https://app.curiositystream.com/video/2',
81 'md5': 'a0074c190e6cddaf86900b28d3e9ee7a',
85 'title': 'How Did You Develop The Internet?',
86 'description': 'Vint Cerf, Google\'s Chief Internet Evangelist, describes how he and Bob Kahn created the internet.',
87 'timestamp': 1448388615,
88 'upload_date': '20151124',
92 def _real_extract(self
, url
):
93 video_id
= self
._match
_id
(url
)
94 media
= self
._call
_api
('media/' + video_id
, video_id
)
95 return self
._extract
_media
_info
(media
)
98 class CuriosityStreamCollectionIE(CuriosityStreamBaseIE
):
99 IE_NAME
= 'curiositystream:collection'
100 _VALID_URL
= r
'https?://app\.curiositystream\.com/collection/(?P<id>\d+)'
102 'url': 'https://app.curiositystream.com/collection/2',
105 'title': 'Curious Minds: The Internet',
106 'description': 'How is the internet shaping our lives in the 21st Century?',
108 'playlist_mincount': 17,
111 def _real_extract(self
, url
):
112 collection_id
= self
._match
_id
(url
)
113 collection
= self
._call
_api
(
114 'collections/' + collection_id
, collection_id
)
116 for media
in collection
.get('media', []):
117 entries
.append(self
._extract
_media
_info
(media
))
118 return self
.playlist_result(
119 entries
, collection_id
,
120 collection
.get('title'), collection
.get('description'))