main
Bob Mottram 2023-10-29 22:00:04 +00:00
parent a68c12d530
commit 23b20a8a58
2 changed files with 31 additions and 21 deletions

View File

@ -4677,3 +4677,31 @@ def corp_servers() -> ():
"""
return ('GitHub.com', 'github.com', 'cloudflare', 'microsoft.com',
'google.com')
def get_media_url_from_video(post_json_object: {}) -> (str, str, str, str):
"""Within a Video post (eg peertube) return the media details
"""
media_type = None
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'])
return media_type, media_url, media_torrent, media_magnet

View File

@ -16,6 +16,7 @@ from utils import get_attributed_to
from utils import get_content_from_post
from utils import dangerous_markup
from utils import license_link_from_name
from utils import get_media_url_from_video
from blocking import is_blocked
from filters import is_filtered
@ -91,27 +92,8 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
conversation_id = remove_id_ending(post_json_object['id'])
media_type = None
media_url = None
media_torrent = None
media_magnet = None
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'])
media_type, media_url, media_torrent, media_magnet = \
get_media_url_from_video(post_json_object)
if not media_url:
return None