public async Task QuerySearchTest() { using (var client = new WebStoreClient()) { var catalogs = await client.QuerySearch("thimb"); CollectionAssert.IsNotEmpty(catalogs); var catalog = catalogs[0]; Assert.IsNotEmpty(catalog.productSlug); Assert.IsNotEmpty(catalog.title); } }
public async Task GetProductInfoTest() { using (var client = new WebStoreClient()) { var catalogs = await client.QuerySearch("thimb"); var product = await client.GetProductInfo(catalogs[0].productSlug); Assert.IsNotEmpty(product.@namespace); Assert.IsNotEmpty(product.pages[0].data.hero.backgroundImageUrl); Assert.IsNotEmpty(product.pages[0].data.about.description); Assert.IsNotEmpty(product.pages[0].data.about.developerAttribution); } }
public override GameMetadata GetMetadata(Game game) { var gameInfo = new GameInfo() { Links = new List <Link>() }; var metadata = new GameMetadata() { GameInfo = gameInfo }; using (var client = new WebStoreClient()) { var catalogs = client.QuerySearch(game.Name).GetAwaiter().GetResult(); if (catalogs.HasItems()) { var catalog = catalogs.FirstOrDefault(a => a.title.Equals(game.Name, StringComparison.InvariantCultureIgnoreCase)); if (catalog == null) { catalog = catalogs[0]; } var product = client.GetProductInfo(catalog.productSlug).GetAwaiter().GetResult(); if (product.pages.HasItems()) { var page = product.pages.FirstOrDefault(a => a.type is string type && type == "productHome"); if (page == null) { page = product.pages[0]; } gameInfo.Developers = page.data.about.developerAttribution?. Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(a => a.Trim()).ToList(); gameInfo.Publishers = page.data.about.publisherAttribution?. Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(a => a.Trim()).ToList(); metadata.BackgroundImage = new MetadataFile(page.data.hero.backgroundImageUrl); gameInfo.Links.Add(new Link( library.PlayniteApi.Resources.GetString("LOCCommonLinksStorePage"), "https://www.epicgames.com/store/en-US/product/" + catalog.productSlug)); if (page.data.socialLinks.HasItems()) { var links = page.data.socialLinks. Where(a => a.Key.StartsWith("link") && !a.Value.IsNullOrEmpty()). Select(a => new Link(a.Key.Replace("link", ""), a.Value)).ToList(); if (links.HasItems()) { gameInfo.Links.AddRange(links); } } if (!page.data.about.description.IsNullOrEmpty()) { gameInfo.Description = Markup.MarkdownToHtml(page.data.about.description); } } } } gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)); // There's not icon available on Epic servers so we will load one from EXE if (game.IsInstalled && string.IsNullOrEmpty(game.Icon)) { var manifest = EpicLauncher.GetInstalledManifests().FirstOrDefault(a => a.AppName == game.GameId); if (manifest != null) { var exePath = Path.Combine(manifest.InstallLocation, manifest.LaunchExecutable); if (File.Exists(exePath)) { using (var ms = new MemoryStream()) { if (IconExtractor.ExtractMainIconFromFile(exePath, ms)) { var iconName = Guid.NewGuid() + ".ico"; metadata.Icon = new MetadataFile(iconName, ms.ToArray()); } } } } } return(metadata); }
public override GameMetadata GetMetadata(Game game) { var gameInfo = new GameInfo() { Links = new List <Link>() }; var metadata = new GameMetadata() { GameInfo = gameInfo }; using (var client = new WebStoreClient()) { var catalogs = client.QuerySearch(game.Name).GetAwaiter().GetResult(); if (catalogs.HasItems()) { var product = client.GetProductInfo(catalogs[0].productSlug).GetAwaiter().GetResult(); if (product.pages.HasItems()) { var page = product.pages[0]; gameInfo.Description = page.data.about.description; gameInfo.Developers = new List <string>() { page.data.about.developerAttribution }; metadata.BackgroundImage = new MetadataFile(page.data.hero.backgroundImageUrl); gameInfo.Links.Add(new Link( library.PlayniteApi.Resources.GetString("LOCCommonLinksStorePage"), "https://www.epicgames.com/store/en-US/product/" + catalogs[0].productSlug)); if (page.data.socialLinks.HasItems()) { var links = page.data.socialLinks. Where(a => a.Key.StartsWith("link") && !a.Value.IsNullOrEmpty()). Select(a => new Link(a.Key.Replace("link", ""), a.Value)).ToList(); if (links.HasItems()) { gameInfo.Links.AddRange(links); } } if (!gameInfo.Description.IsNullOrEmpty()) { gameInfo.Description = gameInfo.Description.Replace("\n", "\n<br>"); } } } } gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)); // There's not icon available on Epic servers so we will load one from EXE if (game.IsInstalled && string.IsNullOrEmpty(game.Icon)) { var playAction = api.ExpandGameVariables(game, game.PlayAction); var executable = string.Empty; if (File.Exists(playAction.Path)) { executable = playAction.Path; } else if (!string.IsNullOrEmpty(playAction.WorkingDir)) { executable = Path.Combine(playAction.WorkingDir, playAction.Path); } var exeIcon = IconExtension.ExtractIconFromExe(executable, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } } return(metadata); }