feat: initial support for metadata refresh
This commit is contained in:
@@ -134,7 +134,7 @@ namespace gaseous_server.Classes
|
||||
if (games.Length == 1)
|
||||
{
|
||||
// exact match!
|
||||
determinedGame = Metadata.Games.GetGame((long)games[0].Id);
|
||||
determinedGame = Metadata.Games.GetGame((long)games[0].Id, false);
|
||||
Logging.Log(Logging.LogType.Information, "Import Game", " IGDB game: " + determinedGame.Name);
|
||||
break;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ namespace gaseous_server.Classes
|
||||
|
||||
// get metadata
|
||||
IGDB.Models.Platform platform = gaseous_server.Classes.Metadata.Platforms.GetPlatform(rom.PlatformId);
|
||||
IGDB.Models.Game game = gaseous_server.Classes.Metadata.Games.GetGame(rom.GameId);
|
||||
IGDB.Models.Game game = gaseous_server.Classes.Metadata.Games.GetGame(rom.GameId, false);
|
||||
|
||||
// build path
|
||||
string platformSlug = "Unknown Platform";
|
||||
@@ -262,6 +262,8 @@ namespace gaseous_server.Classes
|
||||
|
||||
public static void OrganiseLibrary()
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "Organise Library", "Starting library organisation");
|
||||
|
||||
// move rom files to their new location
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string sql = "SELECT * FROM games_roms";
|
||||
@@ -271,6 +273,7 @@ namespace gaseous_server.Classes
|
||||
{
|
||||
foreach (DataRow dr in romDT.Rows)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "Organise Library", "Processing ROM " + dr["name"]);
|
||||
long RomId = (long)dr["id"];
|
||||
MoveGameFile(RomId);
|
||||
}
|
||||
@@ -278,6 +281,8 @@ namespace gaseous_server.Classes
|
||||
|
||||
// clean up empty directories
|
||||
processDirectory(Config.LibraryConfiguration.LibraryDataDirectory);
|
||||
|
||||
Logging.Log(Logging.LogType.Information, "Organise Library", "Finsihed library organisation");
|
||||
}
|
||||
|
||||
private static void processDirectory(string startLocation)
|
||||
|
@@ -20,7 +20,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
Config.IGDB.Secret
|
||||
);
|
||||
|
||||
public static Game? GetGame(long Id)
|
||||
public static Game? GetGame(long Id, bool followSubGames)
|
||||
{
|
||||
if (Id == 0)
|
||||
{
|
||||
@@ -28,18 +28,18 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.id, Id);
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.id, Id, followSubGames);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Game GetGame(string Slug)
|
||||
public static Game GetGame(string Slug, bool followSubGames)
|
||||
{
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.slug, Slug);
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.slug, Slug, followSubGames);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Game> _GetGame(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<Game> _GetGame(SearchUsing searchUsing, object searchValue, bool followSubGames = false)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
@@ -72,12 +72,12 @@ namespace gaseous_server.Classes.Metadata
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
UpdateSubClasses(returnValue);
|
||||
UpdateSubClasses(returnValue, followSubGames);
|
||||
return returnValue;
|
||||
case Storage.CacheStatus.Expired:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
UpdateSubClasses(returnValue);
|
||||
UpdateSubClasses(returnValue, followSubGames);
|
||||
return returnValue;
|
||||
case Storage.CacheStatus.Current:
|
||||
return Storage.GetCacheValue<Game>(returnValue, "id", (long)searchValue);
|
||||
@@ -86,7 +86,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateSubClasses(Game Game)
|
||||
private static void UpdateSubClasses(Game Game, bool followSubGames)
|
||||
{
|
||||
if (Game.Artworks != null)
|
||||
{
|
||||
@@ -95,6 +95,22 @@ namespace gaseous_server.Classes.Metadata
|
||||
Artwork GameArtwork = Artworks.GetArtwork(ArtworkId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(Game));
|
||||
}
|
||||
}
|
||||
if (followSubGames)
|
||||
{
|
||||
List<long> gamesToFetch = new List<long>();
|
||||
if (Game.Bundles != null) { gamesToFetch.AddRange(Game.Bundles.Ids); }
|
||||
if (Game.Dlcs != null) { gamesToFetch.AddRange(Game.Dlcs.Ids); }
|
||||
if (Game.Expansions != null) { gamesToFetch.AddRange(Game.Expansions.Ids); }
|
||||
if (Game.ParentGame != null) { gamesToFetch.Add((long)Game.ParentGame.Id); }
|
||||
if (Game.SimilarGames != null) { gamesToFetch.AddRange(Game.SimilarGames.Ids); }
|
||||
if (Game.StandaloneExpansions != null) { gamesToFetch.AddRange(Game.StandaloneExpansions.Ids); }
|
||||
if (Game.VersionParent != null) { gamesToFetch.Add((long)Game.VersionParent.Id); }
|
||||
|
||||
foreach (long gameId in gamesToFetch)
|
||||
{
|
||||
Game relatedGame = GetGame(gameId, false);
|
||||
}
|
||||
}
|
||||
if (Game.Cover != null)
|
||||
{
|
||||
Cover GameCover = Covers.GetCover(Game.Cover.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(Game));
|
||||
|
@@ -44,7 +44,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime CacheExpiryTime = DateTime.UtcNow.AddHours(-24);
|
||||
DateTime CacheExpiryTime = DateTime.UtcNow.AddHours(-168);
|
||||
if ((DateTime)dt.Rows[0]["lastUpdated"] < CacheExpiryTime)
|
||||
{
|
||||
return CacheStatus.Expired;
|
||||
|
23
gaseous-server/Classes/MetadataManagement.cs
Normal file
23
gaseous-server/Classes/MetadataManagement.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using gaseous_tools;
|
||||
|
||||
namespace gaseous_server.Classes
|
||||
{
|
||||
public class MetadataManagement
|
||||
{
|
||||
public static void RefreshMetadata()
|
||||
{
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
string sql = "SELECT id, `name` FROM game;";
|
||||
DataTable dt = db.ExecuteCMD(sql);
|
||||
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "Metadata Refresh", "Refreshing metadata for game " + dr["name"] + " (" + dr["id"] + ")");
|
||||
Metadata.Games.GetGame((long)dr["id"], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -69,6 +69,11 @@ namespace gaseous_server
|
||||
Logging.Log(Logging.LogType.Information, "Timered Event", "Starting Title Ingestor");
|
||||
Classes.ImportGames importGames = new Classes.ImportGames(Config.LibraryConfiguration.LibraryImportDirectory);
|
||||
break;
|
||||
|
||||
case QueueItemType.MetadataRefresh:
|
||||
Logging.Log(Logging.LogType.Information, "Timered Event", "Starting Metadata Refresher");
|
||||
Classes.MetadataManagement.RefreshMetadata();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -95,7 +100,8 @@ namespace gaseous_server
|
||||
{
|
||||
NotConfigured,
|
||||
SignatureIngestor,
|
||||
TitleIngestor
|
||||
TitleIngestor,
|
||||
MetadataRefresh
|
||||
}
|
||||
|
||||
public enum QueueItemState
|
||||
|
@@ -54,11 +54,12 @@ app.MapControllers();
|
||||
Config.LibraryConfiguration.InitLibrary();
|
||||
|
||||
// organise library
|
||||
gaseous_server.Classes.ImportGame.OrganiseLibrary();
|
||||
//gaseous_server.Classes.ImportGame.OrganiseLibrary();
|
||||
|
||||
// add background tasks
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.SignatureIngestor, 60));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.TitleIngestor, 1));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.MetadataRefresh, 360));
|
||||
|
||||
// start the app
|
||||
app.Run();
|
||||
|
Reference in New Issue
Block a user