2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..compat
import compat_str
14 class MindsBaseIE(InfoExtractor
):
15 _VALID_URL_BASE
= r
'https?://(?:www\.)?minds\.com/'
17 def _call_api(self
, path
, video_id
, resource
, query
=None):
18 api_url
= 'https://www.minds.com/api/' + path
19 token
= self
._get
_cookies
(api_url
).get('XSRF-TOKEN')
20 return self
._download
_json
(
21 api_url
, video_id
, 'Downloading %s JSON metadata' % resource
, headers
={
22 'Referer': 'https://www.minds.com/',
23 'X-XSRF-TOKEN': token
.value
if token
else '',
27 class MindsIE(MindsBaseIE
):
29 _VALID_URL
= MindsBaseIE
._VALID
_URL
_BASE
+ r
'(?:media|newsfeed|archive/view)/(?P<id>[0-9]+)'
31 'url': 'https://www.minds.com/media/100000000000086822',
32 'md5': '215a658184a419764852239d4970b045',
34 'id': '100000000000086822',
36 'title': 'Minds intro sequence',
37 'thumbnail': r
're:https?://.+\.png',
38 'uploader_id': 'ottman',
39 'upload_date': '20130524',
40 'timestamp': 1369404826,
41 'uploader': 'Bill Ottman',
45 'tags': ['animation'],
47 'license': 'attribution-cc',
50 # entity.type == 'activity' and empty title
51 'url': 'https://www.minds.com/newsfeed/798025111988506624',
52 'md5': 'b2733a74af78d7fd3f541c4cbbaa5950',
54 'id': '798022190320226304',
56 'title': '798022190320226304',
57 'uploader': 'ColinFlaherty',
58 'upload_date': '20180111',
59 'timestamp': 1515639316,
60 'uploader_id': 'ColinFlaherty',
63 'url': 'https://www.minds.com/archive/view/715172106794442752',
64 'only_matching': True,
67 'url': 'https://www.minds.com/newsfeed/1197131838022602752',
68 'only_matching': True,
71 def _real_extract(self
, url
):
72 entity_id
= self
._match
_id
(url
)
73 entity
= self
._call
_api
(
74 'v1/entities/entity/' + entity_id
, entity_id
, 'entity')['entity']
75 if entity
.get('type') == 'activity':
76 if entity
.get('custom_type') == 'video':
77 video_id
= entity
['entity_guid']
79 return self
.url_result(entity
['perma_url'])
81 assert(entity
['subtype'] == 'video')
83 # 1080p and webm formats available only on the sources array
84 video
= self
._call
_api
(
85 'v2/media/video/' + video_id
, video_id
, 'video')
88 for source
in (video
.get('sources') or []):
89 src
= source
.get('src')
93 'format_id': source
.get('label'),
94 'height': int_or_none(source
.get('size')),
97 self
._sort
_formats
(formats
)
99 entity
= video
.get('entity') or entity
100 owner
= entity
.get('ownerObj') or {}
101 uploader_id
= owner
.get('username')
103 tags
= entity
.get('tags')
104 if tags
and isinstance(tags
, compat_str
):
108 poster
= video
.get('poster') or entity
.get('thumbnail_src')
110 urlh
= self
._request
_webpage
(poster
, video_id
, fatal
=False)
112 thumbnail
= urlh
.geturl()
116 'title': entity
.get('title') or video_id
,
118 'description': clean_html(entity
.get('description')) or None,
119 'license': str_or_none(entity
.get('license')),
120 'timestamp': int_or_none(entity
.get('time_created')),
121 'uploader': strip_or_none(owner
.get('name')),
122 'uploader_id': uploader_id
,
123 'uploader_url': 'https://www.minds.com/' + uploader_id
if uploader_id
else None,
124 'view_count': int_or_none(entity
.get('play:count')),
125 'like_count': int_or_none(entity
.get('thumbs:up:count')),
126 'dislike_count': int_or_none(entity
.get('thumbs:down:count')),
128 'comment_count': int_or_none(entity
.get('comments:count')),
129 'thumbnail': thumbnail
,
133 class MindsFeedBaseIE(MindsBaseIE
):
136 def _entries(self
, feed_id
):
137 query
= {'limit': self._PAGE_SIZE, 'sync': 1}
140 data
= self
._call
_api
(
141 'v2/feeds/container/%s/videos' % feed_id
,
142 feed_id
, 'page %s' % i
, query
)
143 entities
= data
.get('entities') or []
144 for entity
in entities
:
145 guid
= entity
.get('guid')
148 yield self
.url_result(
149 'https://www.minds.com/newsfeed/' + guid
,
150 MindsIE
.ie_key(), guid
)
151 query
['from_timestamp'] = data
['load-next']
152 if not (query
['from_timestamp'] and len(entities
) == self
._PAGE
_SIZE
):
156 def _real_extract(self
, url
):
157 feed_id
= self
._match
_id
(url
)
158 feed
= self
._call
_api
(
159 'v1/%s/%s' % (self
._FEED
_PATH
, feed_id
),
160 feed_id
, self
._FEED
_TYPE
)[self
._FEED
_TYPE
]
162 return self
.playlist_result(
163 self
._entries
(feed
['guid']), feed_id
,
164 strip_or_none(feed
.get('name')),
165 feed
.get('briefdescription'))
168 class MindsChannelIE(MindsFeedBaseIE
):
169 _FEED_TYPE
= 'channel'
170 IE_NAME
= 'minds:' + _FEED_TYPE
171 _VALID_URL
= MindsBaseIE
._VALID
_URL
_BASE
+ r
'(?!(?:newsfeed|media|api|archive|groups)/)(?P<id>[^/?&#]+)'
172 _FEED_PATH
= 'channel'
174 'url': 'https://www.minds.com/ottman',
177 'title': 'Bill Ottman',
178 'description': 'Co-creator & CEO @minds',
180 'playlist_mincount': 54,
184 class MindsGroupIE(MindsFeedBaseIE
):
186 IE_NAME
= 'minds:' + _FEED_TYPE
187 _VALID_URL
= MindsBaseIE
._VALID
_URL
_BASE
+ r
'groups/profile/(?P<id>[0-9]+)'
188 _FEED_PATH
= 'groups/group'
190 'url': 'https://www.minds.com/groups/profile/785582576369672204/feed/videos',
192 'id': '785582576369672204',
193 'title': 'Cooking Videos',
195 'playlist_mincount': 1,