1
1
mirror of https://github.com/mister-monster/YouTube2PeerTube.git synced 2024-11-22 20:10:15 -05:00

Compare commits

...

4 Commits

Author SHA1 Message Date
mister-monster
9395712a05
Merge pull request #14 from tjiho/master
fix Error handling #4
2020-01-04 23:37:30 -06:00
Tjiho
7af4e6221b add channel name in error file 2020-01-05 01:31:23 +01:00
Tjiho
a6469621b7 write upload error in a file 2020-01-04 17:05:36 +01:00
Tjiho
ba9d9a8301 return error when resquest fail 2020-01-04 16:44:58 +01:00

View File

@ -146,6 +146,14 @@ def get_file(file_path):
return (path.basename(file_path), open(path.abspath(file_path), 'rb'), return (path.basename(file_path), open(path.abspath(file_path), 'rb'),
mimetypes.types_map[path.splitext(file_path)[1]]) 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): def upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension):
# Adapted from Prismedia https://git.lecygnenoir.info/LecygneNoir/prismedia # Adapted from Prismedia https://git.lecygnenoir.info/LecygneNoir/prismedia
pt_api = channel_conf["peertube_instance"] + "/api/v1" 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, 'Content-Type': multipart_data.content_type,
'Authorization': "Bearer " + access_token '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): 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 # Adapted from Prismedia https://git.lecygnenoir.info/LecygneNoir/prismedia
@ -226,7 +235,15 @@ def pt_http_import(dl_dir, channel_conf, queue_item, access_token, thumb_extensi
'Content-Type': multipart_data.content_type, 'Content-Type': multipart_data.content_type,
'Authorization': "Bearer " + access_token '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 log_upload_error(yt_url,channel_conf):
error_file = open("video_errors.csv", "a")
error_file.write(channel_conf['name']+","+yt_url+"\n")
error_file.close()
print("error !")
def run_steps(conf): def run_steps(conf):
# TODO: logging # TODO: logging
@ -275,12 +292,16 @@ def run_steps(conf):
for queue_item in queue: for queue_item in queue:
if not use_pt_http_import: if not use_pt_http_import:
print("uploading " + queue_item["yt_videoid"] + " to Peertube...") print("uploading " + queue_item["yt_videoid"] + " to Peertube...")
upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension) pt_result = upload_to_pt(dl_dir, channel_conf, queue_item, access_token, thumb_extension)
print("done.")
else: else:
print("mirroring " + queue_item["link"] + " to Peertube using HTTP import...") 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) pt_result = pt_http_import(dl_dir, channel_conf, queue_item, access_token, thumb_extension, yt_lang)
print("done.")
if pt_result:
print("done !")
else:
log_upload_error(queue_item["link"],channel_conf)
if delete_videos: if delete_videos:
print("deleting videos and/or thumbnails...") print("deleting videos and/or thumbnails...")
rmtree(dl_dir + "/" + channel_conf["name"], ignore_errors=True) rmtree(dl_dir + "/" + channel_conf["name"], ignore_errors=True)