Compare commits
No commits in common. "0005f3d74b1d85f77cea0065cfd7331a2b25f856" and "3c736674acff48559f6f2941c861ea4ad939739e" have entirely different histories.
0005f3d74b
...
3c736674ac
@ -101,117 +101,105 @@ namespace auto_creamapi.Services
|
|||||||
|
|
||||||
public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown)
|
public async Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb, bool ignoreUnknown)
|
||||||
{
|
{
|
||||||
MyLogger.Log.Debug("Start: GetListOfDlc");
|
MyLogger.Log.Information("Get DLC");
|
||||||
var dlcList = new List<SteamApp>();
|
var dlcList = new List<SteamApp>();
|
||||||
try
|
if (steamApp != null)
|
||||||
{
|
{
|
||||||
if (steamApp != null)
|
var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false);
|
||||||
|
if (steamAppDetails != null)
|
||||||
{
|
{
|
||||||
var steamAppDetails = await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false);
|
MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name, steamAppDetails.Type);
|
||||||
if (steamAppDetails != null)
|
if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo")
|
||||||
{
|
{
|
||||||
MyLogger.Log.Debug("Type for Steam App {Name}: \"{Type}\"", steamApp.Name,
|
steamAppDetails.DLC.ForEach(x =>
|
||||||
steamAppDetails.Type);
|
|
||||||
if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo")
|
|
||||||
{
|
{
|
||||||
steamAppDetails.DLC.ForEach(x =>
|
var result = _cache.FirstOrDefault(y => y.AppId.Equals(x));
|
||||||
|
if (result == null) return;
|
||||||
|
var dlcDetails = AppDetails.GetAsync(x).Result;
|
||||||
|
dlcList.Add(dlcDetails != null
|
||||||
|
? new SteamApp { AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name }
|
||||||
|
: new SteamApp { AppId = x, Name = $"Unknown DLC {x}" });
|
||||||
|
});
|
||||||
|
|
||||||
|
dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name));
|
||||||
|
MyLogger.Log.Information("Got DLC successfully...");
|
||||||
|
|
||||||
|
if (!useSteamDb) return dlcList;
|
||||||
|
|
||||||
|
// Get DLC from SteamDB
|
||||||
|
// Get Cloudflare cookie
|
||||||
|
// Scrape and parse HTML page
|
||||||
|
// Add missing to DLC list
|
||||||
|
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
|
||||||
|
|
||||||
|
var client = new HttpClient();
|
||||||
|
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
||||||
|
|
||||||
|
MyLogger.Log.Information("Get SteamDB App");
|
||||||
|
var httpCall = client.GetAsync(steamDbUri);
|
||||||
|
var response = await httpCall.ConfigureAwait(false);
|
||||||
|
MyLogger.Log.Debug("{Status}", httpCall.Status.ToString());
|
||||||
|
MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString());
|
||||||
|
|
||||||
|
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
||||||
|
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
||||||
|
MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString());
|
||||||
|
|
||||||
|
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 result = _cache.FirstOrDefault(y => y.AppId.Equals(x));
|
var dlcId = element.GetAttribute("data-appid");
|
||||||
if (result == null) return;
|
var query3 = element.QuerySelectorAll("td");
|
||||||
var dlcDetails = AppDetails.GetAsync(x).Result;
|
var dlcName = query3 == null
|
||||||
dlcList.Add(dlcDetails != null
|
? $"Unknown DLC {dlcId}"
|
||||||
? new SteamApp {AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name}
|
: query3[1].Text().Replace("\n", "").Trim();
|
||||||
: new SteamApp {AppId = x, Name = $"Unknown DLC {x}"});
|
|
||||||
});
|
|
||||||
|
|
||||||
dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name));
|
if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
|
||||||
MyLogger.Log.Information("Got DLC successfully...");
|
|
||||||
|
|
||||||
if (!useSteamDb) return dlcList;
|
|
||||||
|
|
||||||
// Get DLC from SteamDB
|
|
||||||
// Get Cloudflare cookie
|
|
||||||
// Scrape and parse HTML page
|
|
||||||
// Add missing to DLC list
|
|
||||||
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
|
|
||||||
|
|
||||||
var client = new HttpClient();
|
|
||||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
|
|
||||||
|
|
||||||
MyLogger.Log.Information("Get SteamDB App");
|
|
||||||
var httpCall = client.GetAsync(steamDbUri);
|
|
||||||
var response = await httpCall.ConfigureAwait(false);
|
|
||||||
MyLogger.Log.Debug("{Status}", httpCall.Status.ToString());
|
|
||||||
MyLogger.Log.Debug("{Boolean}", response.EnsureSuccessStatusCode().ToString());
|
|
||||||
|
|
||||||
var readAsStringAsync = response.Content.ReadAsStringAsync();
|
|
||||||
var responseBody = await readAsStringAsync.ConfigureAwait(false);
|
|
||||||
MyLogger.Log.Debug("{Status}", readAsStringAsync.Status.ToString());
|
|
||||||
|
|
||||||
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");
|
MyLogger.Log.Information("Skipping SteamDB Unknown App {DlcId}", dlcId);
|
||||||
var query3 = element.QuerySelectorAll("td");
|
}
|
||||||
var dlcName = query3 == null
|
else
|
||||||
? $"Unknown DLC {dlcId}"
|
{
|
||||||
: 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 (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
|
if (i > -1)
|
||||||
{
|
{
|
||||||
MyLogger.Log.Information("Skipping SteamDB Unknown App {DlcId}", dlcId);
|
if (dlcList[i].Name.Contains("Unknown DLC")) dlcList[i] = dlcApp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
|
dlcList.Add(dlcApp);
|
||||||
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("{AppId}={Name}", x.AppId, x.Name));
|
|
||||||
MyLogger.Log.Information("Got DLC from SteamDB successfully...");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MyLogger.Log.Error("Could not get DLC from SteamDB!");
|
|
||||||
}
|
}
|
||||||
|
dlcList.ForEach(x => MyLogger.Log.Debug("{AppId}={Name}", x.AppId, x.Name));
|
||||||
|
MyLogger.Log.Information("Got DLC from SteamDB successfully...");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MyLogger.Log.Error("Could not get DLC: Steam App is not of type: \"Game\"");
|
MyLogger.Log.Error("Could not get DLC from SteamDB!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MyLogger.Log.Error("Could not get DLC: Could not get Steam App details");
|
MyLogger.Log.Error("Could not get DLC: Steam App is not of type: \"Game\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MyLogger.Log.Error("Could not get DLC: Invalid Steam App");
|
MyLogger.Log.Error("Could not get DLC...");
|
||||||
}
|
}
|
||||||
|
|
||||||
//return dlcList;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
else
|
||||||
{
|
{
|
||||||
MyLogger.Log.Error("Could not get DLC!");
|
MyLogger.Log.Error("Could not get DLC: Invalid Steam App");
|
||||||
Console.WriteLine(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dlcList;
|
return dlcList;
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
<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.7</PackageVersion>
|
<PackageVersion>2.1.6</PackageVersion>
|
||||||
<Title>auto-creamapi</Title>
|
<Title>auto-creamapi</Title>
|
||||||
<Authors>Jeddunk</Authors>
|
<Authors>Jeddunk</Authors>
|
||||||
<Company>jeddunk.xyz</Company>
|
<Company>jeddunk.xyz</Company>
|
||||||
<AssemblyVersion>2.1.7</AssemblyVersion>
|
<AssemblyVersion>2.1.6</AssemblyVersion>
|
||||||
<FileVersion>2.1.7</FileVersion>
|
<FileVersion>2.1.6</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
Loading…
Reference in New Issue
Block a user