diff --git a/itchiodl/downloader/__main__.py b/itchiodl/downloader/__main__.py index 489f081..cc3c09c 100644 --- a/itchiodl/downloader/__main__.py +++ b/itchiodl/downloader/__main__.py @@ -29,7 +29,6 @@ def main(): ) parser.add_argument( - "-v", "--verify", type=bool, default=False, @@ -82,8 +81,16 @@ def main(): if args.download_publisher: lib.load_games(args.download_publisher) elif args.download_game: - matches = re.match(r"https://(.+)\.itch\.io/(.+)", args.download_game) - lib.load_game(matches.group(1), matches.group(2)) + lib.load_owned_games() + for game in lib.games: + if game.link == args.download_game: + lib.games = [game] + break + if len(lib) > 1: + print("Game Is Not In Library, terminating") + return -1 +# matches = re.match(r"https://(.+)\.itch\.io/(.+)", args.download_game) +# lib.load_game(matches.group(1), matches.group(2)) else: lib.load_owned_games() diff --git a/itchiodl/game.py b/itchiodl/game.py index b2fd0f3..6158d25 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -20,7 +20,7 @@ class Game: self.verbose = True else: self.verbose = False - if '-v' or '--verify' in self.args: + if '--verify' in self.args: self.verify = True else: self.verify = False @@ -70,10 +70,9 @@ class Game: ) j = r.json() for d in j["uploads"]: - print(d["size"]) - if d["size"] <= self.skipping_above_size_B and self.skipping_large_entries: + if not self.skipping_above_size: self.downloads.append(d) - elif not self.skipping_above_size: + elif d["size"] <= self.skipping_above_size_B and self.skipping_large_entries: self.downloads.append(d) else: print("!Skipping Large Item!") @@ -120,28 +119,30 @@ class Game: if os.path.exists(f"{path}/{file}"): print(f"File Already Exists! {file}") if os.path.exists(f"{path}/{file}.md5"): + if self.verify: + with open(f"{path}/{file}.md5", "r") as f: + md5 = f.read().strip() - with open(f"{path}/{file}.md5", "r") as f: - md5 = f.read().strip() + if md5 == d["md5_hash"]: + print(f"Skipping {self.name} - {file}") + return + print(f"MD5 Mismatch! {file}") + else: + if self.verify: + md5 = itchiodl.utils.md5sum(f"{path}/{file}") if md5 == d["md5_hash"]: print(f"Skipping {self.name} - {file}") - return - print(f"MD5 Mismatch! {file}") - else: - md5 = itchiodl.utils.md5sum(f"{path}/{file}") - if md5 == d["md5_hash"]: - print(f"Skipping {self.name} - {file}") - # Create checksum file - with open(f"{path}/{file}.md5", "w") as f: - f.write(d["md5_hash"]) - return - # Old Download or corrupted file? - corrupted = False - if corrupted: - os.remove(f"{path}/{file}") - return + # Create checksum file + with open(f"{path}/{file}.md5", "w") as f: + f.write(d["md5_hash"]) + return + # Old Download or corrupted file? + corrupted = False + if corrupted: + os.remove(f"{path}/{file}") + return if not os.path.exists(f"{path}/old"): os.mkdir(f"{path}/old") diff --git a/itchiodl/library.py b/itchiodl/library.py index 6c43d9c..9bb43aa 100644 --- a/itchiodl/library.py +++ b/itchiodl/library.py @@ -15,6 +15,9 @@ class Library: self.games = [] self.jobs = jobs + def __len__(self): + return len(self.games) + def load_game_page(self, page): """Load a page of games via the API""" print("Loading page", page) diff --git a/itchiodl/utils.py b/itchiodl/utils.py index 9f12e39..1bd307c 100644 --- a/itchiodl/utils.py +++ b/itchiodl/utils.py @@ -24,18 +24,18 @@ def download(url, path, name, file): cd = rsp.headers.get("Content-Disposition") - filename_re = re.search(r'filename="(.+)"', cd) - if filename_re is None: - filename = file - else: - filename = filename_re.group(1) + #filename_re = re.search(r'filename="(.+)"', cd) + #if filename_re is None: + # filename = file + #else: + # filename = filename_re.group(1) - with open(f"{path}/{filename}", "wb") as f: + with open(f"{path}/{file}", "wb") as f: for chunk in rsp.iter_content(10240): f.write(chunk) - print(f"Downloaded {filename}") - return f"{path}/{filename}", True + print(f"Downloaded {file}") + return f"{path}/{file}", True def clean_path(path):