[mastodon] support cards to external services
This commit is contained in:
parent
6adb5ea838
commit
e83f44815c
|
@ -10,6 +10,7 @@ from ..utils import (
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
|
url_or_none,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -118,6 +119,18 @@ class MastodonSHIE(SelfhostedInfoExtractor):
|
||||||
'title': 're:.+ - #FEDIBLOCK',
|
'title': 're:.+ - #FEDIBLOCK',
|
||||||
'ext': 'oga',
|
'ext': 'oga',
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
# mastodon, card to youtube
|
||||||
|
'url': 'https://mstdn.social/@polamatysiak/106183574509332910',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'RWDU0BjcYp0',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'polamatysiak - Moje wczorajsze wystąpienie w Sejmie, koniecznie zobaczcie do końca 🙂 \n#pracaposłanki\n\nhttps://youtu.be/RWDU0BjcYp0',
|
||||||
|
'description': 'md5:0c16fa11a698d5d1b171963fd6833297',
|
||||||
|
'uploader': 'Paulina Matysiak',
|
||||||
|
'uploader_id': 'UCLRAd9-Hw6kEI1aPBrSaF9A',
|
||||||
|
'upload_date': '20210505',
|
||||||
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _determine_instance_software(self, host, webpage=None):
|
def _determine_instance_software(self, host, webpage=None):
|
||||||
|
@ -298,11 +311,8 @@ class MastodonSHIE(SelfhostedInfoExtractor):
|
||||||
'Authorization': login_info['authorization'],
|
'Authorization': login_info['authorization'],
|
||||||
} if login_info else {})
|
} if login_info else {})
|
||||||
|
|
||||||
if not metadata['media_attachments']:
|
|
||||||
raise ExtractorError('No attached medias')
|
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for media in metadata['media_attachments']:
|
for media in metadata['media_attachments'] or ():
|
||||||
if media['type'] in ('video', 'audio'):
|
if media['type'] in ('video', 'audio'):
|
||||||
entries.append({
|
entries.append({
|
||||||
'id': media['id'],
|
'id': media['id'],
|
||||||
|
@ -315,8 +325,6 @@ class MastodonSHIE(SelfhostedInfoExtractor):
|
||||||
'height': int_or_none(try_get(media, lambda x: x['meta']['original']['height'])),
|
'height': int_or_none(try_get(media, lambda x: x['meta']['original']['height'])),
|
||||||
'tbr': int_or_none(try_get(media, lambda x: x['meta']['original']['bitrate'])),
|
'tbr': int_or_none(try_get(media, lambda x: x['meta']['original']['bitrate'])),
|
||||||
})
|
})
|
||||||
if len(entries) == 0:
|
|
||||||
raise ExtractorError('No audio/video attachments')
|
|
||||||
|
|
||||||
title = '%s - %s' % (str_or_none(metadata['account'].get('display_name') or metadata['account']['acct']), clean_html(str_or_none(metadata['content'])))
|
title = '%s - %s' % (str_or_none(metadata['account'].get('display_name') or metadata['account']['acct']), clean_html(str_or_none(metadata['content'])))
|
||||||
if ap_censorship_circuvement == 'peertube':
|
if ap_censorship_circuvement == 'peertube':
|
||||||
|
@ -325,6 +333,17 @@ class MastodonSHIE(SelfhostedInfoExtractor):
|
||||||
r'^<p><a href="[^"]+">(.+?)</a></p>',
|
r'^<p><a href="[^"]+">(.+?)</a></p>',
|
||||||
metadata['content'], 'video title'))
|
metadata['content'], 'video title'))
|
||||||
|
|
||||||
|
if len(entries) == 0:
|
||||||
|
card = metadata.get('card')
|
||||||
|
if card:
|
||||||
|
return {
|
||||||
|
'_type': 'url_transparent',
|
||||||
|
'url': card['url'],
|
||||||
|
'title': title,
|
||||||
|
'thumbnail': url_or_none(card.get('image')),
|
||||||
|
}
|
||||||
|
raise ExtractorError('No audio/video attachments')
|
||||||
|
|
||||||
info_dict = {
|
info_dict = {
|
||||||
"id": id,
|
"id": id,
|
||||||
"title": title,
|
"title": title,
|
||||||
|
|
Loading…
Reference in a new issue