private async Task <Game> ToGameAsync( Orbital7.Apis.IGDB.IGDBApiClient apiClient, Orbital7.Apis.IGDB.Game scrapedGame) { // Get the cover. if (scrapedGame.cover.HasValue) { var scrapedCovers = await apiClient.QueryCoversAsync( fields : "image_id", where : $"id = {scrapedGame.cover.Value}"); if (scrapedCovers.Count > 0) { // Create the game. Game game = new Game(); game.ID = scrapedGame.id.ToString(); game.Name = scrapedGame.name; game.Description = scrapedGame.summary; game.Rating = scrapedGame.total_rating.HasValue ? Math.Round(scrapedGame.total_rating.Value / 10, 1) : 0; //base.SetGameReleaseDate(game, gameNode.GetNodeValue("original_release_date")); base.SetGameImage(game, apiClient.GetImageJpegUrl( scrapedCovers[0].image_id, Apis.IGDB.ImageSizeType.t_720p)); return(game); } } return(null); }
private async Task <List <Game> > PerformSearchAsync( Platform platform, string gameName, bool isExact) { // Retrieve API key (to get a key, visit https://api.igdb.com/). string apiKeyFilePath = Path.Combine(this.ConfigFolderPath, "IGDBAPIKey.txt"); if (!File.Exists(apiKeyFilePath)) { throw new Exception("File containing IGDB API Key not found at: " + apiKeyFilePath); } var apiKeyContents = File.ReadAllText(apiKeyFilePath); var apiKeyLines = apiKeyContents.ParseLines(); // Search. var apiClient = new Orbital7.Apis.IGDB.IGDBApiClient( apiKeyLines[0], apiKeyLines[1]); var scrapedGames = await apiClient.QueryGamesAsync( fields : "cover,id,name,summary,total_rating", search : gameName, where : $"platforms = ({GetPlatformId(platform)})"); var games = new List <Game>(); if (scrapedGames.Count > 0) { if (isExact) { var game = await ToGameAsync( apiClient, scrapedGames[0]); if (game != null) { games.Add(game); } } else { foreach (var scrapedGame in scrapedGames) { var game = await ToGameAsync( apiClient, scrapedGame); if (game != null) { games.Add(game); } } } } return(games); }