mirror of
https://github.com/Emersont1/itchio.git
synced 2026-03-11 08:54:39 +00:00
Pass the "Human Folders" Option Through the Library Class
To remove the need for the `Game` class to parse `sys.argv`, we'll store the option in the `Library` class and pass it to `Game` as needed. The `ArgumentParser.add_argument()` call has been updated to show up as an 'on/off' argument. Also fix the naming convention. According to Python's PEP 8 Style Guide, function and variable names should be lowercase with words separated by underscores (aka snake_case). The rest of this project seems to follow PEP 8, so `humanFolders` should be `human_folders`.
This commit is contained in:
parent
7cec2f24a2
commit
57310c8c99
3 changed files with 14 additions and 18 deletions
|
|
@ -20,11 +20,11 @@ def main():
|
|||
|
||||
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",
|
||||
action="store_true",
|
||||
help=(
|
||||
"Download Folders are named based on the full text version of the title instead of "
|
||||
"the trimmed URL title"
|
||||
),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
|
|
@ -58,7 +58,7 @@ def main():
|
|||
else:
|
||||
l = args.api_key
|
||||
|
||||
lib = itchiodl.Library(l, args.jobs)
|
||||
lib = itchiodl.Library(l, jobs=args.jobs, human_folders=args.human_folders)
|
||||
|
||||
if args.download_publisher:
|
||||
lib.load_games(args.download_publisher)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import json
|
|||
import urllib
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
from sys import argv
|
||||
import requests
|
||||
|
||||
from itchiodl import utils
|
||||
|
|
@ -12,12 +11,8 @@ from itchiodl import utils
|
|||
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
|
||||
def __init__(self, data, human_folders: bool):
|
||||
self.human_folders = human_folders
|
||||
|
||||
self.data = data["game"]
|
||||
self.name = self.data["title"]
|
||||
|
|
@ -32,7 +27,7 @@ class Game:
|
|||
|
||||
matches = re.match(r"https://(.+)\.itch\.io/(.+)", self.link)
|
||||
self.game_slug = matches.group(2)
|
||||
if self.humanFolders:
|
||||
if self.human_folders:
|
||||
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
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ from itchiodl.utils import NoDownloadError
|
|||
class Library:
|
||||
"""Representation of a user's game library"""
|
||||
|
||||
def __init__(self, login, jobs=4):
|
||||
def __init__(self, login, jobs=4, human_folders=False):
|
||||
self.login = login
|
||||
self.games = []
|
||||
self.jobs = jobs
|
||||
self.human_folders = human_folders
|
||||
|
||||
def load_game_page(self, page):
|
||||
"""Load a page of games via the API"""
|
||||
|
|
@ -27,7 +28,7 @@ class Library:
|
|||
j = json.loads(r.text)
|
||||
|
||||
for s in j["owned_keys"]:
|
||||
self.games.append(Game(s))
|
||||
self.games.append(Game(s, self.human_folders))
|
||||
|
||||
return len(j["owned_keys"])
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ class Library:
|
|||
)
|
||||
k = gsp.json()
|
||||
if k != {"uploads": {}}:
|
||||
self.games.append(Game(k))
|
||||
self.games.append(Game(k, self.human_folders))
|
||||
return
|
||||
print(f"{title} is a purchased game.")
|
||||
i = 1
|
||||
|
|
@ -85,7 +86,7 @@ class Library:
|
|||
headers={"Authorization": self.login},
|
||||
)
|
||||
k = json.loads(gsp.text)
|
||||
self.games.append(Game(k))
|
||||
self.games.append(Game(k, self.human_folders))
|
||||
|
||||
def download_library(self, platform=None):
|
||||
"""Download all games in the library"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue