Blog: ' + \ remove_html(blog_address) + '
\n' + if youtube: + options_str += \ + 'YouTube' + \ + ': ' + \ + youtube + '
\n' if tox_address: options_str += \ 'Tox: ' + remove_html(tox_address) + '
\n' diff --git a/webapp_profile.py b/webapp_profile.py index 39a3dc20b..3f7f2e593 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -67,6 +67,7 @@ from donate import get_donation_url from donate import get_website from donate import get_gemini_link from pronouns import get_pronouns +from youtube import get_youtube from xmpp import get_xmpp_address from matrix import get_matrix_address from ssb import get_ssb_address @@ -1095,6 +1096,7 @@ def html_profile(signing_priv_key_pem: str, pgp_fingerprint = get_pgp_fingerprint(profile_json) email_address = get_email_address(profile_json) pronouns = get_pronouns(profile_json) + youtube = get_youtube(profile_json) xmpp_address = get_xmpp_address(profile_json) matrix_address = get_matrix_address(profile_json) ssb_address = get_ssb_address(profile_json) @@ -1103,9 +1105,9 @@ def html_profile(signing_priv_key_pem: str, cwtch_address = get_cwtch_address(profile_json) verified_site_checkmark = '✔' premium = is_premium_account(base_dir, nickname, domain) - if donate_url or website_url or repo_url or pronouns or xmpp_address or \ - matrix_address or ssb_address or tox_address or briar_address or \ - cwtch_address or pgp_pub_key or enigma_pub_key or \ + if donate_url or website_url or repo_url or pronouns or youtube or \ + xmpp_address or matrix_address or ssb_address or tox_address or \ + briar_address or cwtch_address or pgp_pub_key or enigma_pub_key or \ pgp_fingerprint or email_address: donate_section = '' + translate['XMPP'] + ': ' + xmpp_address + '
\n' + if youtube: + donate_section += \ + 'YouTube: ' + youtube + '
\n' if matrix_address: donate_section += \ '' + translate['Matrix'] + ': ' + matrix_address + '
\n' @@ -2714,7 +2720,8 @@ def _html_edit_profile_contact_info(email_address: str, tox_address: str, briar_address: str, cwtch_address: str, - translate: {}) -> str: + translate: {}, + youtube: str) -> str: """Contact Information section of edit profile screen """ edit_profile_form = begin_edit_section(translate['Contact Details']) @@ -2730,6 +2737,8 @@ def _html_edit_profile_contact_info(email_address: str, briar_address) edit_profile_form += edit_text_field('Cwtch', 'cwtchAddress', cwtch_address) + edit_profile_form += edit_text_field('YouTube', 'youtubeChannel', + youtube) edit_profile_form += end_edit_section() return edit_profile_form @@ -3175,7 +3184,7 @@ def html_edit_profile(server, translate: {}, blogs_instance_str = news_instance_str = moved_to = twitter_str = '' bio_str = donate_url = website_url = gemini_link = '' email_address = featured_hashtags = pgp_pub_key = enigma_pub_key = '' - pgp_fingerprint = pronouns = xmpp_address = matrix_address = '' + pgp_fingerprint = pronouns = youtube = xmpp_address = matrix_address = '' ssb_address = blog_address = tox_address = '' cwtch_address = briar_address = '' manually_approves_followers = reject_spam_actors = '' @@ -3189,6 +3198,7 @@ def html_edit_profile(server, translate: {}, website_url = get_website(actor_json, translate) gemini_link = get_gemini_link(actor_json) pronouns = get_pronouns(actor_json) + youtube = get_youtube(actor_json) xmpp_address = get_xmpp_address(actor_json) matrix_address = get_matrix_address(actor_json) ssb_address = get_ssb_address(actor_json) @@ -3407,7 +3417,8 @@ def html_edit_profile(server, translate: {}, xmpp_address, matrix_address, ssb_address, tox_address, briar_address, - cwtch_address, translate) + cwtch_address, translate, + youtube) # notification settings edit_profile_form += \ diff --git a/youtube.py b/youtube.py new file mode 100644 index 000000000..26649325c --- /dev/null +++ b/youtube.py @@ -0,0 +1,101 @@ +__filename__ = "youtube.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.5.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@libreserver.org" +__status__ = "Production" +__module_group__ = "Profile Metadata" + + +from utils import get_attachment_property_value +from utils import remove_html +from utils import string_contains + +youtube_fieldnames = ['youtube'] + + +def get_youtube(actor_json: {}) -> str: + """Returns youtube for the given actor + """ + if not actor_json.get('attachment'): + return '' + if not isinstance(actor_json['attachment'], list): + return '' + for property_value in actor_json['attachment']: + name_value = None + if property_value.get('name'): + name_value = property_value['name'].lower() + elif property_value.get('schema:name'): + name_value = property_value['schema:name'].lower() + if not name_value: + continue + if not string_contains(name_value, youtube_fieldnames): + continue + if not property_value.get('type'): + continue + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + if not property_value['type'].endswith('PropertyValue'): + continue + youtube_text = property_value[prop_value_name] + return remove_html(youtube_text) + return '' + + +def set_youtube(actor_json: {}, youtube: str) -> None: + """Sets youtube for the given actor + """ + if not actor_json.get('attachment'): + actor_json['attachment'] = [] + + # remove any existing value + property_found = None + for property_value in actor_json['attachment']: + name_value = None + if property_value.get('name'): + name_value = property_value['name'].lower() + elif property_value.get('schema:name'): + name_value = property_value['schema:name'].lower() + if not name_value: + continue + if not property_value.get('type'): + continue + if not string_contains(name_value, youtube_fieldnames): + continue + property_found = property_value + break + + if property_found: + actor_json['attachment'].remove(property_found) + + for property_value in actor_json['attachment']: + name_value = None + if property_value.get('name'): + name_value = property_value['name'] + elif property_value.get('schema:name'): + name_value = property_value['schema:name'] + if not name_value: + continue + if not property_value.get('type'): + continue + name_value = name_value.lower() + if not string_contains(name_value, youtube_fieldnames): + continue + if not property_value['type'].endswith('PropertyValue'): + continue + prop_value_name, _ = \ + get_attachment_property_value(property_value) + if not prop_value_name: + continue + property_value[prop_value_name] = remove_html(youtube) + return + + new_youtube = { + "type": "PropertyValue", + "name": "YouTube", + "value": remove_html(youtube) + } + actor_json['attachment'].append(new_youtube)