mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 15:54:45 +01:00
updates to hasheous
This commit is contained in:
4 files changed
+80
-16
No files matched your search
@@ -31,8 +31,16 @@ def upgrade() -> None:
|
||||
)
|
||||
batch_op.create_index("idx_roms_hasheous_id", ["hasheous_id"], unique=False)
|
||||
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("hasheous_id", sa.Integer(), nullable=True))
|
||||
batch_op.add_column(sa.Column("tgdb_id", sa.Integer(), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.drop_column("hasheous_id")
|
||||
batch_op.drop_column("tgdb_id")
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.drop_index("idx_roms_hasheous_id")
|
||||
batch_op.drop_column("hasheous_metadata")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import json
|
||||
from typing import TypedDict
|
||||
from typing import NotRequired, TypedDict
|
||||
|
||||
import httpx
|
||||
from config import HASHEOUS_API_ENABLED
|
||||
@@ -15,11 +15,17 @@ class HasheousMetadata(TypedDict):
|
||||
|
||||
|
||||
class HasheousPlatform(TypedDict):
|
||||
id: int
|
||||
slug: str
|
||||
hasheous_id: int | None
|
||||
name: NotRequired[str]
|
||||
igdb_id: NotRequired[str | None]
|
||||
tgdb_id: NotRequired[int | None]
|
||||
ra_id: NotRequired[int | None]
|
||||
|
||||
|
||||
class HasheousRom(TypedDict):
|
||||
igdb_id: int | None
|
||||
hasheous_id: int | None
|
||||
igdb_id: NotRequired[int | None]
|
||||
|
||||
|
||||
class HasheousHandler(MetadataHandler):
|
||||
@@ -28,20 +34,28 @@ class HasheousHandler(MetadataHandler):
|
||||
self.platform_endpoint = f"{self.BASE_URL}/Platforms"
|
||||
self.games_endpoint = f"{self.BASE_URL}/ByHash"
|
||||
|
||||
async def _request(self, url: str, params: dict, timeout: int = 120) -> dict:
|
||||
async def _request(
|
||||
self, url: str, params: dict, data: dict, timeout: int = 120
|
||||
) -> dict:
|
||||
httpx_client = ctx_httpx_client.get()
|
||||
|
||||
try:
|
||||
log.debug(
|
||||
"API request: URL=%s, Params=%s, Timeout=%s",
|
||||
"API request: URL=%s, Params=%s, Data=%s, Timeout=%s",
|
||||
url,
|
||||
params,
|
||||
data,
|
||||
timeout,
|
||||
)
|
||||
res = await httpx_client.get(
|
||||
print(
|
||||
f"API request: URL={url}, Params={params}, Data={data}, Timeout={timeout}"
|
||||
)
|
||||
res = await httpx_client.post(
|
||||
url,
|
||||
params=params,
|
||||
data=data,
|
||||
timeout=timeout,
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
||||
res.raise_for_status()
|
||||
@@ -61,6 +75,21 @@ class HasheousHandler(MetadataHandler):
|
||||
|
||||
return {}
|
||||
|
||||
def get_platform(self, slug: str) -> HasheousPlatform:
|
||||
platform = HASHEOUS_PLATFORM_LIST.get(slug, None)
|
||||
|
||||
if not platform:
|
||||
return HasheousPlatform(hasheous_id=None, slug=slug)
|
||||
|
||||
return HasheousPlatform(
|
||||
hasheous_id=platform["id"],
|
||||
slug=slug,
|
||||
name=platform["name"],
|
||||
igdb_id=platform["igdb_id"],
|
||||
tgdb_id=platform["tgdb_id"],
|
||||
ra_id=platform["ra_id"],
|
||||
)
|
||||
|
||||
# async def _build_platforms(self) -> None:
|
||||
# from .igdb_handler import IGDB_PLATFORMS_BY_SLUG
|
||||
|
||||
@@ -107,24 +136,41 @@ class HasheousHandler(MetadataHandler):
|
||||
|
||||
async def get_rom(self, rom_attrs: dict) -> HasheousRom:
|
||||
if not HASHEOUS_API_ENABLED:
|
||||
return HasheousRom(igdb_id=None)
|
||||
return HasheousRom(hasheous_id=None)
|
||||
|
||||
md5_hash = rom_attrs.get("md5_hash")
|
||||
sha1_hash = rom_attrs.get("sha1_hash")
|
||||
crc_hash = rom_attrs.get("crc_hash")
|
||||
|
||||
if not (md5_hash or sha1_hash or crc_hash):
|
||||
log.warning(
|
||||
"No hashes provided for Hasheous lookup. "
|
||||
"At least one of md5_hash, sha1_hash, or crc_hash is required."
|
||||
)
|
||||
return HasheousRom(hasheous_id=None)
|
||||
|
||||
data = {}
|
||||
if md5_hash:
|
||||
data["mD5"] = md5_hash
|
||||
if sha1_hash:
|
||||
data["shA1"] = sha1_hash
|
||||
if crc_hash:
|
||||
data["crc"] = crc_hash
|
||||
|
||||
hasheous_game = await self._request(
|
||||
self.games_endpoint,
|
||||
params={
|
||||
"mD5": rom_attrs["md5_hash"],
|
||||
"shA1": rom_attrs["sha1_hash"],
|
||||
"crc": rom_attrs["crc_hash"],
|
||||
"returnAllSources": True,
|
||||
"returnFields": "All",
|
||||
},
|
||||
data=data,
|
||||
)
|
||||
|
||||
import ipdb
|
||||
|
||||
ipdb.set_trace()
|
||||
|
||||
return HasheousRom(igdb_id=None)
|
||||
return HasheousRom(hasheous_id=None)
|
||||
|
||||
|
||||
class SlugToHasheousId(TypedDict):
|
||||
|
||||
@@ -16,7 +16,7 @@ from handler.metadata import (
|
||||
meta_ra_handler,
|
||||
meta_ss_handler,
|
||||
)
|
||||
from handler.metadata.hasheous_handler import HasheousRom
|
||||
from handler.metadata.hasheous_handler import HasheousPlatform, HasheousRom
|
||||
from handler.metadata.igdb_handler import IGDBPlatform, IGDBRom
|
||||
from handler.metadata.launchbox_handler import LaunchboxPlatform, LaunchboxRom
|
||||
from handler.metadata.moby_handler import MobyGamesPlatform, MobyGamesRom
|
||||
@@ -152,12 +152,16 @@ async def scan_platform(
|
||||
if MetadataSource.LB in metadata_sources
|
||||
else LaunchboxPlatform(launchbox_id=None, slug=platform_attrs["slug"])
|
||||
)
|
||||
|
||||
await meta_hasheous_handler.get_platforms()
|
||||
hasheous_platform = (
|
||||
meta_hasheous_handler.get_platform(platform_attrs["slug"])
|
||||
if MetadataSource.HASHEOUS in metadata_sources
|
||||
else HasheousPlatform(hasheous_id=None, slug=platform_attrs["slug"])
|
||||
)
|
||||
|
||||
platform_attrs["name"] = platform_attrs["slug"].replace("-", " ").title()
|
||||
platform_attrs.update(
|
||||
{
|
||||
**hasheous_platform,
|
||||
**launchbox_platform,
|
||||
**ra_platform,
|
||||
**moby_platform,
|
||||
@@ -172,6 +176,7 @@ async def scan_platform(
|
||||
or platform_attrs["ss_id"]
|
||||
or platform_attrs["ra_id"]
|
||||
or platform_attrs["launchbox_id"]
|
||||
or hasheous_platform["hasheous_id"]
|
||||
):
|
||||
log.info(
|
||||
emoji.emojize(
|
||||
@@ -431,7 +436,7 @@ async def scan_rom(
|
||||
async def fetch_hasheous_rom() -> HasheousRom:
|
||||
if (
|
||||
MetadataSource.HASHEOUS in metadata_sources
|
||||
and platform.fs_slug
|
||||
and platform.hasheous_id
|
||||
and (
|
||||
newly_added
|
||||
or scan_type == ScanType.COMPLETE
|
||||
@@ -441,7 +446,7 @@ async def scan_rom(
|
||||
):
|
||||
return await meta_hasheous_handler.get_rom(rom_attrs)
|
||||
|
||||
return HasheousRom(igdb_id=None)
|
||||
return HasheousRom(hasheous_id=None)
|
||||
|
||||
# Run both metadata fetches concurrently
|
||||
(
|
||||
@@ -465,6 +470,8 @@ async def scan_rom(
|
||||
# Only update fields if match is found
|
||||
if playmatch_handler_rom.get("igdb_id"):
|
||||
rom_attrs.update({**playmatch_handler_rom})
|
||||
if hasheous_handler_rom.get("hasheous_id"):
|
||||
rom_attrs.update({**hasheous_handler_rom})
|
||||
if ra_handler_rom.get("ra_id"):
|
||||
rom_attrs.update({**ra_handler_rom})
|
||||
if moby_handler_rom.get("moby_id"):
|
||||
@@ -484,6 +491,7 @@ async def scan_rom(
|
||||
and not ra_handler_rom.get("ra_id")
|
||||
and not launchbox_handler_rom.get("launchbox_id")
|
||||
and not playmatch_handler_rom.get("igdb_id")
|
||||
and not hasheous_handler_rom.get("hasheous_id")
|
||||
):
|
||||
log.warning(
|
||||
emoji.emojize(f"{hl(rom_attrs['fs_name'])} not identified :cross_mark:"),
|
||||
|
||||
@@ -25,6 +25,8 @@ class Platform(BaseModel):
|
||||
ss_id: Mapped[int | None]
|
||||
ra_id: Mapped[int | None]
|
||||
launchbox_id: Mapped[int | None]
|
||||
hasheous_id: Mapped[int | None]
|
||||
tgdb_id: Mapped[int | None]
|
||||
slug: Mapped[str] = mapped_column(String(length=100))
|
||||
fs_slug: Mapped[str] = mapped_column(String(length=100))
|
||||
name: Mapped[str] = mapped_column(String(length=400))
|
||||
|
||||
Reference in new issue
Block a user