SteamGridDB animated covers
This commit is contained in:
@@ -236,6 +236,7 @@ template PreferencesWindow : Adw.PreferencesWindow {
|
||||
valign: center;
|
||||
}
|
||||
}
|
||||
|
||||
Adw.ActionRow {
|
||||
title: _("Prefer Over Official Images");
|
||||
|
||||
@@ -243,6 +244,14 @@ template PreferencesWindow : Adw.PreferencesWindow {
|
||||
valign: center;
|
||||
}
|
||||
}
|
||||
|
||||
Adw.ActionRow {
|
||||
title: _("Prefer Animated Images");
|
||||
|
||||
Switch sgdb_animated_switch {
|
||||
valign: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@
|
||||
</key>
|
||||
<key name="sgdb-prefer" type="b">
|
||||
<default>false</default>
|
||||
</key>
|
||||
<key name="sgdb-animated" type="b">
|
||||
<default>false</default>
|
||||
</key>
|
||||
</schema>
|
||||
<schema id="hu.kramo.Cartridge.State" path="/hu/kramo/Cartridges/State/">
|
||||
|
||||
@@ -120,6 +120,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
sgdb_key_entry_row = Gtk.Template.Child()
|
||||
sgdb_download_switch = Gtk.Template.Child()
|
||||
sgdb_prefer_switch = Gtk.Template.Child()
|
||||
sgdb_animated_switch = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, parent_widget, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -325,6 +326,13 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
|
||||
self.schema.bind(
|
||||
"sgdb-animated",
|
||||
self.sgdb_animated_switch,
|
||||
"active",
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
|
||||
def sgdb_key_changed(_widget):
|
||||
self.schema.set_string("sgdb-key", self.sgdb_key_entry_row.get_text())
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import requests
|
||||
from gi.repository import Gio
|
||||
|
||||
from .create_dialog import create_dialog
|
||||
from .save_cover import save_cover
|
||||
from .save_cover import save_cover, resize_animation
|
||||
|
||||
|
||||
class SGDBSave:
|
||||
@@ -61,29 +61,45 @@ class SGDBSave:
|
||||
task.return_value(game[0])
|
||||
return
|
||||
|
||||
animated_grid = False
|
||||
response = None
|
||||
|
||||
try:
|
||||
grid = requests.get(
|
||||
f'{url}grids/game/{search_result.json()["data"][0]["id"]}?dimensions=600x900',
|
||||
headers=headers,
|
||||
timeout=5,
|
||||
)
|
||||
if self.parent_widget.schema.get_boolean("sgdb-animated"):
|
||||
try:
|
||||
grid = requests.get(
|
||||
f'{url}grids/game/{search_result.json()["data"][0]["id"]}?dimensions=600x900&types=animated',
|
||||
headers=headers,
|
||||
timeout=5,
|
||||
)
|
||||
response = requests.get(
|
||||
grid.json()["data"][0]["url"], timeout=5
|
||||
)
|
||||
animated_grid = True
|
||||
except IndexError:
|
||||
pass
|
||||
if not response:
|
||||
grid = requests.get(
|
||||
f'{url}grids/game/{search_result.json()["data"][0]["id"]}?dimensions=600x900',
|
||||
headers=headers,
|
||||
timeout=5,
|
||||
)
|
||||
response = requests.get(grid.json()["data"][0]["url"], timeout=5)
|
||||
except (requests.exceptions.RequestException, IndexError):
|
||||
task.return_value(game[0])
|
||||
return
|
||||
|
||||
tmp_file = Gio.File.new_tmp(None)[0]
|
||||
|
||||
try:
|
||||
response = requests.get(
|
||||
grid.json()["data"][0]["url"],
|
||||
timeout=5,
|
||||
)
|
||||
except (requests.exceptions.RequestException, IndexError):
|
||||
task.return_value(game[0])
|
||||
return
|
||||
|
||||
Path(tmp_file.get_path()).write_bytes(response.content)
|
||||
save_cover(self.parent_widget, game[0], tmp_file.get_path())
|
||||
|
||||
save_cover(
|
||||
self.parent_widget,
|
||||
game[0],
|
||||
tmp_file.get_path(),
|
||||
animation_path=resize_animation(tmp_file.get_path())
|
||||
if animated_grid
|
||||
else None,
|
||||
)
|
||||
|
||||
task.return_value(game[0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user