From 0bebcddcc4e98326aa6591fca7918636ead3fe9d Mon Sep 17 00:00:00 2001 From: Peter Taylor Date: Sun, 27 Mar 2022 00:09:23 +0000 Subject: [PATCH] Added cleaned up path (#6 fix) (#42) * Added cleaned up path (#6 fix) * autopep8 action fixes (#43) --- itchiodl/game.py | 3 ++- itchiodl/utils.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/itchiodl/game.py b/itchiodl/game.py index a255b3e..a36856f 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -53,7 +53,8 @@ class Game: continue file = d['filename'] or d['display_name'] or d['id'] - path = f"{self.publisher_slug}/{self.game_slug}" + path = itchiodl.utils.clean_path( + f"{self.publisher_slug}/{self.game_slug}") if os.path.exists(f"{path}/{file}"): print(f"Skipping {path}/{file}") continue diff --git a/itchiodl/utils.py b/itchiodl/utils.py index 4dee575..a2d20e5 100644 --- a/itchiodl/utils.py +++ b/itchiodl/utils.py @@ -1,6 +1,7 @@ import requests import re import os +import sys from clint.textui import progress @@ -54,3 +55,11 @@ def download(url, path, name, file): print(f"Downloaded {filename}") return f"{path}/{filename}", True + + +def clean_path(path): + """Cleans a path on windows""" + if sys.platform in ["win32", "cygwin", "msys"]: + path_clean = re.replace(r'[\<\>\:\"\/\\\|\?\*]', "-", path) + return path_clean + return path