mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
Improved scan logs
This commit is contained in:
@@ -9,7 +9,7 @@ from models.platform import Platform
|
||||
from models.rom import Rom
|
||||
|
||||
|
||||
async def scan(_sid: str, platforms: str, complete_rescan: bool = True, sm = None):
|
||||
async def scan(_sid: str, platforms: str, complete_rescan: bool = True, sm=None):
|
||||
"""Scan platforms and roms and write them in database."""
|
||||
|
||||
log.info(emoji.emojize(":magnifying_glass_tilted_right: Scanning "))
|
||||
@@ -27,20 +27,17 @@ async def scan(_sid: str, platforms: str, complete_rescan: bool = True, sm = Non
|
||||
)
|
||||
log.info(f"Platforms to be scanned: {', '.join(platforms)}")
|
||||
for platform in platforms:
|
||||
log.info(emoji.emojize(f":video_game: {platform}"))
|
||||
try:
|
||||
scanned_platform: Platform = fastapi.scan_platform(platform)
|
||||
except RomsNotFoundException as e:
|
||||
log.error(e)
|
||||
continue
|
||||
|
||||
await sm.emit(
|
||||
"scan:scanning_platform", [scanned_platform.name, scanned_platform.slug]
|
||||
)
|
||||
await sm.emit("") # Workaround to emit in real-time
|
||||
if platform != str(scanned_platform):
|
||||
log.info(
|
||||
f"Identified as {scanned_platform}"
|
||||
)
|
||||
|
||||
dbh.add_platform(scanned_platform)
|
||||
|
||||
# Scanning roms
|
||||
@@ -49,17 +46,14 @@ async def scan(_sid: str, platforms: str, complete_rescan: bool = True, sm = Non
|
||||
rom_id: int = dbh.rom_exists(scanned_platform.slug, rom["file_name"])
|
||||
if rom_id and not complete_rescan:
|
||||
continue
|
||||
|
||||
await sm.emit("scan:scanning_rom", rom["file_name"])
|
||||
await sm.emit("") # Workaround to emit in real-time
|
||||
log.info(f"\t - {rom['file_name']}")
|
||||
if rom["multi"]:
|
||||
[
|
||||
log.info(f"\t\t · {file}")
|
||||
for file in rom["files"]
|
||||
]
|
||||
|
||||
scanned_rom: Rom = fastapi.scan_rom(scanned_platform, rom)
|
||||
if rom_id:
|
||||
scanned_rom.id = rom_id
|
||||
|
||||
dbh.add_rom(scanned_rom)
|
||||
dbh.purge_roms(scanned_platform.slug, [rom["file_name"] for rom in fs_roms])
|
||||
dbh.purge_platforms(fs_platforms)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import sys
|
||||
import functools
|
||||
import pydash
|
||||
import requests
|
||||
|
||||
from time import time
|
||||
from unidecode import unidecode as uc
|
||||
from requests.exceptions import HTTPError, Timeout
|
||||
|
||||
import requests
|
||||
from config import CLIENT_ID, CLIENT_SECRET
|
||||
from utils import get_file_name_with_no_tags as get_search_term
|
||||
from logger.logger import log
|
||||
@@ -37,7 +40,7 @@ class IGDBHandler:
|
||||
) -> dict:
|
||||
category_filter: str = f"& category={category}" if category else ""
|
||||
try:
|
||||
return requests.post(
|
||||
res = requests.post(
|
||||
self.games_url,
|
||||
headers=self.headers,
|
||||
data=f"""
|
||||
@@ -45,10 +48,14 @@ class IGDBHandler:
|
||||
fields id, slug, name, summary, screenshots;
|
||||
where platforms=[{p_igdb_id}] {category_filter};
|
||||
""",
|
||||
).json()[0]
|
||||
except IndexError:
|
||||
)
|
||||
res.raise_for_status()
|
||||
except (HTTPError, Timeout) as err:
|
||||
log.error(err)
|
||||
return {}
|
||||
|
||||
return pydash.get(res.json(), "[0]", {})
|
||||
|
||||
@staticmethod
|
||||
def _normalize_cover_url(url: str) -> str:
|
||||
return f"https:{url.replace('https:', '')}"
|
||||
@@ -95,13 +102,11 @@ class IGDBHandler:
|
||||
"slug": slug,
|
||||
}
|
||||
except IndexError:
|
||||
log.warning(f"{slug} not found in IGDB")
|
||||
|
||||
return {
|
||||
"igdb_id": "",
|
||||
"name": slug,
|
||||
"slug": slug,
|
||||
}
|
||||
return {
|
||||
"igdb_id": "",
|
||||
"name": slug,
|
||||
"slug": slug,
|
||||
}
|
||||
|
||||
@check_twitch_token
|
||||
def get_rom(self, file_name: str, p_igdb_id: int):
|
||||
@@ -117,9 +122,6 @@ class IGDBHandler:
|
||||
r_name = res.get("name", search_term)
|
||||
summary = res.get("summary", "")
|
||||
|
||||
if not r_igdb_id:
|
||||
log.warning(f"{r_name} not found in IGDB")
|
||||
|
||||
return {
|
||||
"r_igdb_id": r_igdb_id,
|
||||
"r_slug": r_slug,
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import emoji
|
||||
|
||||
from handler import igdbh
|
||||
from utils import fs, parse_tags, get_file_extension, get_file_name_with_no_tags
|
||||
from config.config_loader import config
|
||||
from models.platform import Platform
|
||||
from models.rom import Rom
|
||||
from logger.logger import log
|
||||
|
||||
|
||||
def scan_platform(fs_slug: str) -> Platform:
|
||||
@@ -14,6 +17,8 @@ def scan_platform(fs_slug: str) -> Platform:
|
||||
Platform object
|
||||
"""
|
||||
|
||||
log.info(f"· {fs_slug}")
|
||||
|
||||
platform_attrs = {}
|
||||
platform_attrs["fs_slug"] = fs_slug
|
||||
|
||||
@@ -25,7 +30,14 @@ def scan_platform(fs_slug: str) -> Platform:
|
||||
except (KeyError, TypeError, AttributeError):
|
||||
platform_attrs["slug"] = fs_slug
|
||||
|
||||
platform_attrs.update(igdbh.get_platform(platform_attrs["slug"]))
|
||||
platform = igdbh.get_platform(platform_attrs["slug"])
|
||||
|
||||
if platform["igdb_id"]:
|
||||
log.info(emoji.emojize(f" Identified as {platform['name']} :video_game:"))
|
||||
else:
|
||||
log.warning(f" {fs_slug} not found in IGDB")
|
||||
|
||||
platform_attrs.update(platform)
|
||||
platform_attrs["n_roms"] = len(fs.get_roms(platform_attrs["fs_slug"]))
|
||||
|
||||
return Platform(**platform_attrs)
|
||||
@@ -40,14 +52,24 @@ def scan_rom(
|
||||
p_slug = platform.fs_slug if platform.fs_slug else platform.slug
|
||||
roms_path = fs.get_roms_structure(p_slug)
|
||||
|
||||
log.info(f"\t · {r_igbd_id_search or rom_attrs['file_name']}")
|
||||
|
||||
if rom_attrs.get("multi", False):
|
||||
[log.info(f"\t\t · {file}") for file in rom_attrs["files"]]
|
||||
|
||||
if r_igbd_id_search:
|
||||
igdbh_rom = igdbh.get_rom_by_id(r_igbd_id_search)
|
||||
else:
|
||||
igdbh_rom = igdbh.get_rom(rom_attrs["file_name"], platform.igdb_id)
|
||||
|
||||
if not igdbh_rom:
|
||||
if not igdbh_rom["r_igdb_id"]:
|
||||
log.warning(
|
||||
f"\t {r_igbd_id_search or rom_attrs['file_name']} not found in IGDB"
|
||||
)
|
||||
return Rom(**rom_attrs)
|
||||
|
||||
log.info(emoji.emojize(f"\t Identified as {igdbh_rom['r_name']} :alien_monster:"))
|
||||
|
||||
rom_attrs.update(igdbh_rom)
|
||||
rom_attrs.update(
|
||||
fs.get_cover(
|
||||
|
||||
Reference in New Issue
Block a user