Make constants per-site

This commit is contained in:
Matt Nadareski
2026-06-14 19:50:06 -04:00
parent d2434f9ceb
commit 89fa29685a
10 changed files with 231 additions and 31 deletions

View File

@@ -4,7 +4,6 @@ using System.Threading.Tasks;
using SabreTools.CommandLine.Inputs;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpOrg;
using SabreTools.RedumpLib.RedumpOrg.Data;
namespace RedumpTool.Features
{

View File

@@ -4,7 +4,6 @@ using System.Threading.Tasks;
using SabreTools.CommandLine.Inputs;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpOrg;
using SabreTools.RedumpLib.RedumpOrg.Data;
namespace RedumpTool.Features
{

View File

@@ -4,7 +4,6 @@ using System.Threading.Tasks;
using SabreTools.CommandLine.Inputs;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpOrg;
using SabreTools.RedumpLib.RedumpOrg.Data;
namespace RedumpTool.Features
{

View File

@@ -1,6 +1,5 @@
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.Data.Sections;
using SabreTools.RedumpLib.RedumpOrg.Data;
using Xunit;
namespace SabreTools.RedumpLib.Test

View File

@@ -12,7 +12,6 @@ using Newtonsoft.Json;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.Data.Sections;
using SabreTools.RedumpLib.RedumpOrg;
using SabreTools.RedumpLib.RedumpOrg.Data;
namespace SabreTools.RedumpLib
{

View File

@@ -90,16 +90,6 @@ namespace SabreTools.RedumpLib.RedumpInfo
#region Constants
/// <summary>
/// Regex matching the current creation time for login
/// </summary>
public static readonly Regex LoginCreationTimeRegex = new(@"<input type=""hidden"" name=""form_token"" value=""(.*?)"" />", RegexOptions.Compiled);
/// <summary>
/// Regex matching the current nonce token for login
/// </summary>
public static readonly Regex LoginTokenRegex = new(@"<input type=""hidden"" name=""form_token"" value=""(.*?)"" />", RegexOptions.Compiled);
/// <summary>
/// Login page URL
/// </summary>
@@ -186,8 +176,8 @@ namespace SabreTools.RedumpLib.RedumpInfo
// Get the current token from the login page
var loginPage = await DownloadString(LoginUrl);
string creationTime = LoginCreationTimeRegex.Match(loginPage ?? string.Empty).Groups[1].Value;
string token = LoginTokenRegex.Match(loginPage ?? string.Empty).Groups[1].Value;
string creationTime = Constants.LoginCreationTimeRegex.Match(loginPage ?? string.Empty).Groups[1].Value;
string token = Constants.LoginTokenRegex.Match(loginPage ?? string.Empty).Groups[1].Value;
#if NETCOREAPP
// Construct the login request
@@ -459,7 +449,7 @@ namespace SabreTools.RedumpLib.RedumpInfo
if (dumpsPage.Contains("<b>Download:</b>"))
{
if (Debug) Console.WriteLine($"DEBUG: CheckSingleSitePage(\"{url}\") - Single disc page");
var value = RedumpOrg.Data.Constants.SfvRegex.Match(dumpsPage).Groups[1].Value;
var value = Constants.SfvRegex.Match(dumpsPage).Groups[1].Value;
if (int.TryParse(value, out int id))
ids.Add(id);
@@ -467,7 +457,7 @@ namespace SabreTools.RedumpLib.RedumpInfo
}
// Otherwise, traverse each dump on the page
var matches = RedumpOrg.Data.Constants.DiscRegex.Matches(dumpsPage);
var matches = Constants.DiscRegex.Matches(dumpsPage);
foreach (Match? match in matches)
{
if (match is null)
@@ -594,7 +584,7 @@ namespace SabreTools.RedumpLib.RedumpInfo
}
// Otherwise, traverse each dump on the page
var matches = RedumpOrg.Data.Constants.NewDiscRegex.Matches(dumpsPage);
var matches = Constants.NewDiscRegex.Matches(dumpsPage);
foreach (Match? match in matches)
{
if (match is null)
@@ -958,8 +948,8 @@ namespace SabreTools.RedumpLib.RedumpInfo
var oldDiscPage = File.ReadAllText(Path.Combine(paddedIdDir, "disc.html"));
// Check for the last modified date in both pages
var oldResult = RedumpOrg.Data.Constants.LastModifiedRegex.Match(oldDiscPage);
var newResult = RedumpOrg.Data.Constants.LastModifiedRegex.Match(discPage);
var oldResult = Constants.LastModifiedRegex.Match(oldDiscPage);
var newResult = Constants.LastModifiedRegex.Match(discPage);
// If both pages contain the same modified date, skip it
if (oldResult.Success && newResult.Success && oldResult.Groups[1].Value == newResult.Groups[1].Value)
@@ -977,8 +967,8 @@ namespace SabreTools.RedumpLib.RedumpInfo
}
// If the downloaded data is invalid or otherwise empty, skip it
var hasAddedDate = RedumpOrg.Data.Constants.AddedRegex.Match(discPage);
var hasModifiedDate = RedumpOrg.Data.Constants.LastModifiedRegex.Match(discPage);
var hasAddedDate = Constants.AddedRegex.Match(discPage);
var hasModifiedDate = Constants.LastModifiedRegex.Match(discPage);
if (!hasAddedDate.Success && !hasModifiedDate.Success)
{
Console.WriteLine($"ID {paddedId} retieved an empty page, skipping...");
@@ -1164,8 +1154,8 @@ namespace SabreTools.RedumpLib.RedumpInfo
var oldDiscPage = File.ReadAllText(Path.Combine(paddedIdDir, "disc.html"));
// Check for the full match ID in both pages
var oldResult = RedumpOrg.Data.Constants.FullMatchRegex.Match(oldDiscPage);
var newResult = RedumpOrg.Data.Constants.FullMatchRegex.Match(discPage);
var oldResult = Constants.FullMatchRegex.Match(oldDiscPage);
var newResult = Constants.FullMatchRegex.Match(discPage);
// If both pages contain the same ID, skip it
if (oldResult.Success && newResult.Success && oldResult.Groups[1].Value == newResult.Groups[1].Value)
@@ -1182,8 +1172,8 @@ namespace SabreTools.RedumpLib.RedumpInfo
}
// Check the added date as a backup
oldResult = RedumpOrg.Data.Constants.AddedRegex.Match(oldDiscPage);
newResult = RedumpOrg.Data.Constants.AddedRegex.Match(discPage);
oldResult = Constants.AddedRegex.Match(oldDiscPage);
newResult = Constants.AddedRegex.Match(discPage);
// If the downloaded data is invalid or otherwise empty, skip it
if (oldResult.Success && !newResult.Success)

View File

@@ -0,0 +1,217 @@
using System.Text.RegularExpressions;
using SabreTools.RedumpLib.Data;
namespace SabreTools.RedumpLib.RedumpInfo
{
public static class Constants
{
#region Regular Expressions
/// <summary>
/// Regex matching the added field on a disc page
/// </summary>
public static readonly Regex AddedRegex = new(@"<tr><td><strong>Added</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the barcodes field on a disc page
/// </summary>
public static readonly Regex BarcodesRegex = new(@"<tr><td><strong>Barcodes</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the BCA field on a disc page
/// </summary>
public static readonly Regex BcaRegex = new(@"<h3>BCA</h3>"
+ @"<div class=""table-scroll table-scroll-compact"">"
+ @"<table class=""table-nowrap binary-table"">"
+ "<thead><tr><th>Row</th><th>Contents</th><th>ASCII</th></tr></thead>"
+ "<tbody>"
+ "<tr><td><code>(?<row1number>.*?)</code></td><td><code>(?<row1contents>.*?)</code></td><td><code>(?<row1ascii>.*?)</code></td></tr>"
+ "<tr><td><code>(?<row2number>.*?)</code></td><td><code>(?<row2contents>.*?)</code></td><td><code>(?<row2ascii>.*?)</code></td></tr>"
+ "<tr><td><code>(?<row3number>.*?)</code></td><td><code>(?<row3contents>.*?)</code></td><td><code>(?<row3ascii>.*?)</code></td></tr>"
+ "<tr><td><code>(?<row4number>.*?)</code></td><td><code>(?<row4contents>.*?)</code></td><td><code>(?<row4ascii>.*?)</code></td></tr>", RegexOptions.Compiled | RegexOptions.Singleline);
/// <summary>
/// Regex matching the category field on a disc page
/// </summary>
public static readonly Regex CategoryRegex = new(@"<tr><td><strong>Category</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the comments field on a disc page
/// </summary>
public static readonly Regex CommentsRegex = new(@"<h3>Comments</h3><p class=""pre-wrap disc-comments"">(.*?)</p>", RegexOptions.Compiled | RegexOptions.Singleline);
/// <summary>
/// Regex matching the contents field on a disc page
/// </summary>
public static readonly Regex ContentsRegex = new(@"<summary><h3>Contents</h3></summary><p class=""pre-wrap disc-contents"">(.*?)</p>", RegexOptions.Compiled | RegexOptions.Singleline);
/// <summary>
/// Regex matching individual disc links on a results page
/// </summary>
public static readonly Regex DiscRegex = new(@"<a href=""/disc/(\d+)/"">", RegexOptions.Compiled);
/// <summary>
/// Regex matching the disc number or letter field on a disc page
/// </summary>
public static readonly Regex DiscNumberLetterRegex = new(@"\((.*?)\)", RegexOptions.Compiled);
/// <summary>
/// Regex matching the dumpers on a disc page
/// </summary>
public static readonly Regex DumpersRegex = new(@"<a href=""/discs/?dumper=(.*?)/"">", RegexOptions.Compiled);
/// <summary>
/// Regex matching the edition field on a disc page
/// </summary>
public static readonly Regex EditionRegex = new(@"<tr><td><strong>Edition</strong></td><td class=""disc-edition-cell""><span class=""disc-edition-value"">(.*?)</span></td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the error count field on a disc page
/// </summary>
public static readonly Regex ErrorCountRegex = new(@"<tr><td><strong>Errors</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the foreign title field on a disc page
/// </summary>
public static readonly Regex ForeignTitleRegex = new(@"<h2 class=""foreign-title"">(.*?)</h2>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the "full match" ID list from a WIP disc page
/// </summary>
/// TODO: Determine if this has a parallel in redump.info
public static readonly Regex FullMatchRegex = new(@"<td class=""static"">full match ids: (.*?)</td>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the languages field on a disc page
/// </summary>
public static readonly Regex LanguagesRegex = new(@"<img class=""flag-icon"" src=""/static/flags/(.*?)\.svg"" title="".*?"" alt="".*?"" />\s*", RegexOptions.Compiled);
/// <summary>
/// Regex matching the last modified field on a disc page
/// </summary>
public static readonly Regex LastModifiedRegex = new(@"<tr><td><strong>Modified</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the current creation time for login
/// </summary>
public static readonly Regex LoginCreationTimeRegex = new(@"<input type=""hidden"" name=""form_token"" value=""(.*?)"" />", RegexOptions.Compiled);
/// <summary>
/// Regex matching the current nonce token for login
/// </summary>
public static readonly Regex LoginTokenRegex = new(@"<input type=""hidden"" name=""form_token"" value=""(.*?)"" />", RegexOptions.Compiled);
/// <summary>
/// Regex matching the media field on a disc page
/// </summary>
public static readonly Regex MediaRegex = new(@"<tr><td><strong>Media</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching individual WIP disc links on a results page
/// </summary>
/// TODO: Determine if this has a parallel in redump.info, maybe the queue page?
public static readonly Regex NewDiscRegex = new(@"<a (style=.*)?href=""/newdisc/(\d+)/"">", RegexOptions.Compiled);
/// <summary>
/// Regex matching the "partial match" ID list from a WIP disc page
/// </summary>
/// TODO: Determine if this has a parallel in redump.info
public static readonly Regex PartialMatchRegex = new(@"<td class=""static"">partial match ids: (.*?)</td>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the disc key on a PS3 disc page
/// </summary>
public static readonly Regex PS3DiscKey = new(@"<tr><td><strong>Disc Key</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the PVD field on a disc page
/// </summary>
public static readonly Regex PvdRegex = new("<h3>PVD</h3>"
+ @"<div class=""table-scroll table-scroll-compact"">"
+ @"<table class=""table-nowrap binary-table"">"
+ "<thead><tr><th></th><th>Contents</th><th>Date</th><th>Time</th><th>GMT</th></tr></thead>"
+ "<tbody>"
+ "<tr><td>Creation</td><td><code>(?<creationbytes>.*?)</code></td><td><code>(?<creationdate>.*?)</code></td><td><code>(?<creationtime>.*?)</code></td><td><code>(?<creationtimezone>.*?)</code></td></tr>"
+ "<tr><td>Modification</td><td><code>(?<modificationbytes>.*?)</code></td><td><code>(?<modificationdate>.*?)</code></td><td><code>(?<modificationtime>.*?)</code></td><td><code>(?<modificationtimezone>.*?)</code></td></tr>"
+ "<tr><td>Expiration</td><td><code>(?<expirationbytes>.*?)</code></td><td><code>(?<expirationdate>.*?)</code></td><td><code>(?<expirationtime>.*?)</code></td><td><code>(?<expirationtimezone>.*?)</code></td></tr>"
+ "<tr><td>Effective</td><td><code>(?<effectivebytes>.*?)</code></td><td><code>(?<effectivedate>.*?)</code></td><td><code>(?<effectivetime>.*?)</code></td><td><code>(?<effectivetimezone>.*?)</code></td></tr>", RegexOptions.Compiled | RegexOptions.Singleline);
/// <summary>
/// Regex matching the region field on a disc page
/// </summary>
public static readonly Regex RegionRegex = new(@"<tr><td><strong>Region</strong></td><td class=""flags-inline flags-region"">"
+ @"<a href=""/discs/?region=(.*?)"">", RegexOptions.Compiled);
/// <summary>
/// Regex matching a double-layer disc ringcode information
/// </summary>
/// TODO: Determine if this has a parallel in redump.info, maybe the queue page?
public static readonly Regex RingCodeDoubleRegex = new(@"", RegexOptions.Compiled | RegexOptions.Singleline); // Varies based on available fields, like Addtional Mould
/// <summary>
/// Regex matching a single-layer disc ringcode information
/// </summary>
/// TODO: Determine if this has a parallel in redump.info, maybe the queue page?
public static readonly Regex RingCodeSingleRegex = new(@"", RegexOptions.Compiled | RegexOptions.Singleline); // Varies based on available fields, like Addtional Mould
/// <summary>
/// Regex matching the serial field on a disc page
/// </summary>
public static readonly Regex SerialRegex = new(@"<<tr><td><strong>Disc Serial</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the SFV link on a disc page
/// </summary>
/// TODO: Determine if this has a parallel in redump.info
public static readonly Regex SfvRegex = new(@"/disc/(\d+)/sfv/", RegexOptions.Compiled);
/// <summary>
/// Regex matching the system field on a disc page
/// </summary>
public static readonly Regex SystemRegex = new(@"<tr><td><strong>System</strong></td><td><a href=""/discs/?system=(.*?)"">", RegexOptions.Compiled);
/// <summary>
/// Regex matching the title field on a disc page
/// </summary>
public static readonly Regex TitleRegex = new(@"<h2>(.*?)</h2>", RegexOptions.Compiled);
/// <summary>
/// Regex matching a single track on a disc page
/// </summary>
/// TODO: Figure out how to translate the new page to this
public static readonly Regex TrackRegex = new(@"<tr><td>(?<number>.*?)</td><td>(?<type>.*?)</td><td>(?<pregap>.*?)</td><td>(?<length>.*?)</td><td>(?<sectors>.*?)</td><td>(?<size>.*?)</td><td>(?<crc32>.*?)</td><td>(?<md5>.*?)</td><td>(?<sha1>.*?)</td></tr>", RegexOptions.Compiled | RegexOptions.Singleline);
/// <summary>
/// Regex matching the track count on a disc page
/// </summary>
/// TODO: There doesn't seem to be a track count anymore
public static readonly Regex TrackCountRegex = new(@"<tr><th>Number of tracks</th><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the version field on a disc page
/// </summary>
public static readonly Regex VersionRegex = new(@"<tr><td><strong>Version</strong></td><td>(.*?)</td></tr>", RegexOptions.Compiled);
/// <summary>
/// Regex matching the write offset field on a disc page
/// </summary>
/// TODO: There doesn't seem to be a write offset anymore
public static readonly Regex WriteOffsetRegex = new(@"<tr><th>Write offset</th><td>(.*?)</td></tr>", RegexOptions.Compiled);
#endregion
#region Subpath Sets
/// <summary>
/// All disc page subpaths as a set
/// </summary>
public static readonly DiscSubpath[] AllDiscSubpaths =
[
DiscSubpath.Cuesheet,
DiscSubpath.Edit,
DiscSubpath.History,
];
#endregion
}
}

View File

@@ -10,7 +10,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpOrg.Data;
using SabreTools.RedumpLib.Web;
namespace SabreTools.RedumpLib.RedumpOrg

View File

@@ -1,7 +1,7 @@
using System.Text.RegularExpressions;
using SabreTools.RedumpLib.Data;
namespace SabreTools.RedumpLib.RedumpOrg.Data
namespace SabreTools.RedumpLib.RedumpOrg
{
public static class Constants
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Text;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpOrg.Data;
// TODO: Errors should validate number or number range (# or #-#)