__filename__ = "webapp_podcast.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.3.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Web Interface Columns" import os import html import urllib.parse from shutil import copyfile from utils import get_config_param from utils import remove_html from media import path_is_audio from content import safe_web_text from webapp_utils import get_broken_link_substitute from webapp_utils import html_header_with_external_style from webapp_utils import html_footer from webapp_utils import html_keyboard_navigation def _html_podcast_social_interactions(podcast_properties: {}, translate: {}, nickname: str) -> str: """Returns html for social interactions with a podcast """ if not podcast_properties: return '' if not podcast_properties.get('socialInteract'): return '' if not podcast_properties['socialInteract'].get('text'): return '' episode_post_url = podcast_properties['socialInteract']['text'] actor_str = '' if podcast_properties['socialInteract'].get('accountId'): actor_handle = podcast_properties['socialInteract']['accountId'] if actor_handle.startswith('@'): actor_handle = actor_handle[1:] actor_str = '?actor=' + actor_handle podcast_str = \ '
\n' + \ ' 💬 ' + \ translate['Leave a comment'] + '\n' + \ ' ' + \ translate['View comments'] + '\n' + \ '
\n' return podcast_str def _html_podcast_performers(podcast_properties: {}) -> str: """Returns html for performers of a podcast """ if not podcast_properties: return '' if not podcast_properties.get('persons'): return '' # list of performers podcast_str = '
\n' podcast_str += '
\n' podcast_str += '\n' podcast_str += '
\n' return podcast_str def _html_podcast_soundbites(link_url: str, extension: str, podcast_properties: {}, translate: {}) -> str: """Returns html for podcast soundbites """ if not podcast_properties: return '' if not podcast_properties.get('soundbites'): return '' podcast_str = '
\n' podcast_str += '
\n' podcast_str += '\n' podcast_str += '
\n' return podcast_str def html_podcast_episode(css_cache: {}, translate: {}, base_dir: str, nickname: str, domain: str, newswire_item: [], theme: str, default_timeline: str, text_mode_banner: str, access_keys: {}) -> str: """Returns html for a podcast episode, giebn an item from the newswire """ css_filename = base_dir + '/epicyon-podcast.css' if os.path.isfile(base_dir + '/podcast.css'): css_filename = base_dir + '/podcast.css' if os.path.isfile(base_dir + '/accounts/podcast-background-custom.jpg'): if not os.path.isfile(base_dir + '/accounts/podcast-background.jpg'): copyfile(base_dir + '/accounts/podcast-background.jpg', base_dir + '/accounts/podcast-background.jpg') instance_title = get_config_param(base_dir, 'instanceTitle') podcast_str = \ html_header_with_external_style(css_filename, instance_title, None) podcast_properties = newswire_item[8] image_url = '' image_src = 'src' if podcast_properties.get('images'): if podcast_properties['images'].get('srcset'): image_url = podcast_properties['images']['srcset'] image_src = 'srcset' if not image_url and podcast_properties.get('image'): image_url = podcast_properties['image'] link_url = newswire_item[1] podcast_str += html_keyboard_navigation(text_mode_banner, {}, {}) podcast_str += '

\n' podcast_str += '
\n' podcast_str += '
\n' podcast_str += '
\n' podcast_str += ' \n' if image_src == 'srcset': podcast_str += ' \n' else: podcast_str += ' \n' podcast_str += '
\n' podcast_str += '
\n' podcast_str += '
\n' audio_extension = None if path_is_audio(link_url): if '.mp3' in link_url: audio_extension = 'mpeg' else: audio_extension = 'ogg' else: if podcast_properties.get('linkMimeType'): if 'audio' in podcast_properties['linkMimeType']: audio_extension = \ podcast_properties['linkMimeType'].split('/')[1] # show widgets for soundbites if audio_extension: podcast_str += _html_podcast_soundbites(link_url, audio_extension, podcast_properties, translate) # podcast player widget podcast_str += \ ' \n' elif podcast_properties.get('linkMimeType'): if '/youtube' in podcast_properties['linkMimeType']: url = link_url.replace('/watch?v=', '/embed/') if '&' in url: url = url.split('&')[0] if '?utm_' in url: url = url.split('?utm_')[0] podcast_str += \ " \n" elif 'video' in podcast_properties['linkMimeType']: video_mime_type = podcast_properties['linkMimeType'] video_msg = 'Your browser does not support the video element.' podcast_str += \ '
\n' + \ ' \n
\n' podcast_title = \ remove_html(html.unescape(urllib.parse.unquote_plus(newswire_item[0]))) if podcast_title: podcast_str += \ '

\n' if newswire_item[4]: podcast_description = \ html.unescape(urllib.parse.unquote_plus(newswire_item[4])) podcast_description = safe_web_text(podcast_description) if podcast_description: podcast_str += '

' + podcast_description + '

\n' # donate button if podcast_properties.get('funding'): if podcast_properties['funding'].get('url'): donate_url = podcast_properties['funding']['url'] podcast_str += \ '

\n' if podcast_properties['categories']: podcast_str += '

' tags_str = '' for tag in podcast_properties['categories']: tag_link = '/users/' + nickname + '/tags/' + tag.replace('#', '') tags_str += '' + tag + ' ' podcast_str += tags_str.strip() + '

\n' podcast_str += _html_podcast_performers(podcast_properties) podcast_str += \ _html_podcast_social_interactions(podcast_properties, translate, nickname) podcast_str += '
\n' podcast_str += '
\n' podcast_str += html_footer() return podcast_str