\n'
return podcast_str
def _html_podcast_performers(podcast_properties: {}) -> str:
"""Returns html for performers of a podcast
"""
if not podcast_properties:
return ''
key = 'persons'
if not podcast_properties.get(key):
return ''
if not isinstance(podcast_properties[key], list):
return ''
# list of performers
podcast_str = '
\n'
podcast_str += '
\n'
podcast_str += '
\n'
for performer in podcast_properties[key]:
if not performer.get('text'):
continue
performer_name = \
'' + performer['text'] + ''
performer_title = performer_name
if performer.get('role'):
performer_title += \
' (' + \
performer['role'] + ')'
if performer.get('group'):
performer_title += ', ' + performer['group'] + ''
performer_title = remove_html(performer_title)
performer_url = ''
if performer.get('href'):
performer_url = remove_html(performer['href'])
performer_img = ''
if performer.get('img'):
performer_img = performer['img']
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'
ctr = 1
for performer in podcast_properties['soundbites']:
if not performer.get('startTime'):
continue
if not performer['startTime'].isdigit():
continue
if not performer.get('duration'):
continue
if not performer['duration'].isdigit():
continue
end_time = str(float(performer['startTime']) +
float(performer['duration']))
podcast_str += '
\n'
audio_extension = None
if path_is_audio(link_url):
if '.mp3' in link_url:
audio_extension = 'mpeg'
elif '.opus' in link_url:
audio_extension = 'opus'
elif '.spx' in link_url:
audio_extension = 'spx'
elif '.flac' in link_url:
audio_extension = 'flac'
elif '.wav' in link_url:
audio_extension = 'wav'
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' + \
' \n \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' + \
" \n \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 \n \n'
podcast_title = \
remove_html(html.unescape(urllib.parse.unquote_plus(newswire_item[0])))
if podcast_title:
# if this is an "explicit" podcast then add a corresponding icon
# to the title
if 'explicit' in podcast_properties:
if podcast_properties['explicit'] is True:
podcast_title += ' 🔞'
podcast_str += \
'\n'
if podcast_properties.get('author'):
author = podcast_properties['author']
podcast_str += '
' + author + '
\n'
transcripts = _html_podcast_transcripts(podcast_properties, translate)
if transcripts:
podcast_str += '
' + transcripts + '
\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'
if podcast_properties.get('duration'):
if podcast_properties['duration'].isdigit():
podcast_str += \
'
\n'
extra_links: list[str] = []
if len(newswire_item) > 10:
extra_links = newswire_item[10]
if extra_links:
links_text = ''
for link_str in extra_links:
link_str = remove_html(link_str)
if not resembles_url(link_str):
continue
if link_str in podcast_str:
continue
if not links_text:
links_text = '
\n'
link_url = link_str
# check that the link is not too long so that it does not
# mess up display on mobile
if len(link_str) > MAX_LINK_LENGTH:
link_str = link_str[:MAX_LINK_LENGTH-1]
links_text += \
'' + link_str + ' \n'
if links_text:
links_text += '
\n'
podcast_str += links_text
if podcast_properties['categories']:
tags_str = ''
for tag in podcast_properties['categories']:
tag = tag.replace('#', '')
if not tag:
continue
tag_link = '/users/' + nickname + '/tags/' + tag
tags_str += \
'#' + \
'' + tag + '' + \
' '
podcast_str += '