initial commit
This commit is contained in:
commit
c4f57e6526
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea/
|
||||||
71
Program.cs
Normal file
71
Program.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using Fizzler.Systems.HtmlAgilityPack;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using DTLib.Console;
|
||||||
|
using File = DTLib.Filesystem.File;
|
||||||
|
using Directory = DTLib.Filesystem.Directory;
|
||||||
|
|
||||||
|
List<string> pageTexts=new List<string>();
|
||||||
|
string separator = "\n";
|
||||||
|
Action<string>? selectedTarget = null;
|
||||||
|
// file url separator
|
||||||
|
new LaunchArgumentParser(
|
||||||
|
new LaunchArgument(new []{"file"}, "loads local html page", LoadLocalPage, "file_path"),
|
||||||
|
new LaunchArgument(new []{"dir"}, "loads html pages from local directory", LoadLocalDir, "dir_path"),
|
||||||
|
new LaunchArgument(new []{"url"}, "downloads html page from a website", DownloadPage, "url"),
|
||||||
|
new LaunchArgument(new []{"col","collection"}, "parses workshop collection page", ()=>selectedTarget=ParseCollection),
|
||||||
|
new LaunchArgument(new []{"sub","subscriptions"}, "parses workshop subscriptions page", ()=>selectedTarget=ParseSubscriptions)
|
||||||
|
).ParseAndHandle(args);
|
||||||
|
if (selectedTarget is null)
|
||||||
|
throw new Exception("no action selected");
|
||||||
|
if (pageTexts.Count==0)
|
||||||
|
throw new Exception("no page path set");
|
||||||
|
foreach (string pageText in pageTexts)
|
||||||
|
selectedTarget(pageText);
|
||||||
|
|
||||||
|
void LoadLocalPage(string path)
|
||||||
|
{
|
||||||
|
pageTexts.Add(File.ReadAllText(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadLocalDir(string path)
|
||||||
|
{
|
||||||
|
foreach (var f in Directory.GetAllFiles(path))
|
||||||
|
{
|
||||||
|
string text = File.ReadAllText(f);
|
||||||
|
if(text.StartsWith("<!DOCTYPE html>"))
|
||||||
|
pageTexts.Add(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void DownloadPage(string collectionUrl)
|
||||||
|
{
|
||||||
|
var http = new HttpClient();
|
||||||
|
pageTexts.Add(http.GetStringAsync(collectionUrl).GetAwaiter().GetResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParseCollection(string pageText)
|
||||||
|
{
|
||||||
|
var page = new HtmlDocument();
|
||||||
|
page.LoadHtml(pageText);
|
||||||
|
var collectionItems = page.DocumentNode.QuerySelectorAll(".collectionItem");
|
||||||
|
var ids = collectionItems.Select(n => n.Id.Remove(0, n.Id.LastIndexOf('_') + 1));
|
||||||
|
string rezult = string.Join(separator, ids);
|
||||||
|
Console.WriteLine(rezult);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParseSubscriptions(string pageText)
|
||||||
|
{
|
||||||
|
var page = new HtmlDocument();
|
||||||
|
page.LoadHtml(pageText);
|
||||||
|
var collectionItems = page.DocumentNode.QuerySelectorAll(".workshopItemSubscriptionDetails");
|
||||||
|
var ids = collectionItems.Select(n => GetSubscriptionId(n));
|
||||||
|
string rezult = string.Join(separator, ids);
|
||||||
|
Console.WriteLine(rezult);
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetSubscriptionId(HtmlNode n)
|
||||||
|
{
|
||||||
|
HtmlNode a = n.ChildNodes.First(sn => sn.Name == "a");
|
||||||
|
HtmlAttribute href = a.Attributes.First(a => a.Name == "href");
|
||||||
|
string url = href.Value;
|
||||||
|
return url.Replace("https://steamcommunity.com/sharedfiles/filedetails/?id=", "");
|
||||||
|
}
|
||||||
16
SteamCollectionParser.csproj
Normal file
16
SteamCollectionParser.csproj
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="DTLib" Version="1.0.3" />
|
||||||
|
<PackageReference Include="Fizzler" Version="1.3.0" />
|
||||||
|
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
16
SteamCollectionParser.sln
Normal file
16
SteamCollectionParser.sln
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamCollectionParser", "SteamCollectionParser.csproj", "{78F88A9F-9B63-405A-B71A-79EBA263CAFA}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{78F88A9F-9B63-405A-B71A-79EBA263CAFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{78F88A9F-9B63-405A-B71A-79EBA263CAFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{78F88A9F-9B63-405A-B71A-79EBA263CAFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{78F88A9F-9B63-405A-B71A-79EBA263CAFA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Loading…
Reference in New Issue
Block a user