1
0
forked from Mirrors/itch-dl
This commit is contained in:
Jeremie J. Jarosh
2023-08-19 09:07:38 -05:00
committed by Dragoon Aethis
parent 4960fee953
commit 6e7de8b5dc
2 changed files with 27 additions and 2 deletions

View File

@@ -1,12 +1,20 @@
import logging
from typing import Dict
from typing import Dict, List, Optional, Tuple
from .api import ItchApiClient
def get_download_keys(client: ItchApiClient) -> Dict[int, str]:
cached_owned_keys: Optional[Tuple[Dict[int, str], List[str]]] = None
def get_owned_keys(client: ItchApiClient) -> Tuple[Dict[int, str], List[str]]:
global cached_owned_keys
if cached_owned_keys is not None:
return cached_owned_keys
logging.info("Fetching all download keys...")
download_keys: Dict[int, str] = {}
game_urls: List[str] = []
page = 1
while True:
@@ -21,6 +29,7 @@ def get_download_keys(client: ItchApiClient) -> Dict[int, str]:
for key in data['owned_keys']:
download_keys[key['game_id']] = key['id']
game_urls.append(key['game']['url'])
if len(data['owned_keys']) == data['per_page']:
page += 1
@@ -28,4 +37,16 @@ def get_download_keys(client: ItchApiClient) -> Dict[int, str]:
break
logging.info(f"Fetched {len(download_keys)} download keys.")
cached_owned_keys = (download_keys, game_urls)
return cached_owned_keys
def get_download_keys(client: ItchApiClient) -> Dict[int, str]:
(download_keys, _) = get_owned_keys(client)
return download_keys
def get_owned_games(client: ItchApiClient) -> List[str]:
(_, game_urls) = get_owned_keys(client)
return game_urls