1
0
forked from Mirrors/itch-dl

Add a Settings system

Allows permanently configuring itch-dl with an API key and other things
in the future. Adds a new dependency, Pydantic, to validate the config.
This commit is contained in:
Ryszard Knop
2022-06-12 19:28:31 +02:00
parent f8f3e45a1b
commit 4542057654
5 changed files with 39 additions and 22 deletions

View File

@@ -14,6 +14,7 @@ from tqdm.contrib.concurrent import thread_map
from .api import ItchApiClient
from .utils import ItchDownloadError, get_int_after_marker_in_json
from .consts import ITCH_GAME_URL_REGEX
from .config import Settings
from .infobox import parse_infobox, InfoboxMetadata
TARGET_PATHS = {
@@ -58,12 +59,12 @@ class GameMetadata(TypedDict, total=False):
class GameDownloader:
def __init__(self, download_to: str, mirror_web: bool, api_key: str, keys: Dict[int, str]):
def __init__(self, download_to: str, mirror_web: bool, settings: Settings, keys: Dict[int, str]):
self.download_to = download_to
self.mirror_web = mirror_web
self.download_keys = keys
self.client = ItchApiClient(api_key)
self.client = ItchApiClient(settings.api_key, settings.user_agent)
@staticmethod
def get_rating_json(site) -> Optional[dict]:
@@ -337,11 +338,11 @@ def drive_downloads(
jobs: List[str],
download_to: str,
mirror_web: bool,
api_key: str,
settings: Settings,
keys: Dict[int, str],
parallel: int = 1
):
downloader = GameDownloader(download_to, mirror_web, api_key, keys)
downloader = GameDownloader(download_to, mirror_web, settings, keys)
tqdm_args = {
"desc": "Games",
"unit": "game",