🚧 Base Legendary source

This commit is contained in:
GeoffreyCoulaud
2023-06-08 10:50:09 +02:00
parent b895c8ebe2
commit 51922ad4c6
2 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
from pathlib import Path
import requests
from gi.repository import Gio
from requests import HTTPError
from urllib3.exceptions import SSLError
from src.game import Game
from src.store.managers.manager import Manager
from src.store.managers.local_cover_manager import LocalCoverManager
from src.utils.save_cover import resize_cover, save_cover
class OnlineCoverManager(Manager):
"""Manager that downloads game covers from URLs"""
run_after = set((LocalCoverManager,))
retryable_on = set((HTTPError, SSLError))
def manager_logic(self, game: Game, additional_data: dict) -> None:
# Ensure that we have a cover to download
cover_url = additional_data.get("online_cover_url", None)
if not cover_url:
return
# Download cover
tmp_file = Gio.File.new_tmp()[0]
with requests.get(cover_url, timeout=5) as cover:
cover.raise_for_status()
Path(tmp_file.get_path()).write_bytes(cover.content)
# Resize and save
save_cover(game.game_id, resize_cover(tmp_file.get_path()))