From 6d011ffbd49da35f2b0c5d1bc4eb146a1930c815 Mon Sep 17 00:00:00 2001 From: Jacob Stevens Date: Sun, 19 Mar 2023 03:05:59 -0500 Subject: [PATCH] Fixed typo and implemented file checking to prevent redownloading --- calibre_tools.py | 12 ++++++++++-- main.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/calibre_tools.py b/calibre_tools.py index ceb8091..989e688 100644 --- a/calibre_tools.py +++ b/calibre_tools.py @@ -93,7 +93,15 @@ class CalibreTools: @staticmethod def threadDownloadBook(link, directory_name): try: - wget.download(link, directory_name) + fragment_removed = link.split("#")[0] + query_string_removed = fragment_removed.split("?")[0] + scheme_removed = query_string_removed.split("://")[-1].split(":")[-1].replace("%20", " ") + if scheme_removed.find("/") != -1: + if not os.path.exists(directory_name + "/" + os.path.basename(scheme_removed)): + printInfo(f'Downloading {link}') + wget.download(link, directory_name) + else: + printInfo(f'File Exists... Skipping {link}') except: pass - CalibreTools.active_threads -= 1 \ No newline at end of file + CalibreTools.active_threads -= 1 diff --git a/main.py b/main.py index ad2147a..69127e2 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ def calibre_implementation(ip_port): printSuccess(f'Found {len(libraries)} libraries') else: libraries.append(args.lib) - if args.thread not is None: + if args.thread is not None: thr = args.thread for library in libraries: printInfo(f'Counting books from library: {library}')