From 739453c8bc20a58edd0532812998729df272f75e Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Thu, 2 Nov 2023 23:37:10 -0500 Subject: [PATCH] Pull media for Playnite from LANCommander server if it exists --- .../LANCommanderClient.cs | 5 +++++ .../LANCommanderLibraryPlugin.cs | 9 +++++++++ LANCommander.SDK/Enums/MediaType.cs | 13 +++++++++++++ LANCommander.SDK/Models/Game.cs | 1 + LANCommander.SDK/Models/Media.cs | 15 +++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 LANCommander.SDK/Enums/MediaType.cs create mode 100644 LANCommander.SDK/Models/Media.cs diff --git a/LANCommander.Playnite.Extension/LANCommanderClient.cs b/LANCommander.Playnite.Extension/LANCommanderClient.cs index b5ecce6..e2cdfd1 100644 --- a/LANCommander.Playnite.Extension/LANCommanderClient.cs +++ b/LANCommander.Playnite.Extension/LANCommanderClient.cs @@ -235,6 +235,11 @@ namespace LANCommander.PlaynitePlugin return response.Data; } + public string GetMediaUrl(Media media) + { + return (new Uri(Client.BaseUrl, $"/api/Media/{media.Id}/Download?fileId={media.FileId}").ToString()); + } + public string GetKey(Guid id) { Logger.Trace("Requesting key allocation..."); diff --git a/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs b/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs index d444245..a5cf79f 100644 --- a/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs +++ b/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs @@ -183,6 +183,15 @@ namespace LANCommander.PlaynitePlugin if (manifest.OnlineMultiplayer != null) metadata.Features.Add(new MetadataNameProperty($"Online Multiplayer {manifest.OnlineMultiplayer.GetPlayerCount()}".Trim())); + if (game.Media.Any(m => m.Type == SDK.Enums.MediaType.Icon)) + metadata.Icon = new MetadataFile(LANCommander.GetMediaUrl(game.Media.First(m => m.Type == SDK.Enums.MediaType.Icon))); + + if (game.Media.Any(m => m.Type == SDK.Enums.MediaType.Cover)) + metadata.CoverImage = new MetadataFile(LANCommander.GetMediaUrl(game.Media.First(m => m.Type == SDK.Enums.MediaType.Cover))); + + if (game.Media.Any(m => m.Type == SDK.Enums.MediaType.Background)) + metadata.BackgroundImage = new MetadataFile(LANCommander.GetMediaUrl(game.Media.First(m => m.Type == SDK.Enums.MediaType.Background))); + gameMetadata.Add(metadata); } catch (Exception ex) diff --git a/LANCommander.SDK/Enums/MediaType.cs b/LANCommander.SDK/Enums/MediaType.cs new file mode 100644 index 0000000..d5283ba --- /dev/null +++ b/LANCommander.SDK/Enums/MediaType.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace LANCommander.SDK.Enums +{ + public enum MediaType + { + Icon, + Cover, + Background + } +} diff --git a/LANCommander.SDK/Models/Game.cs b/LANCommander.SDK/Models/Game.cs index 39e102e..d13737b 100644 --- a/LANCommander.SDK/Models/Game.cs +++ b/LANCommander.SDK/Models/Game.cs @@ -16,6 +16,7 @@ namespace LANCommander.SDK.Models public virtual Company Developer { get; set; } public virtual IEnumerable Archives { get; set; } public virtual IEnumerable