From 377754c95b7ebd317007e8eb80f5bb78885c04f2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 31 Oct 2023 19:20:50 +0000 Subject: [PATCH] Check that url exists --- utils.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/utils.py b/utils.py index 59822faf0..743ae305a 100644 --- a/utils.py +++ b/utils.py @@ -4686,22 +4686,25 @@ def get_media_url_from_video(post_json_object: {}) -> (str, str, str, str): media_url = None media_torrent = None media_magnet = None - if isinstance(post_json_object['url'], list): - for media_link in post_json_object['url']: - if not isinstance(media_link, dict): - continue - if not media_link.get('mediaType'): - continue - if not media_link.get('href'): - continue - if media_link['mediaType'] == 'application/x-bittorrent': - media_torrent = remove_html(media_link['href']) - if media_link['href'].startswith('magnet:'): - media_magnet = remove_html(media_link['href']) - if media_link['mediaType'] != 'video/mp4' and \ - media_link['mediaType'] != 'video/ogv': - continue - if not media_url: - media_type = media_link['mediaType'] - media_url = remove_html(media_link['href']) + if post_json_object.get('url'): + if isinstance(post_json_object['url'], list): + for media_link in post_json_object['url']: + if not isinstance(media_link, dict): + continue + if not media_link.get('mediaType'): + continue + if not media_link.get('href'): + continue + if media_link['mediaType'] == 'application/x-bittorrent': + media_torrent = remove_html(media_link['href']) + if media_link['href'].startswith('magnet:'): + media_magnet = remove_html(media_link['href']) + if media_link['mediaType'] != 'video/mp4' and \ + media_link['mediaType'] != 'video/ogv': + continue + if not media_url: + media_type = media_link['mediaType'] + media_url = remove_html(media_link['href']) + else: + print('WARN: video url does not exist ' + str(post_json_object)) return media_type, media_url, media_torrent, media_magnet