Get list of DLC function now checks if entered app is actually of type "game"
This commit is contained in:
parent
d71144b1d6
commit
721b5e8e7f
@ -100,81 +100,95 @@ namespace auto_creamapi.Services
|
|||||||
var dlcList = new List<SteamApp>();
|
var dlcList = new List<SteamApp>();
|
||||||
if (steamApp != null)
|
if (steamApp != null)
|
||||||
{
|
{
|
||||||
var task = AppDetails.GetAsync(steamApp.AppId);
|
var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false);
|
||||||
var steamAppDetails = await task;
|
if (steamAppDetails != null)
|
||||||
steamAppDetails?.DLC.ForEach(x =>
|
|
||||||
{
|
{
|
||||||
var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)) ??
|
MyLogger.Log.Debug($"Type for Steam App {steamApp.Name}: \"{steamAppDetails.Type}\"");
|
||||||
new SteamApp {AppId = x, Name = $"Unknown DLC {x}"};
|
if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo")
|
||||||
dlcList.Add(result);
|
{
|
||||||
});
|
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}"));
|
dlcList.ForEach(x => MyLogger.Log.Debug($"{x.AppId}={x.Name}"));
|
||||||
MyLogger.Log.Information("Got DLC successfully...");
|
MyLogger.Log.Information("Got DLC successfully...");
|
||||||
|
|
||||||
// Get DLC from SteamDB
|
// Get DLC from SteamDB
|
||||||
// Get Cloudflare cookie
|
// Get Cloudflare cookie
|
||||||
// Scrape and parse HTML page
|
// Scrape and parse HTML page
|
||||||
// Add missing to DLC list
|
// Add missing to DLC list
|
||||||
if (useSteamDb)
|
if (useSteamDb)
|
||||||
{
|
{
|
||||||
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
|
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 client = new HttpClient(handler);
|
||||||
|
|
||||||
var content = client.GetStringAsync(steamDbUri).Result;
|
var content = client.GetStringAsync(steamDbUri).Result;
|
||||||
MyLogger.Log.Debug(content); */
|
MyLogger.Log.Debug(content); */
|
||||||
|
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
||||||
|
|
||||||
MyLogger.Log.Information("Get SteamDB App");
|
MyLogger.Log.Information("Get SteamDB App");
|
||||||
var httpCall = client.GetAsync(steamDbUri);
|
var httpCall = client.GetAsync(steamDbUri);
|
||||||
var response = await httpCall;
|
var response = await httpCall;
|
||||||
MyLogger.Log.Debug(httpCall.Status.ToString());
|
MyLogger.Log.Debug(httpCall.Status.ToString());
|
||||||
MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString());
|
MyLogger.Log.Debug(response.EnsureSuccessStatusCode().ToString());
|
||||||
|
|
||||||
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
||||||
var responseBody = await readAsStringAsync;
|
var responseBody = await readAsStringAsync;
|
||||||
MyLogger.Log.Debug(readAsStringAsync.Status.ToString());
|
MyLogger.Log.Debug(readAsStringAsync.Status.ToString());
|
||||||
|
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
var doc = parser.ParseDocument(responseBody);
|
var doc = parser.ParseDocument(responseBody);
|
||||||
// Console.WriteLine(doc.DocumentElement.OuterHtml);
|
// Console.WriteLine(doc.DocumentElement.OuterHtml);
|
||||||
|
|
||||||
var query1 = doc.QuerySelector("#dlc");
|
var query1 = doc.QuerySelector("#dlc");
|
||||||
if (query1 != null)
|
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)
|
|
||||||
{
|
{
|
||||||
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
|
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
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,16 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<RootNamespace>auto_creamapi</RootNamespace>
|
<RootNamespace>auto_creamapi</RootNamespace>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
|
<PackageVersion>2.1.3</PackageVersion>
|
||||||
|
<Title>auto-creamapi</Title>
|
||||||
|
<Authors>Jeddunk</Authors>
|
||||||
|
<Company>jeddunk.xyz</Company>
|
||||||
|
<AssemblyVersion>2.1.3</AssemblyVersion>
|
||||||
|
<FileVersion>2.1.3</FileVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<DebugType>none</DebugType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user