Support for youtube channel within profile

merge-requests/30/head
Bob Mottram 2024-08-12 18:30:17 +01:00
parent bf8d941ae7
commit b91073ca7d
6 changed files with 162 additions and 8 deletions

View File

@ -81,6 +81,8 @@ from pgp import set_pgp_fingerprint
from pgp import get_pgp_fingerprint
from pronouns import get_pronouns
from pronouns import set_pronouns
from youtube import get_youtube
from youtube import set_youtube
from xmpp import get_xmpp_address
from xmpp import set_xmpp_address
from matrix import get_matrix_address
@ -1982,6 +1984,23 @@ def _profile_post_xmpp_address(actor_json: {}, fields: {},
return actor_changed
def _profile_post_youtube(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change youtube channel address
"""
current_youtube = get_youtube(actor_json)
if fields.get('youtubeChannel'):
if fields['youtubeChannel'] != current_youtube:
set_youtube(actor_json,
fields['youtubeChannel'])
actor_changed = True
else:
if current_youtube:
set_youtube(actor_json, '')
actor_changed = True
return actor_changed
def _profile_post_pronouns(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change pronouns
@ -2849,6 +2868,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
_profile_post_xmpp_address(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_youtube(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_pronouns(actor_json, fields,
actor_changed)

View File

@ -45,6 +45,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
@ -656,6 +657,7 @@ def show_person_options(self, calling_domain: str, path: str,
pgp_pub_key = None
pgp_fingerprint = None
pronouns = None
youtube = None
xmpp_address = None
matrix_address = None
blog_address = None
@ -685,6 +687,7 @@ def show_person_options(self, calling_domain: str, path: str,
website_url = get_website(actor_json, self.server.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)
@ -757,7 +760,8 @@ def show_person_options(self, calling_domain: str, path: str,
self.server.theme_name,
self.server.blocked_cache,
repo_url,
self.server.sites_unavailable)
self.server.sites_unavailable,
youtube)
if msg:
msg = msg.encode('utf-8')
msglen = len(msg)

9
pgp.py
View File

@ -27,6 +27,7 @@ from posts import get_person_box
from auth import create_basic_auth_header
from session import post_json
from pronouns import get_pronouns
from youtube import get_youtube
from xmpp import get_xmpp_address
from matrix import get_matrix_address
from briar import get_briar_address
@ -741,6 +742,9 @@ def actor_to_vcard(actor: {}, domain: str) -> str:
blog_address = get_blog_address(actor)
if blog_address:
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=Blog:' + blog_address + '\n'
youtube = get_youtube(actor)
if youtube:
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=YouTube:' + youtube + '\n'
xmpp_address = get_xmpp_address(actor)
if xmpp_address:
vcard_str += 'IMPP:xmpp:' + xmpp_address + '\n'
@ -813,6 +817,11 @@ def actor_to_vcard_xml(actor: {}, domain: str) -> str:
pronouns = get_pronouns(actor)
if pronouns:
vcard_str += ' <pronouns><text>' + pronouns + '</text></pronouns>\n'
youtube = get_youtube(actor)
if youtube:
vcard_str += ' <url>' + \
'<parameters><type><text>youtube</text></type></parameters>' + \
'<uri>' + youtube + '</uri></url>\n'
xmpp_address = get_xmpp_address(actor)
if xmpp_address:
vcard_str += ' <impp>' + \

View File

@ -170,7 +170,8 @@ def html_person_options(default_timeline: str,
theme: str,
blocked_cache: [],
repo_url: str,
sites_unavailable: []) -> str:
sites_unavailable: [],
youtube: str) -> str:
"""Show options for a person: view/follow/block/report
"""
options_link_str = ''
@ -436,6 +437,11 @@ def html_person_options(default_timeline: str,
' <p class="imText">Blog: <a href="' + \
remove_html(blog_address) + '">' + \
remove_html(blog_address) + '</a></p>\n'
if youtube:
options_str += \
' <p class="imText">YouTube' + \
': <a href="' + remove_html(youtube) + '">' + \
youtube + '</a></p>\n'
if tox_address:
options_str += \
' <p class="imText">Tox: ' + remove_html(tox_address) + '</p>\n'

View File

@ -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 = '<div class="container">\n'
donate_section += ' <center>\n'
@ -1170,6 +1172,10 @@ def html_profile(signing_priv_key_pem: str,
donate_section += \
'<p>' + translate['XMPP'] + ': <a href="xmpp:' + \
xmpp_address + '" tabindex="1">' + xmpp_address + '</a></p>\n'
if youtube:
donate_section += \
'<p>YouTube: <a href="' + \
youtube + '" tabindex="1">' + youtube + '</a></p>\n'
if matrix_address:
donate_section += \
'<p>' + translate['Matrix'] + ': ' + matrix_address + '</p>\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 += \

101
youtube.py 100644
View File

@ -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)