feat: added support for platform logos

This commit is contained in:
Michael Green
2023-04-09 23:45:48 +10:00
parent 913a7ad1e3
commit 36616caf7b
6 changed files with 62 additions and 14 deletions

View File

@@ -0,0 +1,40 @@
using System;
using gaseous_tools;
using IGDB;
using IGDB.Models;
using MySqlX.XDevAPI.Common;
using static gaseous_tools.Config.ConfigFile;
namespace gaseous_server.Classes.Metadata
{
public class PlatformLogos
{
public PlatformLogos()
{
}
private static IGDBClient igdb = new IGDBClient(
// Found in Twitch Developer portal for your app
Config.IGDB.ClientId,
Config.IGDB.Secret
);
public async static void GetPlatformLogo(long Id, string LogoPath)
{
var logo_results = await igdb.QueryAsync<PlatformLogo>(IGDBClient.Endpoints.PlatformLogos, query: "fields alpha_channel,animated,checksum,height,image_id,url,width; where id = " + Id + ";");
var logo_result = logo_results.First();
using (var client = new HttpClient())
{
using (var s = client.GetStreamAsync("https:" + logo_result.Url))
{
using (var fs = new FileStream(LogoPath, FileMode.OpenOrCreate))
{
s.Result.CopyTo(fs);
}
}
}
}
}
}