2023-05-18 20:06:29 +02:00
|
|
|
|
using System.Globalization;
|
2023-05-25 16:55:58 +02:00
|
|
|
|
using System.Text.RegularExpressions;
|
2023-05-18 20:06:29 +02:00
|
|
|
|
|
|
|
|
|
namespace Tranga;
|
2023-05-17 23:23:01 +02:00
|
|
|
|
|
2023-05-19 19:52:24 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Has to be Part of a publication
|
|
|
|
|
/// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file.
|
|
|
|
|
/// </summary>
|
2023-05-17 23:23:01 +02:00
|
|
|
|
public struct Chapter
|
|
|
|
|
{
|
2023-05-18 16:03:00 +02:00
|
|
|
|
public string? name { get; }
|
|
|
|
|
public string? volumeNumber { get; }
|
|
|
|
|
public string? chapterNumber { get; }
|
2023-05-18 16:21:21 +02:00
|
|
|
|
public string url { get; }
|
2023-05-18 19:51:26 +02:00
|
|
|
|
public string fileName { get; }
|
2023-05-25 16:55:58 +02:00
|
|
|
|
|
2023-05-25 17:34:24 +02:00
|
|
|
|
private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
2023-05-19 19:32:47 +02:00
|
|
|
|
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
2023-05-17 23:23:01 +02:00
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
2023-06-03 22:25:24 +02:00
|
|
|
|
this.volumeNumber = volumeNumber;
|
2023-05-17 23:23:01 +02:00
|
|
|
|
this.chapterNumber = chapterNumber;
|
2023-05-18 16:21:21 +02:00
|
|
|
|
this.url = url;
|
2023-06-03 22:25:24 +02:00
|
|
|
|
|
|
|
|
|
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
|
|
|
|
string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : "";
|
|
|
|
|
string chNumberStr = this.chapterNumber is not null ? $"Ch.{chapterNumber} " : "";
|
|
|
|
|
string chNameStr = chapterName.Length > 0 ? $"- {chapterName}" : "";
|
2023-06-03 23:44:58 +02:00
|
|
|
|
chNameStr = chNameStr.Replace("Volume", "").Replace("volume", "");
|
2023-06-03 22:25:24 +02:00
|
|
|
|
this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
|
2023-05-17 23:23:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|