Add music site url option to personal profile

main
Bob Mottram 2024-08-15 15:30:35 +01:00
parent a951635e48
commit dd6ea5b332
34 changed files with 228 additions and 36 deletions

View File

@ -83,6 +83,8 @@ from pronouns import get_pronouns
from pronouns import set_pronouns
from discord import get_discord
from discord import set_discord
from music import get_music_site_url
from music import set_music_site_url
from youtube import get_youtube
from youtube import set_youtube
from pixelfed import get_pixelfed
@ -2007,6 +2009,23 @@ def _profile_post_youtube(actor_json: {}, fields: {},
return actor_changed
def _profile_post_music_site_url(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change music site url address
"""
current_music = get_music_site_url(actor_json)
if fields.get('musicSiteUrl'):
if fields['musicSiteUrl'] != current_music:
set_music_site_url(actor_json,
fields['musicSiteUrl'])
actor_changed = True
else:
if current_music:
set_music_site_url(actor_json, '')
actor_changed = True
return actor_changed
def _profile_post_discord(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change discord channel address
@ -2937,6 +2956,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
_profile_post_youtube(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_music_site_url(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_peertube(actor_json, fields,
actor_changed)

View File

@ -46,6 +46,7 @@ from donate import get_website
from donate import get_gemini_link
from pronouns import get_pronouns
from discord import get_discord
from music import get_music_site_url
from youtube import get_youtube
from pixelfed import get_pixelfed
from peertube import get_peertube
@ -662,6 +663,7 @@ def show_person_options(self, calling_domain: str, path: str,
pronouns = None
pixelfed = None
discord = None
music_site_url = None
youtube = None
peertube = None
xmpp_address = None
@ -695,6 +697,7 @@ def show_person_options(self, calling_domain: str, path: str,
pronouns = get_pronouns(actor_json)
pixelfed = get_pixelfed(actor_json)
discord = get_discord(actor_json)
music_site_url = get_music_site_url(actor_json)
youtube = get_youtube(actor_json)
peertube = get_peertube(actor_json)
xmpp_address = get_xmpp_address(actor_json)
@ -771,7 +774,7 @@ def show_person_options(self, calling_domain: str, path: str,
repo_url,
self.server.sites_unavailable,
youtube, peertube, pixelfed,
discord)
discord, music_site_url)
if msg:
msg = msg.encode('utf-8')
msglen = len(msg)

104
music.py 100644
View File

@ -0,0 +1,104 @@
__filename__ = "music.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
from utils import resembles_url
music_fieldnames = ('music')
music_sites = ('bandcamp.com', 'soundcloud.com')
def get_music_site_url(actor_json: {}) -> str:
"""Returns music site url 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']:
if not property_value.get('type'):
continue
if not isinstance(property_value['type'], str):
continue
if not property_value['type'].endswith('PropertyValue'):
continue
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
music_text = remove_html(property_value[prop_value_name])
if not string_contains(music_text, music_sites):
continue
if not resembles_url(music_text):
continue
return music_text
return ''
def set_music_site_url(actor_json: {}, music_site_url: str) -> None:
"""Sets music site url for the given actor
"""
music_site_url = remove_html(music_site_url)
if not resembles_url(music_site_url):
return
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, music_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, music_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(music_site_url)
return
new_music = {
"type": "PropertyValue",
"name": "Music",
"value": remove_html(music_site_url)
}
actor_json['attachment'].append(new_music)

10
pgp.py
View File

@ -29,6 +29,7 @@ from session import post_json
from pronouns import get_pronouns
from pixelfed import get_pixelfed
from discord import get_discord
from music import get_music_site_url
from youtube import get_youtube
from peertube import get_peertube
from xmpp import get_xmpp_address
@ -753,6 +754,10 @@ def actor_to_vcard(actor: {}, domain: str) -> str:
pixelfed = get_pixelfed(actor)
if pixelfed:
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=Pixelfed:' + pixelfed + '\n'
music_site_url = get_music_site_url(actor)
if music_site_url:
vcard_str += \
'SOCIALPROFILE;SERVICE-TYPE=Music:' + music_site_url + '\n'
youtube = get_youtube(actor)
if youtube:
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=YouTube:' + youtube + '\n'
@ -846,6 +851,11 @@ def actor_to_vcard_xml(actor: {}, domain: str) -> str:
vcard_str += ' <url>' + \
'<parameters><type><text>youtube</text></type></parameters>' + \
'<uri>' + youtube + '</uri></url>\n'
music_site_url = get_music_site_url(actor)
if music_site_url:
vcard_str += ' <url>' + \
'<parameters><type><text>music</text></type></parameters>' + \
'<uri>' + music_site_url + '</uri></url>\n'
peertube = get_peertube(actor)
if peertube:
vcard_str += ' <url>' + \

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "لا تظهر المشاركات التي تمت مشاهدتها بالفعل",
"Watermark image": "صورة العلامة المائية",
"Apply a watermark to uploaded images": "إضافة علامة مائية على الصور التي تم تحميلها",
"Pronouns": "الضمائر"
"Pronouns": "الضمائر",
"Music": "موسيقى"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "ইতিমধ্যে দেখা পোস্ট দেখাবেন না",
"Watermark image": "ওয়াটারমার্ক ইমেজ",
"Apply a watermark to uploaded images": "আপলোড করা ছবিগুলিতে একটি জলছাপ প্রয়োগ করুন",
"Pronouns": "সর্বনাম"
"Pronouns": "সর্বনাম",
"Music": "সঙ্গীত"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "No mostris les publicacions ja vistes",
"Watermark image": "Imatge de filigrana",
"Apply a watermark to uploaded images": "Apliqueu una marca d'aigua a les imatges penjades",
"Pronouns": "Els pronoms"
"Pronouns": "Els pronoms",
"Music": "Música"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Peidiwch â dangos postiadau a welwyd eisoes",
"Watermark image": "Delwedd dyfrnod",
"Apply a watermark to uploaded images": "Cymhwyso dyfrnod i ddelweddau sydd wedi'u llwytho i fyny",
"Pronouns": "Rhagenwau"
"Pronouns": "Rhagenwau",
"Music": "Cerddoriaeth"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Bereits gesehene Beiträge nicht anzeigen",
"Watermark image": "Wasserzeichenbild",
"Apply a watermark to uploaded images": "Hochgeladenen Bildern ein Wasserzeichen hinzufügen",
"Pronouns": "Pronomen"
"Pronouns": "Pronomen",
"Music": "Musik"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Να μην εμφανίζονται οι αναρτήσεις που έχετε ήδη δει",
"Watermark image": "Εικόνα υδατογραφήματος",
"Apply a watermark to uploaded images": "Εφαρμόστε ένα υδατογράφημα στις μεταφορτωμένες εικόνες",
"Pronouns": "Αντωνυμίες"
"Pronouns": "Αντωνυμίες",
"Music": "Μουσική"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Don't show already seen posts",
"Watermark image": "Watermark image",
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images",
"Pronouns": "Pronouns"
"Pronouns": "Pronouns",
"Music": "Music"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "No mostrar publicaciones ya vistas",
"Watermark image": "Imagen de marca de agua",
"Apply a watermark to uploaded images": "Aplicar una marca de agua a las imágenes cargadas",
"Pronouns": "Pronombres"
"Pronouns": "Pronombres",
"Music": "Música"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "پست های قبلا دیده شده را نشان ندهید",
"Watermark image": "تصویر واترمارک",
"Apply a watermark to uploaded images": "اعمال واترمارک روی تصاویر آپلود شده",
"Pronouns": "ضمایر"
"Pronouns": "ضمایر",
"Music": "موسیقی"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Älä näytä jo nähtyjä viestejä",
"Watermark image": "Vesileiman kuva",
"Apply a watermark to uploaded images": "Lisää ladattuihin kuviin vesileima",
"Pronouns": "Pronominit"
"Pronouns": "Pronominit",
"Music": "Musiikki"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Ne pas afficher les messages déjà vus",
"Watermark image": "Image en filigrane",
"Apply a watermark to uploaded images": "Appliquer un filigrane aux images téléchargées",
"Pronouns": "Pronoms"
"Pronouns": "Pronoms",
"Music": "Musique"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Ná taispeáin postálacha atá feicthe cheana féin",
"Watermark image": "Íomhá comhartha uisce",
"Apply a watermark to uploaded images": "Cuir comhartha uisce i bhfeidhm ar íomhánna uaslódáilte",
"Pronouns": "Forainmneacha"
"Pronouns": "Forainmneacha",
"Music": "Ceol"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "אל תראה פוסטים שכבר נראו",
"Watermark image": "תמונת סימן מים",
"Apply a watermark to uploaded images": "החל סימן מים על תמונות שהועלו",
"Pronouns": "כינויים"
"Pronouns": "כינויים",
"Music": "מוּסִיקָה"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "पहले से देखी गई पोस्ट न दिखाएं",
"Watermark image": "वॉटरमार्क छवि",
"Apply a watermark to uploaded images": "अपलोड की गई छवियों पर वॉटरमार्क लागू करें",
"Pronouns": "सर्वनाम"
"Pronouns": "सर्वनाम",
"Music": "संगीत"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Non mostrare i post già visti",
"Watermark image": "Immagine filigrana",
"Apply a watermark to uploaded images": "Applicare una filigrana alle immagini caricate",
"Pronouns": "Pronomi"
"Pronouns": "Pronomi",
"Music": "Musica"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "すでに閲覧した投稿を表示しない",
"Watermark image": "透かし画像",
"Apply a watermark to uploaded images": "アップロードした画像に透かしを適用する",
"Pronouns": "代名詞"
"Pronouns": "代名詞",
"Music": "音楽"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "이미 본 게시물을 표시하지 않음",
"Watermark image": "워터마크 이미지",
"Apply a watermark to uploaded images": "업로드한 이미지에 워터마크를 적용합니다",
"Pronouns": "대명사"
"Pronouns": "대명사",
"Music": "음악"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Mesajên ku berê hatine dîtin nîşan nedin",
"Watermark image": "Wêneyê Watermark",
"Apply a watermark to uploaded images": "Li ser wêneyên barkirî ava nîşanek bicîh bikin",
"Pronouns": "Cînavk"
"Pronouns": "Cînavk",
"Music": "Mûzîk"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Toon geen reeds bekeken berichten",
"Watermark image": "Watermerk afbeelding",
"Apply a watermark to uploaded images": "Een watermerk toepassen op geüploade afbeeldingen",
"Pronouns": "Voornaamwoorden"
"Pronouns": "Voornaamwoorden",
"Music": "Muziek"
}

View File

@ -693,5 +693,6 @@
"Don't show already seen posts": "Don't show already seen posts",
"Watermark image": "Watermark image",
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images",
"Pronouns": "Pronouns"
"Pronouns": "Pronouns",
"Music": "Music"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Nie pokazuj już wyświetlonych postów",
"Watermark image": "Obraz znaku wodnego",
"Apply a watermark to uploaded images": "Zastosuj znak wodny do przesłanych obrazów",
"Pronouns": "Zaimki"
"Pronouns": "Zaimki",
"Music": "Muzyka"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Não mostrar posts já vistos",
"Watermark image": "Imagem de marca de água",
"Apply a watermark to uploaded images": "Aplicar uma marca de água nas imagens enviadas",
"Pronouns": "Pronomes"
"Pronouns": "Pronomes",
"Music": "Música"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Не показывать уже просмотренные публикации",
"Watermark image": "Изображение водяного знака",
"Apply a watermark to uploaded images": "Накладывать водяной знак на загружаемые изображения",
"Pronouns": "Местоимения"
"Pronouns": "Местоимения",
"Music": "Музыка"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Usionyeshe machapisho ambayo tayari yameonekana",
"Watermark image": "Picha ya watermark",
"Apply a watermark to uploaded images": "Tumia watermark kwa picha zilizopakiwa",
"Pronouns": "Viwakilishi"
"Pronouns": "Viwakilishi",
"Music": "Muziki"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Daha önce görülen gönderileri gösterme",
"Watermark image": "Filigran resmi",
"Apply a watermark to uploaded images": "Yüklenen görsellere filigran uygulayın",
"Pronouns": "Zamirler"
"Pronouns": "Zamirler",
"Music": "Müzik"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "Не показувати вже переглянуті публікації",
"Watermark image": "Зображення водяного знака",
"Apply a watermark to uploaded images": "Застосування водяного знака до завантажених зображень",
"Pronouns": "Займенники"
"Pronouns": "Займенники",
"Music": "музика"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "צי ניט ווייַזן שוין געזען אַרטיקלען",
"Watermark image": "וואָטערמאַרק בילד",
"Apply a watermark to uploaded images": "צולייגן אַ וואָטערמאַרק צו ופּלאָאַדעד בילדער",
"Pronouns": "פּראָנאָונס"
"Pronouns": "פּראָנאָונס",
"Music": "מוזיק"
}

View File

@ -697,5 +697,6 @@
"Don't show already seen posts": "不显示已经看过的帖子",
"Watermark image": "水印图像",
"Apply a watermark to uploaded images": "将水印应用于上传的图像",
"Pronouns": "代词"
"Pronouns": "代词",
"Music": "音乐"
}

View File

@ -173,7 +173,8 @@ def html_person_options(default_timeline: str,
sites_unavailable: [],
youtube: str, peertube: str,
pixelfed: str,
discord: str) -> str:
discord: str,
music_site_url: str) -> str:
"""Show options for a person: view/follow/block/report
"""
options_link_str = ''
@ -448,6 +449,11 @@ def html_person_options(default_timeline: str,
' <p class="imText">Discord' + \
': <a href="' + remove_html(discord) + '">' + \
discord + '</a></p>\n'
if music_site_url:
options_str += \
' <p class="imText">' + translate['Music'] + \
': <a href="' + remove_html(music_site_url) + '">' + \
music_site_url + '</a></p>\n'
if youtube:
options_str += \
' <p class="imText">YouTube' + \

View File

@ -69,6 +69,7 @@ from donate import get_gemini_link
from pronouns import get_pronouns
from pixelfed import get_pixelfed
from discord import get_discord
from music import get_music_site_url
from youtube import get_youtube
from peertube import get_peertube
from xmpp import get_xmpp_address
@ -331,6 +332,7 @@ def html_profile_after_search(authorized: bool,
pronouns = get_pronouns(profile_json)
discord = get_discord(profile_json)
music_site_url = get_music_site_url(profile_json)
youtube = get_youtube(profile_json)
peertube = get_peertube(profile_json)
pixelfed = get_pixelfed(profile_json)
@ -459,7 +461,7 @@ def html_profile_after_search(authorized: bool,
person_url, no_of_books,
birth_date,
youtube, peertube, pixelfed,
discord)
discord, music_site_url)
domain_full = get_full_domain(domain, port)
@ -831,7 +833,8 @@ def _get_profile_header_after_search(base_dir: str,
youtube: str,
peertube: str,
pixelfed: str,
discord: str) -> str:
discord: str,
music_site_url: str) -> str:
"""The header of a searched for handle, containing background
image and avatar
"""
@ -956,6 +959,9 @@ def _get_profile_header_after_search(base_dir: str,
if discord:
html_str += ' <p>Discord: <a href="' + discord + '">' + \
discord + '</a></p>\n'
if music_site_url:
html_str += ' <p>' + translate['Music'] + ': <a href="' + \
music_site_url + '">' + music_site_url + '</a></p>\n'
if repo_url:
html_str += ' <p>💻 <a href="' + repo_url + '">' + \
repo_url + '</a></p>\n'
@ -1124,6 +1130,7 @@ def html_profile(signing_priv_key_pem: str,
pronouns = get_pronouns(profile_json)
pixelfed = get_pixelfed(profile_json)
discord = get_discord(profile_json)
music_site_url = get_music_site_url(profile_json)
youtube = get_youtube(profile_json)
peertube = get_peertube(profile_json)
xmpp_address = get_xmpp_address(profile_json)
@ -1135,7 +1142,8 @@ def html_profile(signing_priv_key_pem: str,
verified_site_checkmark = ''
premium = is_premium_account(base_dir, nickname, domain)
if donate_url or website_url or repo_url or pronouns or discord or \
youtube or peertube or pixelfed or xmpp_address or matrix_address or \
music_site_url or youtube or peertube or pixelfed 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'
@ -1209,6 +1217,11 @@ def html_profile(signing_priv_key_pem: str,
donate_section += \
'<p>Discord: <a href="' + \
discord + '" tabindex="1">' + discord + '</a></p>\n'
if music_site_url:
donate_section += \
'<p>' + translate['Music'] + ': <a href="' + \
music_site_url + '" tabindex="1">' + \
music_site_url + '</a></p>\n'
if youtube:
donate_section += \
'<p>YouTube: <a href="' + \
@ -2765,7 +2778,8 @@ def _html_edit_profile_contact_info(email_address: str,
youtube: str,
peertube: str,
pixelfed: str,
discord: str) -> str:
discord: str,
music_site_url: str) -> str:
"""Contact Information section of edit profile screen
"""
edit_profile_form = begin_edit_section(translate['Contact Details'])
@ -2789,6 +2803,8 @@ def _html_edit_profile_contact_info(email_address: str,
pixelfed)
edit_profile_form += edit_text_field('Discord', 'discordChannel',
discord)
edit_profile_form += edit_text_field(translate['Music'],
'musicSiteUrl', music_site_url)
edit_profile_form += end_edit_section()
return edit_profile_form
@ -3238,7 +3254,8 @@ def html_edit_profile(server, translate: {},
email_address = featured_hashtags = pgp_pub_key = enigma_pub_key = ''
pgp_fingerprint = pronouns = peertube = youtube = pixelfed = ''
ssb_address = blog_address = matrix_address = tox_address = ''
cwtch_address = briar_address = xmpp_address = discord = ''
cwtch_address = briar_address = xmpp_address = ''
discord = music_site_url = ''
manually_approves_followers = reject_spam_actors = ''
actor_json = load_json(actor_filename)
@ -3252,6 +3269,7 @@ def html_edit_profile(server, translate: {},
pronouns = get_pronouns(actor_json)
pixelfed = get_pixelfed(actor_json)
discord = get_discord(actor_json)
music_site_url = get_music_site_url(actor_json)
youtube = get_youtube(actor_json)
peertube = get_peertube(actor_json)
xmpp_address = get_xmpp_address(actor_json)
@ -3474,7 +3492,7 @@ def html_edit_profile(server, translate: {},
briar_address,
cwtch_address, translate,
youtube, peertube, pixelfed,
discord)
discord, music_site_url)
# notification settings
edit_profile_form += \