From f094c1e44ed601b46bb707436b343f97f8feeb42 Mon Sep 17 00:00:00 2001 From: Fitti Date: Thu, 1 Jul 2021 16:37:27 +0200 Subject: [PATCH] Handle all up-/download and delete conditions --- clipper.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/clipper.py b/clipper.py index 36400f2..ac13700 100644 --- a/clipper.py +++ b/clipper.py @@ -286,6 +286,9 @@ def dl_progress(count, block_size, total_size): for url in all_urls: total += 1 + download = True + delete = False + upload = False dl_url = url[1] file_name = url[0] + ".mp4" clip_id = file_name.split(" _ ")[-1] @@ -293,23 +296,42 @@ def dl_progress(count, block_size, total_size): file_name = file_name.strip().replace(" ", "_") file_name = re.sub(r'(?u)[^-\w.]', "", file_name) fullpath = pjoin(base_path, file_name) - if gdrive and clip_id in files: - continue - elif clip_id in exist_ids and not gdrive: + if ( + (clip_id in exist_ids and not gdrive) or + (not args.dual and clip_id in files) or + (clip_id in exist_ids and clip_id in files) + ): continue + elif ( + clip_id in exist_ids and + clip_id not in files and + gdrive + ): + download = False + upload = True + elif ( + clip_id not in exist_ids and + clip_id not in files and + gdrive + ): + upload = True + if not args.dual: + delete = True try: print(str(total) + "/" + str(len(all_urls)) + "\t" + fullpath) - dl.urlretrieve(dl_url, fullpath, - reporthook=dl_progress) - if gdrive: + if download: + dl.urlretrieve(dl_url, fullpath, + reporthook=dl_progress) + if upload: upload = drive.CreateFile({'title': file_name, 'parents': [{ 'id': staging_folder }]}) upload.SetContentFile(fullpath) upload.Upload() - remove(fullpath) + if delete: + remove(fullpath) print() except KeyboardInterrupt: if isfile(fullpath):