From c5673cf974b5bfaa188a2751babb18c7f300f986 Mon Sep 17 00:00:00 2001 From: 64Core Date: Wed, 25 May 2022 16:15:01 -0500 Subject: [PATCH] Added the framework for writing verbose folder names, changed how the destination path was being generated to allow for more runtime configurations, also added an extra argument for skipping files above a certain size however it is not currently implemented. --- itchiodl/downloader/__main__.py | 20 ++++++++++++++++++++ itchiodl/game.py | 15 +++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/itchiodl/downloader/__main__.py b/itchiodl/downloader/__main__.py index 70e2223..90b0ab1 100644 --- a/itchiodl/downloader/__main__.py +++ b/itchiodl/downloader/__main__.py @@ -18,6 +18,22 @@ def main(): help="Platform to download for (default: all), will accept values like 'windows', 'linux', 'osx' and android", ) + parser.add_argument( + "-vf", + "--verbose-folders", + type=bool, + default=False, + help="Download Folders are named based on the full text version of the title instead of the trimmed URL title" + ) + + parser.add_argument( + "-sas", + "--skip-above-size", + type=float, + default=float('inf'), + help="Skips individual files that are above the specified size threshold, size in MB" + ) + parser.add_argument( "-j", "--jobs", @@ -41,6 +57,10 @@ def main(): args = parser.parse_args() l = "" + global SkipAboveSize + SkipAboveSize = args.skip_above_size + global VerboseFolders + VerboseFolders = args.verbose_folders if not args.api_key: user = input("Username: ") diff --git a/itchiodl/game.py b/itchiodl/game.py index c080354..9f0172f 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -29,6 +29,13 @@ class Game: self.game_slug = matches.group(2) self.publisher_slug = matches.group(1) + if "VerboseFolders" in globals(): + self.destination_folder = self.game_slug if not VerboseFolders else self.name + else: + self.destination_folder = self.game_slug + print("VerboseFolders Not Detected in Global Variables, Falling Back to Game Slug\n") + self.destination_path = itchiodl.utils.clean_path(f"{self.publisher_slug}/{self.destination_folder}") + self.files = [] self.downloads = [] @@ -62,8 +69,8 @@ class Game: if not os.path.exists(self.publisher_slug): os.mkdir(self.publisher_slug) - if not os.path.exists(f"{self.publisher_slug}/{self.game_slug}"): - os.mkdir(f"{self.publisher_slug}/{self.game_slug}") + if not os.path.exists(self.destination_path): + os.mkdir(self.destination_path) for d in self.downloads: if ( @@ -75,7 +82,7 @@ class Game: continue self.do_download(d, token) - with open(f"{self.publisher_slug}/{self.game_slug}.json", "w") as f: + with open(f"{self.destination_path}.json", "w") as f: json.dump( { "name": self.name, @@ -94,7 +101,7 @@ class Game: print(f"Downloading {d['filename']}") file = itchiodl.utils.clean_path(d["filename"] or d["display_name"] or d["id"]) - path = itchiodl.utils.clean_path(f"{self.publisher_slug}/{self.game_slug}") + path = self.destination_path if os.path.exists(f"{path}/{file}"): print(f"File Already Exists! {file}")