forked from Mirrors/itch-dl
Add Support for https://itch.io/my-purchases
This commit is contained in:
committed by
Dragoon Aethis
parent
4960fee953
commit
6e7de8b5dc
@@ -10,6 +10,7 @@ from .api import ItchApiClient
|
|||||||
from .utils import ItchDownloadError, get_int_after_marker_in_json
|
from .utils import ItchDownloadError, get_int_after_marker_in_json
|
||||||
from .consts import ITCH_BASE, ITCH_URL, ITCH_BROWSER_TYPES
|
from .consts import ITCH_BASE, ITCH_URL, ITCH_BROWSER_TYPES
|
||||||
from .config import Settings
|
from .config import Settings
|
||||||
|
from .keys import get_owned_games
|
||||||
|
|
||||||
|
|
||||||
def get_jobs_for_game_jam_json(game_jam_json: dict) -> List[str]:
|
def get_jobs_for_game_jam_json(game_jam_json: dict) -> List[str]:
|
||||||
@@ -132,6 +133,9 @@ def get_jobs_for_itch_url(url: str, client: ItchApiClient) -> List[str]:
|
|||||||
|
|
||||||
raise ValueError("itch-dl expects a username in profile links.")
|
raise ValueError("itch-dl expects a username in profile links.")
|
||||||
|
|
||||||
|
elif site == "my-purchases": # User Purchased Games
|
||||||
|
return get_owned_games(client)
|
||||||
|
|
||||||
# Something else?
|
# Something else?
|
||||||
raise NotImplementedError(f"itch-dl does not understand \"{site}\" URLs. Please file a new issue.")
|
raise NotImplementedError(f"itch-dl does not understand \"{site}\" URLs. Please file a new issue.")
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from .api import ItchApiClient
|
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...")
|
logging.info("Fetching all download keys...")
|
||||||
download_keys: Dict[int, str] = {}
|
download_keys: Dict[int, str] = {}
|
||||||
|
game_urls: List[str] = []
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -21,6 +29,7 @@ def get_download_keys(client: ItchApiClient) -> Dict[int, str]:
|
|||||||
|
|
||||||
for key in data['owned_keys']:
|
for key in data['owned_keys']:
|
||||||
download_keys[key['game_id']] = key['id']
|
download_keys[key['game_id']] = key['id']
|
||||||
|
game_urls.append(key['game']['url'])
|
||||||
|
|
||||||
if len(data['owned_keys']) == data['per_page']:
|
if len(data['owned_keys']) == data['per_page']:
|
||||||
page += 1
|
page += 1
|
||||||
@@ -28,4 +37,16 @@ def get_download_keys(client: ItchApiClient) -> Dict[int, str]:
|
|||||||
break
|
break
|
||||||
|
|
||||||
logging.info(f"Fetched {len(download_keys)} download keys.")
|
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
|
return download_keys
|
||||||
|
|
||||||
|
|
||||||
|
def get_owned_games(client: ItchApiClient) -> List[str]:
|
||||||
|
(_, game_urls) = get_owned_keys(client)
|
||||||
|
return game_urls
|
||||||
Reference in New Issue
Block a user