mirror of
https://github.com/Emersont1/itchio.git
synced 2026-03-11 08:54:39 +00:00
Added individual game downloader
This commit is contained in:
parent
e66e81a5c0
commit
be5baca377
2 changed files with 39 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import argparse
|
||||
from getpass import getpass
|
||||
import re
|
||||
|
||||
import itchiodl
|
||||
|
||||
|
|
@ -25,6 +26,18 @@ def main():
|
|||
help="Number of concurrent downloads, defaults to 4",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--download-publisher",
|
||||
type=str,
|
||||
help="Download all games from a specific publisher",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--download-game",
|
||||
type=str,
|
||||
help="Download a specific game, should be in the format publisher.itch.io/game",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
l = ""
|
||||
|
|
@ -37,7 +50,15 @@ def main():
|
|||
l = args.api_key
|
||||
|
||||
lib = itchiodl.Library(l, args.jobs)
|
||||
lib.load_games()
|
||||
|
||||
if args.download_publisher:
|
||||
lib.load_game(args.download_publisher)
|
||||
elif args.download_game:
|
||||
matches = re.match(r"https://(.+)\.itch\.io/(.+)", args.download_game)
|
||||
lib.load_game(matches.group(1), matches.group(2))
|
||||
else:
|
||||
lib.load_owned_games()
|
||||
|
||||
lib.download_library(args.platform)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from itchiodl.game import Game
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ class Library:
|
|||
|
||||
return len(j["owned_keys"])
|
||||
|
||||
def load_games(self):
|
||||
def load_owned_games(self):
|
||||
"""Load all games in the library via the API"""
|
||||
page = 1
|
||||
while True:
|
||||
|
|
@ -36,6 +37,21 @@ class Library:
|
|||
break
|
||||
page += 1
|
||||
|
||||
def load_game(self, publisher, title):
|
||||
"""Load a game by publisher and title"""
|
||||
requests.get(
|
||||
f"https://{publisher}.itch.io/{title}/data.json",
|
||||
headers={"Authorization": self.login},
|
||||
)
|
||||
self.games.append(Game(publisher, title))
|
||||
|
||||
def load_games(self, publisher):
|
||||
"""Load all games by publisher"""
|
||||
rsp = requests.get(f"https://{publisher}.itch.io")
|
||||
soup = BeautifulSoup(rsp.text, "html.parser")
|
||||
for link in soup.select("a.game-link"):
|
||||
self.games.append(Game(link.get("data-label").split(":")[1]))
|
||||
|
||||
def download_library(self, platform=None):
|
||||
"""Download all games in the library"""
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue