mirror of https://gitlab.com/bashrc2/epicyon
Bencoded torrents
parent
91c24f224b
commit
fcf626607a
|
|
@ -103,7 +103,7 @@ def convert_torrent_to_note(base_dir: str, nickname: str, domain: str,
|
|||
conversation_id = post_id_to_convthread_id(conversation_id,
|
||||
post_json_object['published'])
|
||||
|
||||
media_type, media_url, media_torrent, media_magnet = \
|
||||
media_type, media_url, media_torrent, media_magnet, media_bencoded = \
|
||||
get_media_url_from_torrent(post_json_object)
|
||||
|
||||
if not media_url:
|
||||
|
|
@ -131,9 +131,9 @@ def convert_torrent_to_note(base_dir: str, nickname: str, domain: str,
|
|||
if isinstance(post_json_object['cc'], list):
|
||||
cc = post_json_object['cc']
|
||||
|
||||
if media_torrent or media_magnet:
|
||||
if media_torrent or media_magnet or media_bencoded:
|
||||
content += '<p>'
|
||||
if media_torrent:
|
||||
if media_torrent or media_bencoded:
|
||||
content += '<a href="' + media_torrent + '">⇓</a> '
|
||||
if media_magnet:
|
||||
content += '<a href="' + media_magnet + '">🧲</a>'
|
||||
|
|
|
|||
33
utils.py
33
utils.py
|
|
@ -3589,17 +3589,21 @@ def lines_in_file(filename: str) -> int:
|
|||
return 0
|
||||
|
||||
|
||||
def get_media_url_from_video(post_json_object: {}) -> (str, str, str, str):
|
||||
def get_media_url_from_video(post_json_object: {}) -> (str, 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
|
||||
media_bencoded = None
|
||||
if not post_json_object.get('url'):
|
||||
return media_type, media_url, media_torrent, media_magnet
|
||||
return media_type, media_url, media_torrent, \
|
||||
media_magnet, media_bencoded
|
||||
if not isinstance(post_json_object['url'], list):
|
||||
return media_type, media_url, media_torrent, media_magnet
|
||||
return media_type, media_url, media_torrent, \
|
||||
media_magnet, media_bencoded
|
||||
for media_link in post_json_object['url']:
|
||||
if not isinstance(media_link, dict):
|
||||
continue
|
||||
|
|
@ -3628,26 +3632,32 @@ def get_media_url_from_video(post_json_object: {}) -> (str, str, str, str):
|
|||
media_torrent = remove_html(media_link['href'])
|
||||
if media_link['href'].startswith('magnet:'):
|
||||
media_magnet = remove_html(media_link['href'])
|
||||
elif media_link['href'].startswith('bencoded:'):
|
||||
media_bencoded = 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
|
||||
return media_type, media_url, media_torrent, media_magnet, media_bencoded
|
||||
|
||||
|
||||
def get_media_url_from_torrent(post_json_object: {}) -> (str, str, str, str):
|
||||
def get_media_url_from_torrent(post_json_object: {}) -> (str, str, str,
|
||||
str, str):
|
||||
"""Within a Torrent post return the media details
|
||||
"""
|
||||
media_type = None
|
||||
media_url = None
|
||||
media_torrent = None
|
||||
media_magnet = None
|
||||
media_bencoded = None
|
||||
if not post_json_object.get('url'):
|
||||
return media_type, media_url, media_torrent, media_magnet
|
||||
return media_type, media_url, media_torrent, \
|
||||
media_magnet, media_bencoded
|
||||
if not isinstance(post_json_object['url'], list):
|
||||
return media_type, media_url, media_torrent, media_magnet
|
||||
return media_type, media_url, media_torrent, \
|
||||
media_magnet, media_bencoded
|
||||
for media_link in post_json_object['url']:
|
||||
if not isinstance(media_link, dict):
|
||||
continue
|
||||
|
|
@ -3666,9 +3676,12 @@ def get_media_url_from_torrent(post_json_object: {}) -> (str, str, str, str):
|
|||
if not tag_link.get('href'):
|
||||
continue
|
||||
if tag_link['mediaType'] == 'application/x-bittorrent' or \
|
||||
tag_link['mediaType'].startswith('magnet:'):
|
||||
tag_link['mediaType'].startswith('magnet:') or \
|
||||
tag_link['mediaType'].startswith('bencoded:'):
|
||||
if tag_link['mediaType'].startswith('magnet:'):
|
||||
media_magnet = remove_html(media_link['href'])
|
||||
elif tag_link['mediaType'].startswith('bencoded:'):
|
||||
media_bencoded = remove_html(media_link['href'])
|
||||
else:
|
||||
media_torrent = remove_html(media_link['href'])
|
||||
media_type = tag_link['mediaType']
|
||||
|
|
@ -3680,13 +3693,15 @@ def get_media_url_from_torrent(post_json_object: {}) -> (str, str, str, str):
|
|||
media_torrent = remove_html(media_link['href'])
|
||||
if media_link['href'].startswith('magnet:'):
|
||||
media_magnet = remove_html(media_link['href'])
|
||||
elif media_link['href'].startswith('bencoded:'):
|
||||
media_bencoded = 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
|
||||
return media_type, media_url, media_torrent, media_magnet, media_bencoded
|
||||
|
||||
|
||||
def get_reply_to(post_json_object: {}) -> str:
|
||||
|
|
|
|||
6
video.py
6
video.py
|
|
@ -104,7 +104,7 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
|
|||
conversation_id = post_id_to_convthread_id(conversation_id,
|
||||
post_json_object['published'])
|
||||
|
||||
media_type, media_url, media_torrent, media_magnet = \
|
||||
media_type, media_url, media_torrent, media_magnet, media_bencoded = \
|
||||
get_media_url_from_video(post_json_object)
|
||||
|
||||
if not media_url:
|
||||
|
|
@ -117,9 +117,9 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
|
|||
'url': media_url
|
||||
}]
|
||||
|
||||
if media_torrent or media_magnet:
|
||||
if media_torrent or media_magnet or media_bencoded:
|
||||
content += '<p>'
|
||||
if media_torrent:
|
||||
if media_torrent or media_bencoded:
|
||||
content += '<a href="' + media_torrent + '">⇓</a> '
|
||||
if media_magnet:
|
||||
content += '<a href="' + media_magnet + '">🧲</a>'
|
||||
|
|
|
|||
|
|
@ -1274,10 +1274,10 @@ def get_post_attachments_as_html(base_dir: str,
|
|||
# handle peertube-style video posts, where the media links
|
||||
# are stored in the url field
|
||||
if post_json_object.get('object'):
|
||||
media_type, media_url, _, _ = \
|
||||
media_type, media_url, _, _, _ = \
|
||||
get_media_url_from_video(post_json_object['object'])
|
||||
else:
|
||||
media_type, media_url, _, _ = \
|
||||
media_type, media_url, _, _, _ = \
|
||||
get_media_url_from_video(post_json_object)
|
||||
if media_url and media_type:
|
||||
attachment_dict = [{
|
||||
|
|
|
|||
Loading…
Reference in New Issue