mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
update function defs
This commit is contained in:
@@ -23,7 +23,7 @@ async def export_gamelist(
|
|||||||
platform_ids: Annotated[
|
platform_ids: Annotated[
|
||||||
List[int], Query(description="List of platform IDs to export")
|
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")
|
bool, Query(description="Use local paths instead of URLs")
|
||||||
] = False,
|
] = False,
|
||||||
) -> Response:
|
) -> Response:
|
||||||
@@ -35,13 +35,14 @@ async def export_gamelist(
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exporter = GamelistExporter()
|
exporter = GamelistExporter(local_export=local_export)
|
||||||
files_written = []
|
files_written = []
|
||||||
|
|
||||||
# Export each platform to its respective directory
|
# Export each platform to its respective directory
|
||||||
for platform_id in platform_ids:
|
for platform_id in platform_ids:
|
||||||
success = await exporter.export_platform_to_file(
|
success = await exporter.export_platform_to_file(
|
||||||
platform_id, request if not local_path else None
|
platform_id,
|
||||||
|
request,
|
||||||
)
|
)
|
||||||
if success:
|
if success:
|
||||||
files_written.append(f"gamelist_{platform_id}.xml")
|
files_written.append(f"gamelist_{platform_id}.xml")
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ def extract_media_from_ss_game(rom: Rom, game: SSGame) -> SSMetadataMedia:
|
|||||||
ss_media["box2d_back_url"] = media["url"]
|
ss_media["box2d_back_url"] = media["url"]
|
||||||
if MetadataMediaType.BOX2D_BACK in preferred_media_types:
|
if MetadataMediaType.BOX2D_BACK in preferred_media_types:
|
||||||
ss_media["box2d_back_path"] = (
|
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"]:
|
elif media.get("type") == "bezel-16-9" and not ss_media["bezel_url"]:
|
||||||
ss_media["bezel_url"] = media["url"]
|
ss_media["bezel_url"] = media["url"]
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from xml.etree.ElementTree import ( # trunk-ignore(bandit/B405)
|
|||||||
tostring,
|
tostring,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from fastapi import Request
|
||||||
|
|
||||||
from config import FRONTEND_RESOURCES_PATH, YOUTUBE_BASE_URL
|
from config import FRONTEND_RESOURCES_PATH, YOUTUBE_BASE_URL
|
||||||
from handler.database import db_platform_handler, db_rom_handler
|
from handler.database import db_platform_handler, db_rom_handler
|
||||||
from handler.filesystem import fs_platform_handler
|
from handler.filesystem import fs_platform_handler
|
||||||
@@ -16,16 +18,21 @@ from models.rom import Rom
|
|||||||
class GamelistExporter:
|
class GamelistExporter:
|
||||||
"""Export RomM collections to ES-DE gamelist.xml format"""
|
"""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:
|
def _format_release_date(self, timestamp: int) -> str:
|
||||||
"""Format release date to YYYYMMDDTHHMMSS format"""
|
"""Format release date to YYYYMMDDTHHMMSS format"""
|
||||||
return datetime.fromtimestamp(timestamp / 1000).strftime("%Y%m%dT%H%M%S")
|
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"""
|
"""Create a <game> element for a ROM"""
|
||||||
game = Element("game")
|
game = Element("game")
|
||||||
|
|
||||||
# Basic game info
|
# Basic game info
|
||||||
if request:
|
if self.local_export:
|
||||||
|
SubElement(game, "path").text = f"./{rom.fs_name}"
|
||||||
|
else:
|
||||||
SubElement(game, "path").text = str(
|
SubElement(game, "path").text = str(
|
||||||
request.url_for(
|
request.url_for(
|
||||||
"get_rom_content",
|
"get_rom_content",
|
||||||
@@ -33,15 +40,14 @@ class GamelistExporter:
|
|||||||
file_name=rom.fs_name,
|
file_name=rom.fs_name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
SubElement(game, "path").text = f"./{rom.fs_name}"
|
|
||||||
SubElement(game, "name").text = rom.name or rom.fs_name
|
SubElement(game, "name").text = rom.name or rom.fs_name
|
||||||
|
|
||||||
if rom.summary:
|
if rom.summary:
|
||||||
SubElement(game, "desc").text = rom.summary
|
SubElement(game, "desc").text = rom.summary
|
||||||
|
|
||||||
# Media files
|
# Media files
|
||||||
if getattr(rom, "path_cover_l", None):
|
if rom.path_cover_l:
|
||||||
SubElement(game, "thumbnail").text = (
|
SubElement(game, "thumbnail").text = (
|
||||||
f"{FRONTEND_RESOURCES_PATH}/{rom.path_cover_l}"
|
f"{FRONTEND_RESOURCES_PATH}/{rom.path_cover_l}"
|
||||||
)
|
)
|
||||||
@@ -107,13 +113,13 @@ class GamelistExporter:
|
|||||||
SubElement(game, "marquee").text = (
|
SubElement(game, "marquee").text = (
|
||||||
f"{FRONTEND_RESOURCES_PATH}/{rom.ss_metadata["logo_path"]}"
|
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 = (
|
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 = (
|
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"):
|
if rom.ss_metadata.get("title_screen"):
|
||||||
SubElement(game, "title_screen").text = (
|
SubElement(game, "title_screen").text = (
|
||||||
@@ -149,7 +155,7 @@ class GamelistExporter:
|
|||||||
|
|
||||||
return game
|
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
|
"""Export a platform's ROMs to gamelist.xml format
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -182,7 +188,7 @@ class GamelistExporter:
|
|||||||
async def export_platform_to_file(
|
async def export_platform_to_file(
|
||||||
self,
|
self,
|
||||||
platform_id: int,
|
platform_id: int,
|
||||||
request=None,
|
request: Request,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Export platform ROMs to gamelist.xml file in the platform's directory
|
"""Export platform ROMs to gamelist.xml file in the platform's directory
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user