From 721b5e8e7f5e59980bd51927544b2551944de3e1 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 4 Jan 2021 12:27:48 +0100 Subject: [PATCH] Get list of DLC function now checks if entered app is actually of type "game" --- auto-creamapi/Services/CacheService.cs | 114 ++++++++++++++----------- auto-creamapi/auto-creamapi.csproj | 10 +++ 2 files changed, 74 insertions(+), 50 deletions(-) diff --git a/auto-creamapi/Services/CacheService.cs b/auto-creamapi/Services/CacheService.cs index efacfd2..41a990d 100644 --- a/auto-creamapi/Services/CacheService.cs +++ b/auto-creamapi/Services/CacheService.cs @@ -100,81 +100,95 @@ namespace auto_creamapi.Services var dlcList = new List(); if (steamApp != null) { - var task = AppDetails.GetAsync(steamApp.AppId); - var steamAppDetails = await task; - steamAppDetails?.DLC.ForEach(x => + var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false); + if (steamAppDetails != null) { - var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)) ?? - new SteamApp {AppId = x, Name = $"Unknown DLC {x}"}; - dlcList.Add(result); - }); + MyLogger.Log.Debug($"Type for Steam App {steamApp.Name}: \"{steamAppDetails.Type}\""); + if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo") + { + steamAppDetails?.DLC.ForEach(x => + { + var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)) ?? + new SteamApp {AppId = x, Name = $"Unknown DLC {x}"}; + dlcList.Add(result); + }); - dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); - MyLogger.Log.Information("Got DLC successfully..."); + dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); + MyLogger.Log.Information("Got DLC successfully..."); - // Get DLC from SteamDB - // Get Cloudflare cookie - // Scrape and parse HTML page - // Add missing to DLC list - if (useSteamDb) - { - var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/"); + // Get DLC from SteamDB + // Get Cloudflare cookie + // Scrape and parse HTML page + // Add missing to DLC list + if (useSteamDb) + { + var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/"); - /* var handler = new ClearanceHandler(); + /* var handler = new ClearanceHandler(); var client = new HttpClient(handler); var content = client.GetStringAsync(steamDbUri).Result; MyLogger.Log.Debug(content); */ - var client = new HttpClient(); - client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); + var client = new HttpClient(); + client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); - MyLogger.Log.Information("Get SteamDB App"); - var httpCall = client.GetAsync(steamDbUri); - var response = await httpCall; - MyLogger.Log.Debug(httpCall.Status.ToString()); - MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString()); + MyLogger.Log.Information("Get SteamDB App"); + var httpCall = client.GetAsync(steamDbUri); + var response = await httpCall; + MyLogger.Log.Debug(httpCall.Status.ToString()); + MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString()); - var readAsStringAsync = response.Content.ReadAsStringAsync(); - var responseBody = await readAsStringAsync; - MyLogger.Log.Debug(readAsStringAsync.Status.ToString()); + var readAsStringAsync = response.Content.ReadAsStringAsync(); + var responseBody = await readAsStringAsync; + MyLogger.Log.Debug(readAsStringAsync.Status.ToString()); - var parser = new HtmlParser(); - var doc = parser.ParseDocument(responseBody); - // Console.WriteLine(doc.DocumentElement.OuterHtml); + var parser = new HtmlParser(); + var doc = parser.ParseDocument(responseBody); + // Console.WriteLine(doc.DocumentElement.OuterHtml); - var query1 = doc.QuerySelector("#dlc"); - if (query1 != null) - { - var query2 = query1.QuerySelectorAll(".app"); - foreach (var element in query2) - { - var dlcId = element.GetAttribute("data-appid"); - var dlcName = $"Unknown DLC {dlcId}"; - var query3 = element.QuerySelectorAll("td"); - if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim(); - - var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; - var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); - if (i > -1) + var query1 = doc.QuerySelector("#dlc"); + if (query1 != null) { - if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp; + var query2 = query1.QuerySelectorAll(".app"); + foreach (var element in query2) + { + var dlcId = element.GetAttribute("data-appid"); + var dlcName = $"Unknown DLC {dlcId}"; + var query3 = element.QuerySelectorAll("td"); + if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim(); + + var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName}; + var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId)); + if (i > -1) + { + if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp; + } + else + { + dlcList.Add(dlcApp); + } + } + + dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); + MyLogger.Log.Information("Got DLC from SteamDB successfully..."); } else { - dlcList.Add(dlcApp); + MyLogger.Log.Error("Could not get DLC from SteamDB!"); } } - - dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}")); - MyLogger.Log.Information("Got DLC from SteamDB successfully..."); } else { - MyLogger.Log.Error("Could not get DLC from SteamDB!"); + MyLogger.Log.Error("Could not get DLC: Steam App is not of type: \"Game\""); } } + else + { + MyLogger.Log.Error("Could not get DLC..."); + } } else { diff --git a/auto-creamapi/auto-creamapi.csproj b/auto-creamapi/auto-creamapi.csproj index e8531d5..1d0cc07 100644 --- a/auto-creamapi/auto-creamapi.csproj +++ b/auto-creamapi/auto-creamapi.csproj @@ -5,6 +5,16 @@ netcoreapp3.1 auto_creamapi true + 2.1.3 + auto-creamapi + Jeddunk + jeddunk.xyz + 2.1.3 + 2.1.3 + + + + none