1 from .common
import InfoExtractor
2 from ..compat
import compat_str
12 class MindsBaseIE(InfoExtractor
):
13 _VALID_URL_BASE
= r
'https?://(?:www\.)?minds\.com/'
15 def _call_api(self
, path
, video_id
, resource
, query
=None):
16 api_url
= 'https://www.minds.com/api/' + path
17 token
= self
._get
_cookies
(api_url
).get('XSRF-TOKEN')
18 return self
._download
_json
(
19 api_url
, video_id
, 'Downloading %s JSON metadata' % resource
, headers
={
20 'Referer': 'https://www.minds.com/',
21 'X-XSRF-TOKEN': token
.value
if token
else '',
25 class MindsIE(MindsBaseIE
):
27 _VALID_URL
= MindsBaseIE
._VALID
_URL
_BASE
+ r
'(?:media|newsfeed|archive/view)/(?P<id>[0-9]+)'
29 'url': 'https://www.minds.com/media/100000000000086822',
30 'md5': '215a658184a419764852239d4970b045',
32 'id': '100000000000086822',
34 'title': 'Minds intro sequence',
35 'thumbnail': r
're:https?://.+\.png',
36 'uploader_id': 'ottman',
37 'upload_date': '20130524',
38 'timestamp': 1369404826,
39 'uploader': 'Bill Ottman',
43 'tags': ['animation'],
45 'license': 'attribution-cc',
48 # entity.type == 'activity' and empty title
49 'url': 'https://www.minds.com/newsfeed/798025111988506624',
50 'md5': 'b2733a74af78d7fd3f541c4cbbaa5950',
52 'id': '798022190320226304',
54 'title': '798022190320226304',
55 'uploader': 'ColinFlaherty',
56 'upload_date': '20180111',
57 'timestamp': 1515639316,
58 'uploader_id': 'ColinFlaherty',
61 'url': 'https://www.minds.com/archive/view/715172106794442752',
62 'only_matching': True,
65 'url': 'https://www.minds.com/newsfeed/1197131838022602752',
66 'only_matching': True,
69 def _real_extract(self
, url
):
70 entity_id
= self
._match
_id
(url
)
71 entity
= self
._call
_api
(
72 'v1/entities/entity/' + entity_id
, entity_id
, 'entity')['entity']
73 if entity
.get('type') == 'activity':
74 if entity
.get('custom_type') == 'video':
75 video_id
= entity
['entity_guid']
77 return self
.url_result(entity
['perma_url'])
79 assert entity
['subtype'] == 'video'
81 # 1080p and webm formats available only on the sources array
82 video
= self
._call
_api
(
83 'v2/media/video/' + video_id
, video_id
, 'video')
86 for source
in (video
.get('sources') or []):
87 src
= source
.get('src')
91 'format_id': source
.get('label'),
92 'height': int_or_none(source
.get('size')),
96 entity
= video
.get('entity') or entity
97 owner
= entity
.get('ownerObj') or {}
98 uploader_id
= owner
.get('username')
100 tags
= entity
.get('tags')
101 if tags
and isinstance(tags
, compat_str
):
105 poster
= video
.get('poster') or entity
.get('thumbnail_src')
107 urlh
= self
._request
_webpage
(poster
, video_id
, fatal
=False)
113 'title': entity
.get('title') or video_id
,
115 'description': clean_html(entity
.get('description')) or None,
116 'license': str_or_none(entity
.get('license')),
117 'timestamp': int_or_none(entity
.get('time_created')),
118 'uploader': strip_or_none(owner
.get('name')),
119 'uploader_id': uploader_id
,
120 'uploader_url': format_field(uploader_id
, None, 'https://www.minds.com/%s'),
121 'view_count': int_or_none(entity
.get('play:count')),
122 'like_count': int_or_none(entity
.get('thumbs:up:count')),
123 'dislike_count': int_or_none(entity
.get('thumbs:down:count')),
125 'comment_count': int_or_none(entity
.get('comments:count')),
126 'thumbnail': thumbnail
,
130 class MindsFeedBaseIE(MindsBaseIE
):
133 def _entries(self
, feed_id
):
134 query
= {'limit': self
._PAGE
_SIZE
, 'sync': 1}
137 data
= self
._call
_api
(
138 'v2/feeds/container/%s/videos' % feed_id
,
139 feed_id
, 'page %s' % i
, query
)
140 entities
= data
.get('entities') or []
141 for entity
in entities
:
142 guid
= entity
.get('guid')
145 yield self
.url_result(
146 'https://www.minds.com/newsfeed/' + guid
,
147 MindsIE
.ie_key(), guid
)
148 query
['from_timestamp'] = data
['load-next']
149 if not (query
['from_timestamp'] and len(entities
) == self
._PAGE
_SIZE
):
153 def _real_extract(self
, url
):
154 feed_id
= self
._match
_id
(url
)
155 feed
= self
._call
_api
(
156 'v1/%s/%s' % (self
._FEED
_PATH
, feed_id
),
157 feed_id
, self
._FEED
_TYPE
)[self
._FEED
_TYPE
]
159 return self
.playlist_result(
160 self
._entries
(feed
['guid']), feed_id
,
161 strip_or_none(feed
.get('name')),
162 feed
.get('briefdescription'))
165 class MindsChannelIE(MindsFeedBaseIE
):
166 _FEED_TYPE
= 'channel'
167 IE_NAME
= 'minds:' + _FEED_TYPE
168 _VALID_URL
= MindsBaseIE
._VALID
_URL
_BASE
+ r
'(?!(?:newsfeed|media|api|archive|groups)/)(?P<id>[^/?&#]+)'
169 _FEED_PATH
= 'channel'
171 'url': 'https://www.minds.com/ottman',
174 'title': 'Bill Ottman',
175 'description': 'Co-creator & CEO @minds',
177 'playlist_mincount': 54,
181 class MindsGroupIE(MindsFeedBaseIE
):
183 IE_NAME
= 'minds:' + _FEED_TYPE
184 _VALID_URL
= MindsBaseIE
._VALID
_URL
_BASE
+ r
'groups/profile/(?P<id>[0-9]+)'
185 _FEED_PATH
= 'groups/group'
187 'url': 'https://www.minds.com/groups/profile/785582576369672204/feed/videos',
189 'id': '785582576369672204',
190 'title': 'Cooking Videos',
192 'playlist_mincount': 1,