get content when converting video to note

main
Bob Mottram 2023-10-29 13:24:52 +00:00
parent aed024f21d
commit f447293436
6 changed files with 46 additions and 25 deletions

View File

@ -16,6 +16,7 @@ import webbrowser
import urllib.parse import urllib.parse
from pathlib import Path from pathlib import Path
from random import randint from random import randint
from utils import get_actor_languages_list
from utils import get_attributed_to from utils import get_attributed_to
from utils import remove_html from utils import remove_html
from utils import safe_system_string from utils import safe_system_string
@ -64,6 +65,7 @@ from bookmarks import send_bookmark_via_server
from bookmarks import send_undo_bookmark_via_server from bookmarks import send_undo_bookmark_via_server
from delete import send_delete_via_server from delete import send_delete_via_server
from person import get_actor_json from person import get_actor_json
from cache import get_person_from_cache
def _desktop_help() -> None: def _desktop_help() -> None:
@ -803,6 +805,12 @@ def _read_local_box_post(session, nickname: str, domain: str,
yt_replace_domain = None yt_replace_domain = None
twitter_replacement_domain = None twitter_replacement_domain = None
show_vote_posts = False show_vote_posts = False
languages_understood = []
person_url = local_actor_url(http_prefix, nickname, domain_full)
actor_json = \
get_person_from_cache(base_dir, person_url, person_cache)
if actor_json:
languages_understood = get_actor_languages_list(actor_json)
post_json_object2 = \ post_json_object2 = \
download_announce(session, base_dir, download_announce(session, base_dir,
http_prefix, http_prefix,
@ -817,7 +825,8 @@ def _read_local_box_post(session, nickname: str, domain: str,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blocked_cache, bold_reading, blocked_cache, bold_reading,
show_vote_posts) show_vote_posts,
languages_understood)
if post_json_object2: if post_json_object2:
if has_object_dict(post_json_object2): if has_object_dict(post_json_object2):
if post_json_object2['object'].get('attributedTo') and \ if post_json_object2['object'].get('attributedTo') and \
@ -2661,7 +2670,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
signing_priv_key_pem, signing_priv_key_pem,
blocked_cache, blocked_cache,
bold_reading, bold_reading,
show_vote_posts) show_vote_posts,
languages_understood)
if post_json_object2: if post_json_object2:
post_json_object = post_json_object2 post_json_object = post_json_object2
if post_json_object: if post_json_object:

View File

@ -3001,7 +3001,8 @@ def _receive_announce(recent_posts_cache: {},
lists_enabled: str, bold_reading: bool, lists_enabled: str, bold_reading: bool,
dogwhistles: {}, mitm: bool, dogwhistles: {}, mitm: bool,
min_images_for_accounts: [], min_images_for_accounts: [],
buy_sites: {}) -> bool: buy_sites: {},
languages_understood: []) -> bool:
"""Receives an announce activity within the POST section of HTTPServer """Receives an announce activity within the POST section of HTTPServer
""" """
if message_json['type'] != 'Announce': if message_json['type'] != 'Announce':
@ -3183,7 +3184,8 @@ def _receive_announce(recent_posts_cache: {},
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blocked_cache, bold_reading, blocked_cache, bold_reading,
show_vote_posts) show_vote_posts,
languages_understood)
if not post_json_object: if not post_json_object:
print('WARN: unable to download announce: ' + str(message_json)) print('WARN: unable to download announce: ' + str(message_json))
not_in_onion = True not_in_onion = True
@ -4757,7 +4759,8 @@ def _inbox_after_initial(server, inbox_start_time,
max_like_count, cw_lists, lists_enabled, max_like_count, cw_lists, lists_enabled,
bold_reading, dogwhistles, mitm, bold_reading, dogwhistles, mitm,
server.min_images_for_accounts, server.min_images_for_accounts,
server.buy_sites): server.buy_sites,
languages_understood):
if debug: if debug:
print('DEBUG: Announce accepted from ' + actor) print('DEBUG: Announce accepted from ' + actor)
fitness_performance(inbox_start_time, server.fitness, fitness_performance(inbox_start_time, server.fitness,
@ -4973,7 +4976,8 @@ def _inbox_after_initial(server, inbox_start_time,
allow_local_network_access, allow_local_network_access,
recent_posts_cache, debug, system_language, recent_posts_cache, debug, system_language,
domain_full, person_cache, signing_priv_key_pem, domain_full, person_cache, signing_priv_key_pem,
bold_reading, show_vote_posts): bold_reading, show_vote_posts,
languages_understood):
# media index will be updated # media index will be updated
update_index_list.append('tlmedia') update_index_list.append('tlmedia')
fitness_performance(inbox_start_time, server.fitness, fitness_performance(inbox_start_time, server.fitness,

View File

@ -543,7 +543,7 @@ def post_message_to_outbox(session, translate: {},
acct_dir(base_dir, post_to_nickname, domain) + '/.noVotes' acct_dir(base_dir, post_to_nickname, domain) + '/.noVotes'
if os.path.isfile(show_vote_file): if os.path.isfile(show_vote_file):
show_vote_posts = False show_vote_posts = False
languages_understood = []
if is_image_media(session, base_dir, http_prefix, if is_image_media(session, base_dir, http_prefix,
post_to_nickname, domain, post_to_nickname, domain,
message_json, message_json,
@ -555,7 +555,8 @@ def post_message_to_outbox(session, translate: {},
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
bold_reading, bold_reading,
show_vote_posts): show_vote_posts,
languages_understood):
inbox_update_index('tlmedia', base_dir, inbox_update_index('tlmedia', base_dir,
post_to_nickname + '@' + domain, post_to_nickname + '@' + domain,
saved_filename, debug) saved_filename, debug)

View File

@ -4212,7 +4212,8 @@ def is_image_media(session, base_dir: str, http_prefix: str,
domain_full: str, person_cache: {}, domain_full: str, person_cache: {},
signing_priv_key_pem: str, signing_priv_key_pem: str,
bold_reading: bool, bold_reading: bool,
show_vote_posts: bool) -> bool: show_vote_posts: bool,
languages_understood: []) -> bool:
"""Returns true if the given post has attached image media """Returns true if the given post has attached image media
""" """
if post_json_object['type'] == 'Announce': if post_json_object['type'] == 'Announce':
@ -4229,7 +4230,8 @@ def is_image_media(session, base_dir: str, http_prefix: str,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blocked_cache, bold_reading, blocked_cache, bold_reading,
show_vote_posts) show_vote_posts,
languages_understood)
if post_json_announce: if post_json_announce:
post_json_object = post_json_announce post_json_object = post_json_announce
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
@ -5597,7 +5599,8 @@ def download_announce(session, base_dir: str, http_prefix: str,
domain_full: str, person_cache: {}, domain_full: str, person_cache: {},
signing_priv_key_pem: str, signing_priv_key_pem: str,
blocked_cache: {}, bold_reading: bool, blocked_cache: {}, bold_reading: bool,
show_vote_posts: bool) -> {}: show_vote_posts: bool,
languages_understood: []) -> {}:
"""Download the post referenced by an announce """Download the post referenced by an announce
""" """
if not post_json_object.get('object'): if not post_json_object.get('object'):
@ -5726,7 +5729,8 @@ def download_announce(session, base_dir: str, http_prefix: str,
converted_json = \ converted_json = \
convert_video_to_note(base_dir, nickname, domain, convert_video_to_note(base_dir, nickname, domain,
system_language, system_language,
announced_json, blocked_cache) announced_json, blocked_cache,
languages_understood)
if converted_json: if converted_json:
announced_json = converted_json announced_json = converted_json
if not contains_statuses(announced_json['id']): if not contains_statuses(announced_json['id']):

View File

@ -13,13 +13,15 @@ from utils import get_nickname_from_actor
from utils import get_domain_from_actor from utils import get_domain_from_actor
from utils import remove_id_ending from utils import remove_id_ending
from utils import get_attributed_to from utils import get_attributed_to
from utils import get_content_from_post
from blocking import is_blocked from blocking import is_blocked
from filters import is_filtered from filters import is_filtered
def convert_video_to_note(base_dir: str, nickname: str, domain: str, def convert_video_to_note(base_dir: str, nickname: str, domain: str,
system_language: str, system_language: str,
post_json_object: {}, blocked_cache: {}) -> {}: post_json_object: {}, blocked_cache: {},
languages_understood: []) -> {}:
"""Converts a PeerTube Video ActivityPub(ish) object into """Converts a PeerTube Video ActivityPub(ish) object into
a Note, so that it can then be displayed in a timeline a Note, so that it can then be displayed in a timeline
""" """
@ -92,10 +94,9 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
system_language): system_language):
return None return None
content += '<p>' + post_json_object['license']['name'] + '</p>' content += '<p>' + post_json_object['license']['name'] + '</p>'
post_content = post_json_object['content'] post_content = \
if 'contentMap' in post_json_object: get_content_from_post(post_json_object, system_language,
if post_json_object['contentMap'].get(system_language): languages_understood, "content")
post_content = post_json_object['contentMap'][system_language]
content += post_content content += post_content
conversation_id = remove_id_ending(post_json_object['id']) conversation_id = remove_id_ending(post_json_object['id'])

View File

@ -2162,6 +2162,13 @@ def individual_post_as_html(signing_priv_key_pem: str,
if is_public_post(post_json_object): if is_public_post(post_json_object):
is_public_repeat = True is_public_repeat = True
person_url = local_actor_url(http_prefix, nickname, domain_full)
actor_json = \
get_person_from_cache(base_dir, person_url, person_cache)
languages_understood = []
if actor_json:
languages_understood = get_actor_languages_list(actor_json)
title_str = '' title_str = ''
gallery_str = '' gallery_str = ''
is_announced = False is_announced = False
@ -2185,7 +2192,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
domain_full, person_cache, domain_full, person_cache,
signing_priv_key_pem, signing_priv_key_pem,
blocked_cache, bold_reading, blocked_cache, bold_reading,
show_vote_posts) show_vote_posts,
languages_understood)
if not post_json_announce: if not post_json_announce:
# if the announce could not be downloaded then mark it as rejected # if the announce could not be downloaded then mark it as rejected
announced_post_id = remove_id_ending(post_json_object['id']) announced_post_id = remove_id_ending(post_json_object['id'])
@ -2515,13 +2523,6 @@ def individual_post_as_html(signing_priv_key_pem: str,
_log_post_timing(enable_timing_log, post_start_time, '14') _log_post_timing(enable_timing_log, post_start_time, '14')
person_url = local_actor_url(http_prefix, nickname, domain_full)
actor_json = \
get_person_from_cache(base_dir, person_url, person_cache)
languages_understood = []
if actor_json:
languages_understood = get_actor_languages_list(actor_json)
edits_filename = account_dir + box_name + '/' + edits_post_url edits_filename = account_dir + box_name + '/' + edits_post_url
edits_str = '' edits_str = ''
if os.path.isfile(edits_filename): if os.path.isfile(edits_filename):