__filename__ = "webapp_media.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.3.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Timeline" import os from utils import valid_url_prefix def load_peertube_instances(base_dir: str, peertube_instances: []) -> None: """Loads peertube instances from file into the given list """ peertube_list = None peertube_instances_filename = base_dir + '/accounts/peertube.txt' if os.path.isfile(peertube_instances_filename): with open(peertube_instances_filename, 'r', encoding='utf-8') as fp_inst: peertube_str = fp_inst.read() if peertube_str: peertube_str = peertube_str.replace('\r', '') peertube_list = peertube_str.split('\n') if not peertube_list: return for url in peertube_list: if url in peertube_instances: continue peertube_instances.append(url) def _add_embedded_video_from_sites(translate: {}, content: str, peertube_instances: [], width: int, height: int, domain: str) -> str: """Adds embedded videos """ if 'www.tiktok.com/@' in content and \ 'www.tiktok.com/embed.js' not in content: url = content.split('www.tiktok.com/@')[1] if '<' in url: url = url.split('<')[0] if '/video/' in url: channel = url.split('/video/')[0] video_id = url.split('/video/')[1] if '?' in video_id: video_id = video_id.split('?')[0] content += \ '
\n' + \ '\n' + \ '\n\n' + \ '@' + channel + '\n' + \ ' \n