Try to get DLC name if missing and not using SteamDB
This commit is contained in:
parent
1d69b7b45a
commit
8a4e601236
@ -111,85 +111,83 @@ namespace auto_creamapi.Services
|
|||||||
MyLogger.Log.Debug($"Type for Steam App {steamApp.Name}: \"{steamAppDetails.Type}\"");
|
MyLogger.Log.Debug($"Type for Steam App {steamApp.Name}: \"{steamAppDetails.Type}\"");
|
||||||
if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo")
|
if (steamAppDetails.Type == "game" | steamAppDetails.Type == "demo")
|
||||||
{
|
{
|
||||||
steamAppDetails?.DLC.ForEach(x =>
|
steamAppDetails.DLC.ForEach(x =>
|
||||||
{
|
{
|
||||||
var result = _cache.FirstOrDefault(y => y.AppId.Equals(x)) ??
|
var result = _cache.FirstOrDefault(y => y.AppId.Equals(x));
|
||||||
new SteamApp {AppId = x, Name = $"Unknown DLC {x}"};
|
if (result == null)
|
||||||
|
{
|
||||||
|
var dlcDetails = AppDetails.GetAsync(x).Result;
|
||||||
|
result = dlcDetails != null
|
||||||
|
? new SteamApp { AppId = dlcDetails.SteamAppId, Name = dlcDetails.Name }
|
||||||
|
: new SteamApp { AppId = x, Name = $"Unknown DLC {x}" };
|
||||||
|
}
|
||||||
|
|
||||||
dlcList.Add(result);
|
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...");
|
||||||
|
|
||||||
|
if (!useSteamDb) return dlcList;
|
||||||
|
|
||||||
// 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)
|
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;
|
||||||
|
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 parser = new HtmlParser();
|
||||||
|
var doc = parser.ParseDocument(responseBody);
|
||||||
|
// Console.WriteLine(doc.DocumentElement.OuterHtml);
|
||||||
|
|
||||||
|
var query1 = doc.QuerySelector("#dlc");
|
||||||
|
if (query1 != null)
|
||||||
{
|
{
|
||||||
var steamDbUri = new Uri($"https://steamdb.info/app/{steamApp.AppId}/dlc/");
|
var query2 = query1.QuerySelectorAll(".app");
|
||||||
|
foreach (var element in query2)
|
||||||
/* 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);
|
|
||||||
|
|
||||||
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 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");
|
var dlcId = element.GetAttribute("data-appid");
|
||||||
foreach (var element in query2)
|
var dlcName = $"Unknown DLC {dlcId}";
|
||||||
{
|
var query3 = element.QuerySelectorAll("td");
|
||||||
var dlcId = element.GetAttribute("data-appid");
|
if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim();
|
||||||
var dlcName = $"Unknown DLC {dlcId}";
|
|
||||||
var query3 = element.QuerySelectorAll("td");
|
|
||||||
if (query3 != null) dlcName = query3[1].Text().Replace("\n", "").Trim();
|
|
||||||
|
|
||||||
if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
|
if (ignoreUnknown && dlcName.Contains("SteamDB Unknown App"))
|
||||||
|
{
|
||||||
|
MyLogger.Log.Information($"Skipping SteamDB Unknown App {dlcId}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var dlcApp = new SteamApp {AppId = Convert.ToInt32(dlcId), Name = dlcName};
|
||||||
|
var i = dlcList.FindIndex(x => x.AppId.Equals(dlcApp.AppId));
|
||||||
|
if (i > -1)
|
||||||
{
|
{
|
||||||
MyLogger.Log.Information($"Skipping SteamDB Unknown App {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($"{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($"{x.AppId}={x.Name}"));
|
||||||
|
MyLogger.Log.Information("Got DLC from SteamDB successfully...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MyLogger.Log.Error("Could not get DLC from SteamDB!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
xmlns:vm="clr-namespace:auto_creamapi.ViewModels"
|
xmlns:vm="clr-namespace:auto_creamapi.ViewModels"
|
||||||
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
|
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
|
||||||
xmlns:converters="clr-namespace:auto_creamapi.Converters"
|
xmlns:converters="clr-namespace:auto_creamapi.Converters"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="720" d:DesignWidth="560">
|
||||||
<views:MvxWpfView.Resources>
|
<views:MvxWpfView.Resources>
|
||||||
<converters:ListOfDLcToStringNativeConverter x:Key="DlcConv" />
|
<converters:ListOfDLcToStringNativeConverter x:Key="DlcConv" />
|
||||||
</views:MvxWpfView.Resources>
|
</views:MvxWpfView.Resources>
|
||||||
@ -27,7 +28,7 @@
|
|||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<wcl:WatermarkTextBox Text="{Binding DllPath}" Watermark="Path to game's steam_api(64).dll..."
|
<wcl:WatermarkTextBox Text="{Binding DllPath}" Watermark="Path to game's steam_api(64).dll..."
|
||||||
Margin="10,11,55,0" TextWrapping="NoWrap" VerticalAlignment="Top" Padding="0"
|
Margin="10,10,55,0" TextWrapping="NoWrap" VerticalAlignment="Top" Padding="0"
|
||||||
Grid.Row="0" IsReadOnly="True" IsReadOnlyCaretVisible="True">
|
Grid.Row="0" IsReadOnly="True" IsReadOnlyCaretVisible="True">
|
||||||
<!--MouseDoubleClick="{Binding Path=OpenFileCommand}"-->
|
<!--MouseDoubleClick="{Binding Path=OpenFileCommand}"-->
|
||||||
<wcl:WatermarkTextBox.InputBindings>
|
<wcl:WatermarkTextBox.InputBindings>
|
||||||
@ -95,7 +96,7 @@
|
|||||||
Text="{Binding Dlcs, Converter={StaticResource DlcConv}, Mode=TwoWay}"
|
Text="{Binding Dlcs, Converter={StaticResource DlcConv}, Mode=TwoWay}"
|
||||||
Margin="10,10,10,0" Watermark="List of DLCs...
0000 = DLC Name"
|
Margin="10,10,10,0" Watermark="List of DLCs...
0000 = DLC Name"
|
||||||
TextWrapping="Wrap" AcceptsReturn="True"
|
TextWrapping="Wrap" AcceptsReturn="True"
|
||||||
VerticalScrollBarVisibility="Visible" Padding="0"
|
VerticalScrollBarVisibility="Visible" Padding="5,5,5,5"
|
||||||
FontFamily="../resources/#Courier Prime" Grid.Row="3" />
|
FontFamily="../resources/#Courier Prime" Grid.Row="3" />
|
||||||
<Button Content="Get DLCs for AppID" Margin="0,10,10,10" Height="19.96" HorizontalAlignment="Right"
|
<Button Content="Get DLCs for AppID" Margin="0,10,10,10" Height="19.96" HorizontalAlignment="Right"
|
||||||
VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="4" />
|
VerticalAlignment="Bottom" Width="108" Command="{Binding GetListOfDlcCommand}" Grid.Row="4" />
|
||||||
|
Loading…
Reference in New Issue
Block a user