mirror of
https://github.com/mister-monster/YouTube2PeerTube.git
synced 2024-11-24 20:26:47 -05:00
return error when resquest fail
This commit is contained in:
parent
fb2a0125f2
commit
ba9d9a8301
@ -146,6 +146,14 @@ def get_file(file_path):
|
||||
return (path.basename(file_path), open(path.abspath(file_path), 'rb'),
|
||||
mimetypes.types_map[path.splitext(file_path)[1]])
|
||||
|
||||
|
||||
def handle_peertube_result(request_result):
|
||||
if request_result.status_code < 300:
|
||||
return True
|
||||
else:
|
||||
print(request_result)
|
||||
return False
|
||||
|
||||
def upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension):
|
||||
# Adapted from Prismedia https://git.lecygnenoir.info/LecygneNoir/prismedia
|
||||
pt_api = channel_conf["peertube_instance"] + "/api/v1"
|
||||
@ -184,7 +192,8 @@ def upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension
|
||||
'Content-Type': multipart_data.content_type,
|
||||
'Authorization': "Bearer " + access_token
|
||||
}
|
||||
print(requests.post(pt_api + "/videos/upload", data=multipart_data, headers=headers).content)
|
||||
|
||||
return handle_peertube_result(requests.post(pt_api + "/videos/upload", data=multipart_data, headers=headers))
|
||||
|
||||
def pt_http_import(dl_dir, channel_conf, queue_item, access_token, thumb_extension, yt_lang):
|
||||
# Adapted from Prismedia https://git.lecygnenoir.info/LecygneNoir/prismedia
|
||||
@ -226,7 +235,10 @@ def pt_http_import(dl_dir, channel_conf, queue_item, access_token, thumb_extensi
|
||||
'Content-Type': multipart_data.content_type,
|
||||
'Authorization': "Bearer " + access_token
|
||||
}
|
||||
print(requests.post(pt_api + "/videos/imports", data=multipart_data, headers=headers).content)
|
||||
|
||||
return handle_peertube_result(requests.post(pt_api + "/videos/imports", data=multipart_data, headers=headers))
|
||||
|
||||
|
||||
|
||||
def run_steps(conf):
|
||||
# TODO: logging
|
||||
@ -275,12 +287,16 @@ def run_steps(conf):
|
||||
for queue_item in queue:
|
||||
if not use_pt_http_import:
|
||||
print("uploading " + queue_item["yt_videoid"] + " to Peertube...")
|
||||
upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension)
|
||||
print("done.")
|
||||
pt_result = upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension)
|
||||
|
||||
else:
|
||||
print("mirroring " + queue_item["link"] + " to Peertube using HTTP import...")
|
||||
pt_http_import(dl_dir, channel_conf, queue_item, access_token, thumb_extension, yt_lang)
|
||||
print("done.")
|
||||
pt_result = pt_http_import(dl_dir, channel_conf, queue_item, access_token, thumb_extension, yt_lang)
|
||||
|
||||
if pt_result:
|
||||
print("done !")
|
||||
else:
|
||||
print("Error !")
|
||||
if delete_videos:
|
||||
print("deleting videos and/or thumbnails...")
|
||||
rmtree(dl_dir + "/" + channel_conf["name"], ignore_errors=True)
|
||||
|
Loading…
Reference in New Issue
Block a user