update function defs

This commit is contained in:
Georges-Antoine Assi
2025-11-24 19:36:27 -05:00
parent 5b195065fe
commit bb351199f1
3 changed files with 22 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ async def export_gamelist(
platform_ids: Annotated[
List[int], Query(description="List of platform IDs to export")
],
local_path: Annotated[
local_export: Annotated[
bool, Query(description="Use local paths instead of URLs")
] = False,
) -> Response:
@@ -35,13 +35,14 @@ async def export_gamelist(
)
try:
exporter = GamelistExporter()
exporter = GamelistExporter(local_export=local_export)
files_written = []
# Export each platform to its respective directory
for platform_id in platform_ids:
success = await exporter.export_platform_to_file(
platform_id, request if not local_path else None
platform_id,
request,
)
if success:
files_written.append(f"gamelist_{platform_id}.xml")

View File

@@ -234,7 +234,7 @@ def extract_media_from_ss_game(rom: Rom, game: SSGame) -> SSMetadataMedia:
ss_media["box2d_back_url"] = media["url"]
if MetadataMediaType.BOX2D_BACK in preferred_media_types:
ss_media["box2d_back_path"] = (
f"{fs_resource_handler.get_media_resources_path(rom.platform_id, rom.id, MetadataMediaType.BOX2D)}/box2d_back.png"
f"{fs_resource_handler.get_media_resources_path(rom.platform_id, rom.id, MetadataMediaType.BOX2D_BACK)}/box2d_back.png"
)
elif media.get("type") == "bezel-16-9" and not ss_media["bezel_url"]:
ss_media["bezel_url"] = media["url"]

View File

@@ -6,6 +6,8 @@ from xml.etree.ElementTree import ( # trunk-ignore(bandit/B405)
tostring,
)
from fastapi import Request
from config import FRONTEND_RESOURCES_PATH, YOUTUBE_BASE_URL
from handler.database import db_platform_handler, db_rom_handler
from handler.filesystem import fs_platform_handler
@@ -16,16 +18,21 @@ from models.rom import Rom
class GamelistExporter:
"""Export RomM collections to ES-DE gamelist.xml format"""
def __init__(self, local_export: bool = False):
self.local_export = local_export
def _format_release_date(self, timestamp: int) -> str:
"""Format release date to YYYYMMDDTHHMMSS format"""
return datetime.fromtimestamp(timestamp / 1000).strftime("%Y%m%dT%H%M%S")
def _create_game_element(self, rom: Rom, request=None) -> Element:
def _create_game_element(self, rom: Rom, request: Request) -> Element:
"""Create a <game> element for a ROM"""
game = Element("game")
# Basic game info
if request:
if self.local_export:
SubElement(game, "path").text = f"./{rom.fs_name}"
else:
SubElement(game, "path").text = str(
request.url_for(
"get_rom_content",
@@ -33,15 +40,14 @@ class GamelistExporter:
file_name=rom.fs_name,
)
)
else:
SubElement(game, "path").text = f"./{rom.fs_name}"
SubElement(game, "name").text = rom.name or rom.fs_name
if rom.summary:
SubElement(game, "desc").text = rom.summary
# Media files
if getattr(rom, "path_cover_l", None):
if rom.path_cover_l:
SubElement(game, "thumbnail").text = (
f"{FRONTEND_RESOURCES_PATH}/{rom.path_cover_l}"
)
@@ -107,13 +113,13 @@ class GamelistExporter:
SubElement(game, "marquee").text = (
f"{FRONTEND_RESOURCES_PATH}/{rom.ss_metadata["logo_path"]}"
)
if rom.ss_metadata.get("miximage"):
if rom.ss_metadata.get("miximage_path"):
SubElement(game, "miximage").text = (
f"{FRONTEND_RESOURCES_PATH}/{rom.ss_metadata["miximage"]}"
f"{FRONTEND_RESOURCES_PATH}/{rom.ss_metadata["miximage_path"]}"
)
if rom.ss_metadata.get("physical"):
if rom.ss_metadata.get("physical_path"):
SubElement(game, "physicalmedia").text = (
f"{FRONTEND_RESOURCES_PATH}/{rom.ss_metadata["physical"]}"
f"{FRONTEND_RESOURCES_PATH}/{rom.ss_metadata["physical_path"]}"
)
if rom.ss_metadata.get("title_screen"):
SubElement(game, "title_screen").text = (
@@ -149,7 +155,7 @@ class GamelistExporter:
return game
def export_platform_to_xml(self, platform_id: int, request=None) -> str:
def export_platform_to_xml(self, platform_id: int, request: Request) -> str:
"""Export a platform's ROMs to gamelist.xml format
Args:
@@ -182,7 +188,7 @@ class GamelistExporter:
async def export_platform_to_file(
self,
platform_id: int,
request=None,
request: Request,
) -> bool:
"""Export platform ROMs to gamelist.xml file in the platform's directory