#55 merges (dos2Unix)

Co-authored-by: Blaze Marshall <wertercatt@wertercatt.com>
This commit is contained in:
Peter Taylor 2022-05-18 13:44:49 +01:00
parent e8ef0f8a5a
commit c93b5ddb0c
3 changed files with 36 additions and 10 deletions

View file

@ -52,7 +52,7 @@ def main():
lib = itchiodl.Library(l, args.jobs)
if args.download_publisher:
lib.load_game(args.download_publisher)
lib.load_games(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))

View file

@ -18,9 +18,13 @@ class Game:
self.name = self.data["title"]
self.publisher = self.data["user"]["username"]
self.link = self.data["url"]
self.id = data["id"]
self.game_id = data["game_id"]
if "game_id" in self.data:
self.id = self.data["id"]
self.game_id = self.data["game_id"]
else:
self.id = False
self.game_id = self.data["id"]
matches = re.match(r"https://(.+)\.itch\.io/(.+)", self.link)
self.game_slug = matches.group(2)
@ -32,10 +36,16 @@ class Game:
def load_downloads(self, token):
"""Load all downloads for this game"""
self.downloads = []
r = requests.get(
if self.id:
r = requests.get(
f"https://api.itch.io/games/{self.game_id}/uploads?download_key_id={self.id}",
headers={"Authorization": token},
)
else:
r = requests.get(
f"https://api.itch.io/games/{self.game_id}/uploads",
headers={"Authorization": token},
)
j = r.json()
for d in j["uploads"]:
self.downloads.append(d)
@ -129,10 +139,16 @@ class Game:
j = r.json()
# Download
url = (
if self.id:
url = (
f"https://api.itch.io/uploads/{d['id']}/"
+ f"download?api_key={token}&download_key_id={self.id}&uuid={j['uuid']}"
)
)
else:
url = (
f"https://api.itch.io/uploads/{d['id']}/"
+ f"download?api_key={token}&uuid={j['uuid']}"
)
# response_code = urllib.request.urlopen(url).getcode()
try:
itchiodl.utils.download(url, path, self.name, file)

View file

@ -44,14 +44,24 @@ class Library:
headers={"Authorization": self.login},
)
j = json.loads(rsp.text)
self.games.append(Game(j["id"]))
game_id = j["id"]
gsp = requests.get(
f"https://api.itch.io/games/{game_id}",
headers={"Authorization": self.login},
)
self.games.append(Game(json.loads(gsp.text)))
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]))
for link in soup.select("a.game_link"):
game_id = link.get("data-label").split(":")[1]
gsp = requests.get(
f"https://api.itch.io/games/{game_id}",
headers={"Authorization": self.login},
)
self.games.append(Game(json.loads(gsp.text)))
def download_library(self, platform=None):
"""Download all games in the library"""