Removed some debug code

-v is no longer a symbol for --verify due to overlap with -vf
lack of --verify now correctly prevents .md5 file generation
Fixed an Issue where unicode filenames were getting mangled in utils.py, unsure what the larger purpose of that regular expression block is
This commit is contained in:
64Core 2022-06-04 12:46:19 -05:00
parent 5e62b47ab3
commit 7be4210d7a
4 changed files with 43 additions and 32 deletions

View file

@ -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()

View file

@ -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")

View file

@ -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)

View file

@ -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):