fetch 1080p cover and huge screenshots

This commit is contained in:
Zurdi
2024-06-15 16:58:13 +02:00
parent 2cc66a1b69
commit cf38949a65
9 changed files with 12 additions and 53 deletions

View File

@@ -369,12 +369,10 @@ async def update_rom(
file_location_s = f"{artwork_path}/small.{file_ext}"
with open(file_location_s, "wb+") as artwork_s:
artwork_s.write(artwork_file)
fs_resource_handler.resize_cover(file_location_s, CoverSize.SMALL)
file_location_l = f"{artwork_path}/big.{file_ext}"
with open(file_location_l, "wb+") as artwork_l:
artwork_l.write(artwork_file)
fs_resource_handler.resize_cover(file_location_l, CoverSize.BIG)
db_rom_handler.update_rom(id, cleaned_data)

View File

@@ -41,40 +41,6 @@ class FSResourcesHandler(FSHandler):
)
)
@staticmethod
def resize_cover(cover_path: str, size: CoverSize = CoverSize.BIG) -> None:
"""Resizes the cover image to the standard size
Args:
cover_path: path where the original cover were stored
size: size of the cover
"""
cover = Image.open(cover_path)
if size == CoverSize.BIG and cover.size[1] > DEFAULT_HEIGHT_COVER_L:
big_dimensions = (DEFAULT_WIDTH_COVER_L, DEFAULT_HEIGHT_COVER_L)
background = Image.new("RGBA", big_dimensions, (0, 0, 0, 0))
cover.thumbnail(big_dimensions)
offset = (
int(round(((DEFAULT_WIDTH_COVER_L - cover.size[0]) / 2), 0)),
0,
)
elif size == CoverSize.SMALL and cover.size[1] > DEFAULT_HEIGHT_COVER_S:
small_dimensions = (DEFAULT_WIDTH_COVER_S, DEFAULT_HEIGHT_COVER_S)
background = Image.new("RGBA", small_dimensions, (0, 0, 0, 0))
cover.thumbnail(small_dimensions)
offset = (
int(round(((DEFAULT_WIDTH_COVER_S - cover.size[0]) / 2), 0)),
0,
)
else:
return
background.paste(cover, offset)
try:
background.save(cover_path)
except OSError:
rgb_background = background.convert("RGB")
rgb_background.save(cover_path)
def _store_cover(
self, fs_slug: str, rom_name: str, url_cover: str, size: CoverSize
):
@@ -91,7 +57,11 @@ class FSResourcesHandler(FSHandler):
try:
res = requests.get(
url_cover.replace("t_thumb", f"t_cover_{size.value}"),
(
url_cover.replace("t_thumb", f"t_cover_small")
if size.value == CoverSize.SMALL.value
else url_cover.replace("t_thumb", f"t_1080p")
),
stream=True,
timeout=120,
)
@@ -106,7 +76,6 @@ class FSResourcesHandler(FSHandler):
Path(cover_path).mkdir(parents=True, exist_ok=True)
with open(f"{cover_path}/{cover_file}", "wb") as f:
shutil.copyfileobj(res.raw, f)
self.resize_cover(f"{cover_path}/{cover_file}", size)
@staticmethod
def _get_cover_path(fs_slug: str, rom_name: str, size: CoverSize):

View File

@@ -424,7 +424,7 @@ class IGDBBaseHandler(MetadataHandler):
url_cover=self._normalize_cover_url(rom.get("cover", {}).get("url", "")),
url_screenshots=[
self._normalize_cover_url(s.get("url", "")).replace(
"t_thumb", "t_original"
"t_thumb", "t_screenshot_huge"
)
for s in rom.get("screenshots", [])
],
@@ -453,7 +453,7 @@ class IGDBBaseHandler(MetadataHandler):
url_cover=self._normalize_cover_url(rom.get("cover", {}).get("url", "")),
url_screenshots=[
self._normalize_cover_url(s.get("url", "")).replace(
"t_thumb", "t_original"
"t_thumb", "t_screenshot_huge"
)
for s in rom.get("screenshots", [])
],
@@ -542,9 +542,7 @@ class IGDBBaseHandler(MetadataHandler):
.replace("t_thumb", "t_cover_big")
),
"url_screenshots": [
self._normalize_cover_url(s.get("url", "")).replace(
"t_thumb", "t_original"
)
self._normalize_cover_url(s.get("url", ""))
for s in rom.get("screenshots", [])
],
"igdb_metadata": extract_metadata_from_igdb_rom(rom),

View File

@@ -15,8 +15,8 @@ const combined = ref([
class="pa-0"
cols="4"
sm="3"
lg="4"
xl="6"
lg="6"
xxl="4"
v-for="expansion in combined"
>
<a

View File

@@ -125,7 +125,7 @@ onMounted(() => {
!item.igdb_id && !item.moby_id
? `/assets/default/cover/small_${theme.global.name.value}_unmatched.png`
: item.has_cover
? `/assets/romm/resources/${item.path_cover_s}`
? `/assets/romm/resources/${item.path_cover_l}`
: `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
"
/>

View File

@@ -36,7 +36,6 @@ onMounted(() => {
:key="rom.id"
class="px-1 pt-1 pb-2"
:cols="views[0]['size-cols']"
:xs="views[0]['size-xs']"
:sm="views[0]['size-sm']"
:md="views[0]['size-md']"
:lg="views[0]['size-lg']"
@@ -47,6 +46,7 @@ onMounted(() => {
:rom="rom"
transform-scale
show-action-bar
title-on-hover
/>
</v-col>
</v-row>

View File

@@ -10,7 +10,6 @@ export const views: Record<
"size-lg": number;
"size-md": number;
"size-sm": number;
"size-xs": number;
"size-cols": number;
}
> = {
@@ -21,7 +20,6 @@ export const views: Record<
"size-lg": 2,
"size-md": 2,
"size-sm": 3,
"size-xs": 3,
"size-cols": 4,
},
1: {
@@ -31,7 +29,6 @@ export const views: Record<
"size-lg": 3,
"size-md": 3,
"size-sm": 4,
"size-xs": 6,
"size-cols": 6,
},
2: {
@@ -41,7 +38,6 @@ export const views: Record<
"size-lg": 12,
"size-md": 12,
"size-sm": 12,
"size-xs": 12,
"size-cols": 12,
},
};

View File

@@ -283,7 +283,6 @@ watch(currentView, (newView) => {
:key="rom.id"
class="pa-1"
:cols="views[currentView]['size-cols']"
:xs="views[currentView]['size-xs']"
:sm="views[currentView]['size-sm']"
:md="views[currentView]['size-md']"
:lg="views[currentView]['size-lg']"

View File

@@ -116,7 +116,6 @@ watch(
<v-col
cols="12"
md="7"
lg="6"
xl="8"
class="px-5"
:class="{