Kavita naming convention

This commit is contained in:
glax 2023-06-03 22:25:24 +02:00
parent 14785e5672
commit 6d91788655
2 changed files with 23 additions and 5 deletions

View File

@ -20,16 +20,20 @@ public struct Chapter
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url) public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
{ {
this.name = name; this.name = name;
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1"; this.volumeNumber = volumeNumber;
this.chapterNumber = chapterNumber; this.chapterNumber = chapterNumber;
this.url = url; this.url = url;
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
NumberFormatInfo nfi = new NumberFormatInfo() NumberFormatInfo nfi = new NumberFormatInfo()
{ {
NumberDecimalSeparator = "." NumberDecimalSeparator = "."
}; };
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1) sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
.ToString(nfi); .ToString(nfi);
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
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}" : "";
this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
} }
} }

View File

@ -1,6 +1,7 @@
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Xml.Linq; using System.Xml.Linq;
using Logging; using Logging;
using static System.IO.UnixFileMode; using static System.IO.UnixFileMode;
@ -111,7 +112,20 @@ public abstract class Connector
/// <returns>true if chapter is present</returns> /// <returns>true if chapter is present</returns>
public bool CheckChapterIsDownloaded(Publication publication, Chapter chapter) public bool CheckChapterIsDownloaded(Publication publication, Chapter chapter)
{ {
return File.Exists(GetArchiveFilePath(publication, chapter)); Regex legalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
string oldFilePath = Path.Join(downloadLocation, publication.folderName, $"{string.Concat(legalCharacters.Matches(chapter.name ?? ""))} - V{chapter.volumeNumber}C{chapter.chapterNumber} - {chapter.sortNumber}.cbz");
string oldFilePath2 = Path.Join(downloadLocation, publication.folderName, $"{string.Concat(legalCharacters.Matches(chapter.name ?? ""))} - VC{chapter.chapterNumber} - {chapter.sortNumber}.cbz");
string newFilePath = GetArchiveFilePath(publication, chapter);
if (File.Exists(oldFilePath))
{
logger?.WriteLine(this.GetType().ToString(), $"Moving old file {oldFilePath} -> {newFilePath}");
File.Move(oldFilePath, newFilePath);
}else if (File.Exists(oldFilePath2))
{
logger?.WriteLine(this.GetType().ToString(), $"Moving old file {oldFilePath2} -> {newFilePath}");
File.Move(oldFilePath2, newFilePath);
}
return File.Exists(newFilePath);
} }
/// <summary> /// <summary>
@ -120,7 +134,7 @@ public abstract class Connector
/// <returns>Filepath</returns> /// <returns>Filepath</returns>
protected string GetArchiveFilePath(Publication publication, Chapter chapter) protected string GetArchiveFilePath(Publication publication, Chapter chapter)
{ {
return Path.Join(downloadLocation, publication.folderName, $"{chapter.fileName}.cbz"); return Path.Join(downloadLocation, publication.folderName, $"{publication.folderName} - {chapter.fileName}.cbz");
} }
/// <summary> /// <summary>