Skip to content

Commit de4927e

Browse files
committed
added filter for static/animated cover
1 parent 3758982 commit de4927e

File tree

2 files changed

+99
-29
lines changed

2 files changed

+99
-29
lines changed

backend/handler/metadata/sgdb_handler.py

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
STEAMGRIDDB_API_ENABLED: Final = bool(STEAMGRIDDB_API_KEY)
99

1010
# SteamGridDB dimensions
11-
STEAMVERTICAL = "600x900"
12-
GALAXY342 = "342x482"
13-
GALAXY660 = "660x930"
14-
SQUARE512 = "512x512"
15-
SQUARE1024 = "1024x1024"
11+
STEAMVERTICAL: Final = "600x900"
12+
GALAXY342: Final = "342x482"
13+
GALAXY660: Final = "660x930"
14+
SQUARE512: Final = "512x512"
15+
SQUARE1024: Final = "1024x1024"
16+
17+
# SteamGridDB types
18+
STATIC: Final = "static"
19+
ANIMATED: Final = "animated"
20+
21+
SGDB_API_COVER_LIMIT: Final = 50
1622

1723

1824
class SGDBBaseHandler:
@@ -34,28 +40,58 @@ def get_details(self, search_term):
3440

3541
if len(search_response["data"]) == 0:
3642
log.warning(f"Could not find '{search_term}' on SteamGridDB")
37-
return ""
43+
return []
3844

3945
games = []
4046
for game in search_response["data"]:
47+
page = 0
4148
covers_response = requests.get(
4249
f"{self.grid_endpoint}/{game['id']}",
4350
headers=self.headers,
4451
timeout=120,
4552
params={
4653
"dimensions": f"{STEAMVERTICAL},{GALAXY342},{GALAXY660},{SQUARE512},{SQUARE1024}",
54+
"types": f"{STATIC},{ANIMATED}",
55+
"page": page,
4756
},
4857
).json()
4958

50-
games.append(
51-
{
52-
"name": game["name"],
53-
"resources": [
54-
{"thumb": cover["thumb"], "url": cover["url"]}
55-
for cover in covers_response["data"]
56-
],
57-
}
58-
)
59+
while (
60+
len(covers_response["data"]) < covers_response["total"]
61+
and covers_response["total"] > SGDB_API_COVER_LIMIT
62+
):
63+
page += 1
64+
covers_response["data"].extend(
65+
requests.get(
66+
f"{self.grid_endpoint}/{game['id']}",
67+
headers=self.headers,
68+
timeout=120,
69+
params={
70+
"dimensions": f"{STEAMVERTICAL},{GALAXY342},{GALAXY660},{SQUARE512},{SQUARE1024}",
71+
"types": f"{STATIC},{ANIMATED}",
72+
"page": page,
73+
},
74+
).json()["data"]
75+
)
76+
77+
if len(covers_response["data"]) > 0:
78+
games.append(
79+
{
80+
"name": game["name"],
81+
"resources": [
82+
{
83+
"thumb": cover["thumb"],
84+
"url": cover["url"],
85+
"type": (
86+
"animated"
87+
if cover["thumb"].split(".")[-1] == "webm"
88+
else "static"
89+
),
90+
}
91+
for cover in covers_response["data"]
92+
],
93+
}
94+
)
5995

6096
return games
6197

frontend/src/components/common/Game/Dialog/SearchCoverRom.vue

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<script setup lang="ts">
2-
import type { SearchCoverSchema, SearchRomSchema } from "@/__generated__";
2+
import type { SearchCoverSchema } from "@/__generated__";
33
import RDialog from "@/components/common/RDialog.vue";
44
import romApi from "@/services/api/rom";
55
import storeRoms, { type SimpleRom } from "@/stores/roms";
66
import type { Events } from "@/types/emitter";
77
import type { Emitter } from "mitt";
88
import { inject, onBeforeUnmount, ref } from "vue";
9-
import { useDisplay, useTheme } from "vuetify";
9+
import { useDisplay } from "vuetify";
1010
1111
// Props
12-
const { xs, lgAndUp } = useDisplay();
12+
const { lgAndUp } = useDisplay();
1313
const show = ref(false);
1414
const romsStore = storeRoms();
15-
const theme = useTheme();
1615
const rom = ref<SimpleRom | null>(null);
1716
const searching = ref(false);
1817
const searchTerm = ref("");
1918
const games = ref<SearchCoverSchema[]>();
19+
const filteredGames = ref<SearchCoverSchema[]>();
2020
const panels = ref([0]);
21-
const panelIndex = ref(0);
2221
const emitter = inject<Emitter<Events>>("emitter");
22+
const type = ref("all");
2323
emitter?.on("showSearchCoverDialog", (romToSearch) => {
2424
rom.value = romToSearch;
2525
searchTerm.value = romToSearch.name || romToSearch.file_name_no_tags || "";
@@ -45,6 +45,19 @@ async function searchCovers() {
4545
})
4646
.then((response) => {
4747
games.value = response.data;
48+
filteredGames.value = games.value
49+
.map((game) => {
50+
return {
51+
...game,
52+
resources:
53+
type.value === "all"
54+
? game.resources
55+
: game.resources.filter(
56+
(resource) => resource.type === type.value
57+
),
58+
};
59+
})
60+
.filter((item) => item.resources.length > 0);
4861
})
4962
.catch((error) => {
5063
emitter?.emit("snackbarShow", {
@@ -62,9 +75,6 @@ async function searchCovers() {
6275
async function updateCover(url_cover: string) {
6376
if (!rom.value) return;
6477
65-
console.log(url_cover);
66-
console.log(url_cover.replace("thumb", "grid"));
67-
6878
show.value = false;
6979
emitter?.emit("showLoadingDialog", { loading: true, scrim: true });
7080
@@ -92,6 +102,24 @@ async function updateCover(url_cover: string) {
92102
});
93103
}
94104
105+
function filterCovers() {
106+
if (games.value) {
107+
filteredGames.value = games.value
108+
.map((game) => {
109+
return {
110+
...game,
111+
resources:
112+
type.value === "all"
113+
? game.resources
114+
: game.resources.filter(
115+
(resource) => resource.type === type.value
116+
),
117+
};
118+
})
119+
.filter((item) => item.resources.length > 0);
120+
}
121+
}
122+
95123
function closeDialog() {
96124
show.value = false;
97125
games.value = undefined;
@@ -116,7 +144,7 @@ onBeforeUnmount(() => {
116144
>
117145
<template #toolbar>
118146
<v-row class="align-center" no-gutters>
119-
<v-col cols="10" sm="11">
147+
<v-col cols="8" sm="9">
120148
<v-text-field
121149
id="search-text-field"
122150
@keyup.enter="searchCovers()"
@@ -128,6 +156,15 @@ onBeforeUnmount(() => {
128156
clearable
129157
/>
130158
</v-col>
159+
<v-col cols="2" sm="2">
160+
<v-select
161+
v-model="type"
162+
hide-details
163+
label="Type"
164+
@update:model-value="filterCovers"
165+
:items="['all', 'static', 'animated']"
166+
/>
167+
</v-col>
131168
<v-col>
132169
<v-btn
133170
type="submit"
@@ -150,7 +187,7 @@ onBeforeUnmount(() => {
150187
rounded="0"
151188
variant="accordion"
152189
>
153-
<v-expansion-panel v-for="game in games" :key="game.name">
190+
<v-expansion-panel v-for="game in filteredGames" :key="game.name">
154191
<v-expansion-panel-title class="bg-terciary">
155192
<v-row no-gutters class="justify-center">
156193
<v-list-item class="pa-0">{{ game.name }}</v-list-item>
@@ -176,10 +213,7 @@ onBeforeUnmount(() => {
176213
cover
177214
>
178215
<template #error>
179-
<v-img
180-
:src="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
181-
cover
182-
></v-img>
216+
<v-img :src="resource.url" cover></v-img>
183217
</template>
184218
<template #placeholder>
185219
<div

0 commit comments

Comments
 (0)