From 2b441abbc8e37675ba087241dd609dd65b9f5599 Mon Sep 17 00:00:00 2001 From: "Jeremie J. Jarosh" Date: Sat, 15 Apr 2023 11:36:55 -0500 Subject: [PATCH] Allow the download directory to be changed --- itchiodl/downloader/__main__.py | 14 +++++++++++++- itchiodl/game.py | 5 +++-- itchiodl/library.py | 9 +++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/itchiodl/downloader/__main__.py b/itchiodl/downloader/__main__.py index 8814692..61de5e5 100644 --- a/itchiodl/downloader/__main__.py +++ b/itchiodl/downloader/__main__.py @@ -8,6 +8,16 @@ import itchiodl def main(): parser = argparse.ArgumentParser(prog="python -m hstp", description="Build an ") + parser.add_argument( + "-o", + "--output-dir", + type=str, + default=".", + help=( + "The location to store the downloaded files, defaults to the current working directory" + ), + ) + parser.add_argument( "-k", "--api-key", help="Use API key instead of username/password" ) @@ -58,7 +68,9 @@ def main(): else: l = args.api_key - lib = itchiodl.Library(l, jobs=args.jobs, human_folders=args.human_folders) + lib = itchiodl.Library( + l, jobs=args.jobs, human_folders=args.human_folders, output_dir=args.output_dir + ) if args.download_publisher: lib.load_games(args.download_publisher) diff --git a/itchiodl/game.py b/itchiodl/game.py index 1dbfb44..fb811e6 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -11,8 +11,9 @@ from itchiodl import utils class Game: """Representation of a game download""" - def __init__(self, data, human_folders: bool): + def __init__(self, data, human_folders: bool, output_dir: str): self.human_folders = human_folders + self.output_path = Path(output_dir) self.data = data["game"] self.name = self.data["title"] @@ -40,7 +41,7 @@ class Game: self.files = [] self.downloads = [] self.dir = ( - Path(".") + self.output_path / utils.clean_path(self.publisher_slug) / utils.clean_path(self.game_slug) ) diff --git a/itchiodl/library.py b/itchiodl/library.py index e0b4688..db83e00 100644 --- a/itchiodl/library.py +++ b/itchiodl/library.py @@ -12,11 +12,12 @@ from itchiodl.utils import NoDownloadError class Library: """Representation of a user's game library""" - def __init__(self, login, jobs=4, human_folders=False): + def __init__(self, login, jobs=4, human_folders=False, output_dir="."): self.login = login self.games = [] self.jobs = jobs self.human_folders = human_folders + self.output_dir = output_dir def load_game_page(self, page): """Load a page of games via the API""" @@ -28,7 +29,7 @@ class Library: j = json.loads(r.text) for s in j["owned_keys"]: - self.games.append(Game(s, self.human_folders)) + self.games.append(Game(s, self.human_folders, self.output_dir)) return len(j["owned_keys"]) @@ -55,7 +56,7 @@ class Library: ) k = gsp.json() if k != {"uploads": {}}: - self.games.append(Game(k, self.human_folders)) + self.games.append(Game(k, self.human_folders, self.output_dir)) return print(f"{title} is a purchased game.") i = 1 @@ -86,7 +87,7 @@ class Library: headers={"Authorization": self.login}, ) k = json.loads(gsp.text) - self.games.append(Game(k, self.human_folders)) + self.games.append(Game(k, self.human_folders, self.output_dir)) def download_library(self, platform=None): """Download all games in the library"""