diff --git a/webapp_podcast.py b/webapp_podcast.py index 3c08e97d9..2f53abf22 100644 --- a/webapp_podcast.py +++ b/webapp_podcast.py @@ -43,81 +43,91 @@ def _html_podcast_chapters(link_url: str, """ if not podcast_properties: return '' - key = 'chapters' + key: str = 'chapters' if not podcast_properties.get(key): return '' if not isinstance(podcast_properties[key], dict): return '' + chapters_url = '' if podcast_properties[key].get('url'): - url_str = get_url_from_post(podcast_properties[key]['url']) - chapters_url = remove_html(url_str) + url_str: str = get_url_from_post(podcast_properties[key]['url']) + if url_str: + chapters_url: str = remove_html(url_str) elif podcast_properties[key].get('uri'): - chapters_url = podcast_properties[key]['uri'] + if isinstance(podcast_properties[key]['uri'], str): + chapters_url: str = podcast_properties[key]['uri'] else: return '' + if not chapters_url: + return '' html_str: str = '' - if podcast_properties[key].get('type'): - url_type = podcast_properties[key]['type'] + if not podcast_properties[key].get('type'): + return '' + if not isinstance(podcast_properties[key]['type'], str): + return '' + url_type: str = podcast_properties[key]['type'] - curr_session = session - if chapters_url.endswith('.onion'): - curr_session = session_onion - elif chapters_url.endswith('.i2p'): - curr_session = session_i2p - elif is_yggdrasil_url(chapters_url): - curr_session = session_yggdrasil + curr_session = session + if chapters_url.endswith('.onion'): + curr_session = session_onion + elif chapters_url.endswith('.i2p'): + curr_session = session_i2p + elif is_yggdrasil_url(chapters_url): + curr_session = session_yggdrasil - as_header = { - 'Accept': url_type - } + if 'json' not in url_type: + return html_str - if 'json' in url_type: - chapters_json = \ - get_json(None, curr_session, chapters_url, - as_header, None, debug, mitm_servers, __version__, - http_prefix, domain) - if not get_json_valid(chapters_json): - return '' - if not chapters_json.get('chapters'): - return '' - if not isinstance(chapters_json['chapters'], list): - return '' - chapters_html: str = '' - for chapter in chapters_json['chapters']: - if not isinstance(chapter, dict): - continue - if not chapter.get('title'): - continue - if not chapter.get('startTime'): - continue - chapter_title = chapter['title'] - chapter_url: str = '' - if chapter.get('url'): - url_str = get_url_from_post(chapter['url']) - chapter_url = remove_html(url_str) - chapter_title = \ - '' + \ - chapter['title'] + '<\a>' - start_sec = chapter['startTime'] - skip_url = link_url + '#t=' + str(start_sec) - start_time_str = \ - '' + \ - str(datetime.timedelta(seconds=start_sec)) + \ - '' - if chapter.get('img'): - chapters_html += \ - '
' + author + '
\n' - transcripts = _html_podcast_transcripts(podcast_properties, translate) + transcripts: str = _html_podcast_transcripts(podcast_properties, translate) if transcripts: podcast_str += '' + transcripts + '
\n' if newswire_item[4]: - podcast_description = \ + podcast_description: str = \ html.unescape(urllib.parse.unquote_plus(newswire_item[4])) podcast_description = safe_web_text(podcast_description) if podcast_description: @@ -476,8 +496,9 @@ def html_podcast_episode(translate: {}, # donate button if podcast_properties.get('funding'): if podcast_properties['funding'].get('url'): - url_str = get_url_from_post(podcast_properties['funding']['url']) - donate_url = remove_html(url_str) + url_str: str = \ + get_url_from_post(podcast_properties['funding']['url']) + donate_url: str = remove_html(url_str) podcast_str += \ '