misskey extractor
This commit is contained in:
parent
2c8fa677b2
commit
fa290c78e7
|
@ -713,6 +713,7 @@ from .minds import (
|
|||
from .ministrygrid import MinistryGridIE
|
||||
from .minoto import MinotoIE
|
||||
from .miomio import MioMioIE
|
||||
from .misskey import MisskeySHIE
|
||||
from .mit import TechTVMITIE, OCWMITIE
|
||||
from .mitele import MiTeleIE
|
||||
from .mixcloud import (
|
||||
|
|
63
haruhi_dl/extractor/misskey.py
Normal file
63
haruhi_dl/extractor/misskey.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
# coding: utf-8
|
||||
|
||||
from .common import SelfhostedInfoExtractor
|
||||
from ..utils import (
|
||||
mimetype2ext,
|
||||
parse_iso8601,
|
||||
ExtractorError,
|
||||
)
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class MisskeySHIE(SelfhostedInfoExtractor):
|
||||
IE_NAME = 'misskey'
|
||||
_VALID_URL = r'misskey:(?P<host>[^:]+):(?P<id>[\da-z]+)'
|
||||
_SH_VALID_URL = r'https?://(?P<host>[^/]+)/notes/(?P<id>[\da-z]+)'
|
||||
_SH_VALID_CONTENT_STRINGS = (
|
||||
'<meta name="application-name" content="Misskey"',
|
||||
'<meta name="misskey:',
|
||||
'<!-- If you are reading this message... how about joining the development of Misskey? -->',
|
||||
)
|
||||
|
||||
def _selfhosted_extract(self, url, webpage=None):
|
||||
host, video_id = self._match_id_and_host(url)
|
||||
|
||||
post = self._download_json(f'https://{host}/api/notes/show', video_id,
|
||||
data=bytes(json.dumps({
|
||||
'noteId': video_id,
|
||||
}).encode('utf-8')),
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
})
|
||||
|
||||
entries = []
|
||||
for file in post['files']:
|
||||
if not file['type'].startswith('video/') and not file['type'].startswith('audio/'):
|
||||
continue
|
||||
entries.append({
|
||||
'id': file['id'],
|
||||
'url': file['url'],
|
||||
'ext': mimetype2ext(file.get('type')),
|
||||
'title': file.get('name'),
|
||||
'thumbnail': file.get('thumbnailUrl'),
|
||||
'timestamp': parse_iso8601(file.get('createdAt')),
|
||||
'filesize': file['size'] if file.get('size') != 0 else None,
|
||||
'age_limit': 18 if file.get('isSensitive') else 0,
|
||||
})
|
||||
|
||||
if len(entries) == 0:
|
||||
raise ExtractorError('No media found in post')
|
||||
elif len(entries) == 1:
|
||||
info_dict = entries[0]
|
||||
else:
|
||||
info_dict = {
|
||||
'_type': 'playlist',
|
||||
'entries': entries,
|
||||
}
|
||||
|
||||
info_dict.update({
|
||||
'id': video_id,
|
||||
'title': post.get('text') or '_',
|
||||
})
|
||||
return info_dict
|
Loading…
Reference in a new issue