mirror of
https://github.com/Emersont1/itchio.git
synced 2026-03-11 08:54:39 +00:00
Human Friendly naming option (#75)
* Fixes an issue prevents writing paths that end in '...' or similar * Add Framework for human readable folder structures * Removed -h argument due to conflict * Game Folders / Files now respond to --human-folders * Update Readme.md to include new argument * Remove -h from arg logic because it's not used and collides with help --------- Co-authored-by: 64Core <webmaster@64core.io>
This commit is contained in:
parent
b64e8197b9
commit
6b2113a64e
4 changed files with 30 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 = []
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue