From 4a1990ac3262fb74382e283c769fb9fcd3ff0aaf Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:22:40 +0900 Subject: [PATCH 1/2] Allow dest to refer to a filename relative to working directory 1) Allows user to set dest as merely a filename to be placed in the current directory If self.dest is set, but lacks a directory portion, then sets self.dest to itself with the working directory ['.'+os.sep] appended to the front of it. 2) Made so only checks for / creates the output directory once. --- pySmartDL/pySmartDL.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pySmartDL/pySmartDL.py b/pySmartDL/pySmartDL.py index 4fd5ebc..b444b52 100644 --- a/pySmartDL/pySmartDL.py +++ b/pySmartDL/pySmartDL.py @@ -130,17 +130,18 @@ def __init__(self, urls, dest=None, progress_bar=True, fix_urls=True, threads=5, self.post_threadpool_thread = None self.control_thread = None - if not os.path.exists(os.path.dirname(self.dest)): - self.logger.info('Folder "{}" does not exist. Creating...'.format(os.path.dirname(self.dest))) - os.makedirs(os.path.dirname(self.dest)) + dir = os.path.dirname(self.dest) + if not dir: + self.dest = os.path.join(".", self.dest) + else: + if not os.path.exists(dir): + self.logger.info('Directory "{}" does not exist. Creating it...'.format(dir)) + os.makedirs(dir) if not utils.is_HTTPRange_supported(self.url, timeout=self.timeout): self.logger.warning("Server does not support HTTPRange. threads_count is set to 1.") self.threads_count = 1 if os.path.exists(self.dest): self.logger.warning('Destination "{}" already exists. Existing file will be removed.'.format(self.dest)) - if not os.path.exists(os.path.dirname(self.dest)): - self.logger.warning('Directory "{}" does not exist. Creating it...'.format(os.path.dirname(self.dest))) - os.makedirs(os.path.dirname(self.dest)) self.logger.info("Creating a ThreadPool of {} thread(s).".format(self.threads_count)) self.pool = utils.ManagedThreadPoolExecutor(self.threads_count) From bcb6192350c38cc53426ca77ea38e218d87fb9c0 Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Tue, 27 Feb 2024 15:19:33 +0900 Subject: [PATCH 2/2] Add working directory logging When destination has no directory component, add logging info for placing the file into the working directory --- pySmartDL/pySmartDL.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pySmartDL/pySmartDL.py b/pySmartDL/pySmartDL.py index b444b52..4f88af2 100644 --- a/pySmartDL/pySmartDL.py +++ b/pySmartDL/pySmartDL.py @@ -132,6 +132,7 @@ def __init__(self, urls, dest=None, progress_bar=True, fix_urls=True, threads=5, dir = os.path.dirname(self.dest) if not dir: + self.logger.info('Destination "{}" does not have a directory component. Placing it in current working directory'.format(self.dest)) self.dest = os.path.join(".", self.dest) else: if not os.path.exists(dir):