JMBeresford / retrom

A centralized game library/collection management service with a focus on emulation
GNU General Public License v3.0
677 stars 10 forks source link

Metadata System Overhaul - New providers and caching of metadata #102

Open JMBeresford opened 1 month ago

JMBeresford commented 1 month ago

Tasks:

In preparation of adding additional metadata providers, the current implementation of fetching metadata should be refactored to be more generic.

A trait such as the following would be a good jumping off point:

pub trait MetadataProvider<PlatformMeta, GameMeta> {
  pub fn searchGameMetadata(game: retrom_codegen::Game) -> Option<GameMeta[]> {
    // default impl returns None, as not all providers will support all types of metadata
    return None;
  }

  pub fn searchPlatformMetadata(platform: retrom_codegen::Platform) -> Option<PlatformMeta[]> {
    return None;
  }

  // etc
}

Then, we could impl this trait for given providers:

pub struct IGDBMetadataProvider;

impl MetadataProvider<igdb::Platform, igdb::Game> for IGDBMetadataProvider {
  pub fn searchGameMetadata(game: retrom_codegen::Game) -> Option<igdb::Game[]> {
    // fetch meta, sort as/if needed, etc
    let metadata = self.do_the_thing(game);

    return Some(metadata);
  }

  // etc
}
GiFuJo commented 1 month ago

Would this approach allow for using the app without an external metadata provider? I'd like to provide all the metadata myself, but an api key for IGDB seems to be requirement for running the server currently.

JMBeresford commented 1 month ago

@GiFuJo you can set the IGDB credentials to empty strings to run without IGDB support. You can still edit metadata manually, but note that this is not fully featured yet.

The change detailed in this issue will also enable local media for metadata, which is currently not possible (externals URLs are needed for images).