Skip to content

Commit

Permalink
Handle all up-/download and delete conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Fittiboy committed Jul 1, 2021
1 parent bcfdb69 commit f094c1e
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions clipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,30 +286,52 @@ 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]
if sys.platform.startswith("win"):
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):
Expand Down

0 comments on commit f094c1e

Please sign in to comment.