Ejemplo n.º 1
0
 public MetadataController(UpdatableAppSettings settings, IgdbApi igdbApi)
 {
     this.settings      = settings;
     this.igdbApi       = igdbApi;
     gamesController    = new GamesController(settings, igdbApi);
     expandedController = new ExpandedGameController(settings, igdbApi);
     parsedController   = new GameParsedController(settings, igdbApi);
 }
Ejemplo n.º 2
0
        public async Task <ServicesResponse <ExpandedGame> > Post([FromBody] SdkModels.Game game)
        {
            var   isKnownPlugin = game.PluginId != Guid.Empty;
            var   isSteamPlugin = BuiltinExtensions.GetIdFromExtension(BuiltinExtension.SteamLibrary) == game.PluginId;
            ulong igdbId        = 0;
            var   matchId       = $"{game.GameId}{game.PluginId}".MD5();
            var   searchId      = $"{game.Name}{game.ReleaseDate?.Year}".MD5();

            logger.Debug($"IGDB metadata: {game.GameId},{game.Name},{game.PluginId},{game.ReleaseDate}");

            // Check if match was previously found
            if (isKnownPlugin)
            {
                if (isSteamPlugin)
                {
                    igdbId = await GamesBySteamIdController.GetIgdbMatch(ulong.Parse(game.GameId));
                }
                else
                {
                    var match = Database.IGBDGameIdMatches.FindById(matchId);
                    if (match != null)
                    {
                        igdbId = match.IgdbId;
                    }
                }
            }

            if (igdbId == 0)
            {
                var match = Database.IGDBSearchIdMatches.FindById(searchId);
                if (match != null)
                {
                    igdbId = match.IgdbId;
                }
            }

            var foundMetadata = new ExpandedGame();

            if (igdbId != 0)
            {
                return(new ServicesResponse <ExpandedGame>(await GameParsedController.GetExpandedGame(igdbId)));
            }
            else
            {
                igdbId = await TryMatchGame(game);

                if (igdbId != 0)
                {
                    foundMetadata = await GameParsedController.GetExpandedGame(igdbId);
                }
            }

            // Update match database if match was found
            if (igdbId != 0)
            {
                if (isKnownPlugin && !isSteamPlugin)
                {
                    Database.IGBDGameIdMatches.Upsert(new GameIdMatch
                    {
                        GameId  = game.GameId,
                        Id      = matchId,
                        IgdbId  = igdbId,
                        Library = game.PluginId
                    });
                }

                Database.IGDBSearchIdMatches.Upsert(new SearchIdMatch
                {
                    Term   = game.Name,
                    Id     = searchId,
                    IgdbId = igdbId
                });
            }

            return(new ServicesResponse <ExpandedGame>(foundMetadata));
        }