From 793b615278bf47c4539df1e7a741baddf0c3e40a Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sat, 21 Oct 2023 09:55:05 +1100 Subject: [PATCH] skips downloading files which already exist --- autoradio/autoradio.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/autoradio/autoradio.py b/autoradio/autoradio.py index 3be9d37..a187692 100644 --- a/autoradio/autoradio.py +++ b/autoradio/autoradio.py @@ -9,10 +9,13 @@ from pathlib import Path def download_audio(link, destdir): parts = link.split('/') ptarget = Path(destdir) / Path(parts[-1]) - target = str(ptarget.resolve()) - args = [ "wget", link, "-o", target ] - print(f"downloading {link} to {target}") - subprocess.run(args) + target = ptarget.resolve() + if target.exists(): + print("File already exists, skipping") + else: + args = [ "wget", link, "-o", str(target) ] + print(f"downloading {link}") + subprocess.run(args)