Add Framework for human readable folder structures

This commit is contained in:
64Core 2023-03-18 21:32:04 -05:00
parent c95b75b085
commit 2310f0ff66
2 changed files with 26 additions and 1 deletions

View file

@ -18,6 +18,16 @@ def main():
help="Platform to download for (default: all), will accept values like 'windows', 'linux', 'osx' and android",
)
parser.add_argument(
"-h",
"--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",

View file

@ -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 '-h' in self.args or '--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,15 @@ 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.name = 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.name = self.game_slug
self.publisher_slug = matches.group(1)
self.files = []
self.downloads = []