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