diff --git a/Readme.md b/Readme.md index 5eab20c..18829f4 100644 --- a/Readme.md +++ b/Readme.md @@ -30,6 +30,10 @@ itch-download -k KEYHERE -j 4 # only download osx or cross platform downloads itch-download -p osx + +# folder structure uses display names for users/publishers and game titles +itch-download --human-folders + ``` ## Add All Games in a bundle to your library diff --git a/itchiodl/downloader/__main__.py b/itchiodl/downloader/__main__.py index 70e2223..3830a93 100644 --- a/itchiodl/downloader/__main__.py +++ b/itchiodl/downloader/__main__.py @@ -18,6 +18,15 @@ def main(): help="Platform to download for (default: all), will accept values like 'windows', 'linux', 'osx' and android", ) + parser.add_argument( + "--human-folders", + type=bool, + default=False, + const=True, + nargs='?', + help="Download Folders are named based on the full text version of the title instead of the trimmed URL title" + ) + parser.add_argument( "-j", "--jobs", diff --git a/itchiodl/game.py b/itchiodl/game.py index 3937c49..55b5641 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -4,6 +4,7 @@ import urllib import datetime from pathlib import Path import requests +from sys import argv from itchiodl import utils @@ -12,6 +13,12 @@ class Game: """Representation of a game download""" def __init__(self, data): + self.args = argv[1:] + if '--human-folders' in self.args: + self.humanFolders = True + else: + self.humanFolders = False + self.data = data["game"] self.name = self.data["title"] self.publisher = self.data["user"]["username"] @@ -25,7 +32,14 @@ class Game: matches = re.match(r"https://(.+)\.itch\.io/(.+)", self.link) self.game_slug = matches.group(2) - self.publisher_slug = matches.group(1) + if self.humanFolders: + self.game_slug = utils.clean_path(self.data["title"]) + self.publisher_slug = self.data.get("user").get("display_name") + # This Branch covers the case that the user has not set a display name, and defaults to their username + if not self.publisher_slug: + self.publisher_slug = self.data.get("user").get("username") + else: + self.publisher_slug = matches.group(1) self.files = [] self.downloads = [] diff --git a/itchiodl/utils.py b/itchiodl/utils.py index b972f67..4a7b78a 100644 --- a/itchiodl/utils.py +++ b/itchiodl/utils.py @@ -41,6 +41,8 @@ def clean_path(path): """Cleans a path on windows""" if sys.platform in ["win32", "cygwin", "msys"]: path_clean = re.sub(r"[<>:|?*\"\/\\]", "-", path) + # This checks for strings that end in ... or similar, weird corner case that affects fewer than 0.1% of titles + path_clean = re.sub(r'(.)[.]\1+$', "-", path_clean) return path_clean return path