mirror of
https://github.com/rommapp/romm.git
synced 2026-02-19 07:50:57 +01:00
[ROMM-386] Fix assets path for games with invalid caracters in titles
This commit is contained in:
@@ -3,6 +3,7 @@ import shutil
|
||||
from pathlib import Path
|
||||
import datetime
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
|
||||
from config import (
|
||||
LIBRARY_BASE_PATH,
|
||||
@@ -64,7 +65,7 @@ def _get_cover_path(p_slug: str, r_name: str, size: str):
|
||||
|
||||
Args:
|
||||
p_slug: short name of the platform
|
||||
file_name: name of rom file
|
||||
r_name: name of rom
|
||||
size: size of the cover -> big | small
|
||||
"""
|
||||
strtime = str(datetime.datetime.now().timestamp())
|
||||
@@ -72,21 +73,23 @@ def _get_cover_path(p_slug: str, r_name: str, size: str):
|
||||
|
||||
|
||||
def get_cover(overwrite: bool, p_slug: str, r_name: str, url_cover: str = "") -> dict:
|
||||
rom_name = quote(r_name)
|
||||
|
||||
# Cover small
|
||||
if (overwrite or not _cover_exists(p_slug, r_name, "small")) and url_cover:
|
||||
_store_cover(p_slug, r_name, url_cover, "small")
|
||||
if (overwrite or not _cover_exists(p_slug, rom_name, "small")) and url_cover:
|
||||
_store_cover(p_slug, rom_name, url_cover, "small")
|
||||
path_cover_s = (
|
||||
_get_cover_path(p_slug, r_name, "small")
|
||||
if _cover_exists(p_slug, r_name, "small")
|
||||
_get_cover_path(p_slug, rom_name, "small")
|
||||
if _cover_exists(p_slug, rom_name, "small")
|
||||
else DEFAULT_PATH_COVER_S
|
||||
)
|
||||
|
||||
# Cover big
|
||||
if (overwrite or not _cover_exists(p_slug, r_name, "big")) and url_cover:
|
||||
_store_cover(p_slug, r_name, url_cover, "big")
|
||||
if (overwrite or not _cover_exists(p_slug, rom_name, "big")) and url_cover:
|
||||
_store_cover(p_slug, rom_name, url_cover, "big")
|
||||
(path_cover_l, has_cover) = (
|
||||
(_get_cover_path(p_slug, r_name, "big"), 1)
|
||||
if _cover_exists(p_slug, r_name, "big")
|
||||
(_get_cover_path(p_slug, rom_name, "big"), 1)
|
||||
if _cover_exists(p_slug, rom_name, "big")
|
||||
else (DEFAULT_PATH_COVER_L, 0)
|
||||
)
|
||||
|
||||
@@ -102,7 +105,7 @@ def _store_screenshot(p_slug: str, r_name: str, url: str, idx: int):
|
||||
|
||||
Args:
|
||||
p_slug: short name of the platform
|
||||
file_name: name of rom file
|
||||
r_name: name of rom
|
||||
url: url to get the screenshot
|
||||
"""
|
||||
screenshot_file: str = f"{idx}.jpg"
|
||||
@@ -119,17 +122,19 @@ def _get_screenshot_path(p_slug: str, r_name: str, idx: str):
|
||||
|
||||
Args:
|
||||
p_slug: short name of the platform
|
||||
file_name: name of rom file
|
||||
r_name: name of rom
|
||||
idx: index number of screenshot
|
||||
"""
|
||||
return f"{p_slug}/{r_name}/screenshots/{idx}.jpg"
|
||||
|
||||
|
||||
def get_screenshots(p_slug: str, r_name: str, url_screenshots: list) -> dict:
|
||||
rom_name = quote(r_name)
|
||||
|
||||
path_screenshots: list[str] = []
|
||||
for idx, url in enumerate(url_screenshots):
|
||||
_store_screenshot(p_slug, r_name, url, idx)
|
||||
path_screenshots.append(_get_screenshot_path(p_slug, r_name, str(idx)))
|
||||
_store_screenshot(p_slug, rom_name, url, idx)
|
||||
path_screenshots.append(_get_screenshot_path(p_slug, rom_name, str(idx)))
|
||||
return {"path_screenshots": path_screenshots}
|
||||
|
||||
|
||||
@@ -309,10 +314,12 @@ def build_upload_roms_path(p_slug: str):
|
||||
|
||||
|
||||
def build_artwork_path(r_name: str, p_slug: str, file_ext: str):
|
||||
rom_name = quote(r_name)
|
||||
strtime = str(datetime.datetime.now().timestamp())
|
||||
path_cover_l = f"{p_slug}/{r_name}/cover/big.{file_ext}?timestamp={strtime}"
|
||||
path_cover_s = f"{p_slug}/{r_name}/cover/small.{file_ext}?timestamp={strtime}"
|
||||
artwork_path = f"{RESOURCES_BASE_PATH}/{p_slug}/{r_name}/cover"
|
||||
|
||||
path_cover_l = f"{p_slug}/{rom_name}/cover/big.{file_ext}?timestamp={strtime}"
|
||||
path_cover_s = f"{p_slug}/{rom_name}/cover/small.{file_ext}?timestamp={strtime}"
|
||||
artwork_path = f"{RESOURCES_BASE_PATH}/{p_slug}/{rom_name}/cover"
|
||||
Path(artwork_path).mkdir(parents=True, exist_ok=True)
|
||||
return path_cover_l, path_cover_s, artwork_path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user