mirror of https://gitlab.com/bashrc2/epicyon
Create video attachment from peertube-style post
parent
23b20a8a58
commit
694a913b08
|
@ -12,6 +12,7 @@ from shutil import copyfile
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from session import get_json
|
from session import get_json
|
||||||
from session import get_json_valid
|
from session import get_json_valid
|
||||||
|
from utils import get_media_url_from_video
|
||||||
from utils import get_attributed_to
|
from utils import get_attributed_to
|
||||||
from utils import local_network_host
|
from utils import local_network_host
|
||||||
from utils import dangerous_markup
|
from utils import dangerous_markup
|
||||||
|
@ -1245,15 +1246,37 @@ def get_post_attachments_as_html(base_dir: str,
|
||||||
"""Returns a string representing any attachments
|
"""Returns a string representing any attachments
|
||||||
"""
|
"""
|
||||||
attachment_str = ''
|
attachment_str = ''
|
||||||
|
attachment_ctr = 0
|
||||||
gallery_str = ''
|
gallery_str = ''
|
||||||
|
attachment_dict = []
|
||||||
|
|
||||||
|
# handle peertube-style video posts, where the media links
|
||||||
|
# are stored in the url field
|
||||||
|
if post_json_object.get('object'):
|
||||||
|
media_type, media_url, _, _ = \
|
||||||
|
get_media_url_from_video(post_json_object['object'])
|
||||||
|
else:
|
||||||
|
media_type, media_url, _, _ = \
|
||||||
|
get_media_url_from_video(post_json_object)
|
||||||
|
if media_url and media_type:
|
||||||
|
attachment_dict = [{
|
||||||
|
'mediaType': media_type,
|
||||||
|
'name': content,
|
||||||
|
'type': 'Document',
|
||||||
|
'url': media_url
|
||||||
|
}]
|
||||||
|
if not post_json_object['object'].get('attachment'):
|
||||||
|
post_json_object['object']['attachment'] = \
|
||||||
|
attachment_dict
|
||||||
|
|
||||||
if not post_json_object['object'].get('attachment'):
|
if not post_json_object['object'].get('attachment'):
|
||||||
return attachment_str, gallery_str
|
return attachment_str, gallery_str
|
||||||
|
|
||||||
if not isinstance(post_json_object['object']['attachment'], list):
|
if not isinstance(post_json_object['object']['attachment'], list):
|
||||||
return attachment_str, gallery_str
|
return attachment_str, gallery_str
|
||||||
|
|
||||||
attachment_ctr = 0
|
attachment_dict += post_json_object['object']['attachment']
|
||||||
attachment_str = ''
|
|
||||||
media_style_added = False
|
media_style_added = False
|
||||||
post_id = None
|
post_id = None
|
||||||
if post_json_object['object'].get('id'):
|
if post_json_object['object'].get('id'):
|
||||||
|
@ -1262,7 +1285,7 @@ def get_post_attachments_as_html(base_dir: str,
|
||||||
|
|
||||||
# chat links
|
# chat links
|
||||||
# https://codeberg.org/fediverse/fep/src/branch/main/fep/1970/fep-1970.md
|
# https://codeberg.org/fediverse/fep/src/branch/main/fep/1970/fep-1970.md
|
||||||
for attach in post_json_object['object']['attachment']:
|
for attach in attachment_dict:
|
||||||
if not attach.get('type') or \
|
if not attach.get('type') or \
|
||||||
not attach.get('name') or \
|
not attach.get('name') or \
|
||||||
not attach.get('href') or \
|
not attach.get('href') or \
|
||||||
|
@ -1299,7 +1322,7 @@ def get_post_attachments_as_html(base_dir: str,
|
||||||
|
|
||||||
# obtain transcripts
|
# obtain transcripts
|
||||||
transcripts = {}
|
transcripts = {}
|
||||||
for attach in post_json_object['object']['attachment']:
|
for attach in attachment_dict:
|
||||||
if not attach.get('mediaType'):
|
if not attach.get('mediaType'):
|
||||||
continue
|
continue
|
||||||
if attach['mediaType'] != 'text/vtt':
|
if attach['mediaType'] != 'text/vtt':
|
||||||
|
@ -1323,7 +1346,7 @@ def get_post_attachments_as_html(base_dir: str,
|
||||||
if name and url:
|
if name and url:
|
||||||
transcripts[name] = remove_html(url)
|
transcripts[name] = remove_html(url)
|
||||||
|
|
||||||
for attach in post_json_object['object']['attachment']:
|
for attach in attachment_dict:
|
||||||
if not (attach.get('mediaType') and attach.get('url')):
|
if not (attach.get('mediaType') and attach.get('url')):
|
||||||
continue
|
continue
|
||||||
media_license = ''
|
media_license = ''
|
||||||
|
|
Loading…
Reference in New Issue