__filename__ = "webapp_podcast.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.2.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 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_performers(podcast_properties: {}) -> str: """Returns html for performers of a podcast """ 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.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' podcast_title = newswire_item[0].replace('"', '') podcast_title = \ remove_html(html.unescape(urllib.parse.unquote_plus(podcast_title))) if podcast_title: podcast_str += \ '

\n' if newswire_item[4]: podcast_description = \ html.unescape(urllib.parse.unquote_plus(newswire_item[4])) podcast_description = remove_html(podcast_description) if podcast_description: remove_chars = ('Œ', 'â€', 'ğŸ', '�') for remchar in remove_chars: podcast_description = podcast_description.replace(remchar, '') 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' podcast_str += _html_podcast_performers(podcast_properties) podcast_str += '
\n' podcast_str += '
\n' podcast_str += html_footer() return podcast_str