From 6d91788655acbbec4a810eeaa6c5f79ba651eaf0 Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 3 Jun 2023 22:25:24 +0200 Subject: [PATCH] Kavita naming convention --- Tranga/Chapter.cs | 10 +++++++--- Tranga/Connector.cs | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 050d5e4..e85d057 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -20,16 +20,20 @@ public struct Chapter public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url) { this.name = name; - this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1"; + this.volumeNumber = volumeNumber; this.chapterNumber = chapterNumber; this.url = url; - string chapterName = string.Concat(LegalCharacters.Matches(name ?? "")); NumberFormatInfo nfi = new NumberFormatInfo() { NumberDecimalSeparator = "." }; sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1) .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}"; } } \ No newline at end of file diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index c706df9..47ed2cf 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -1,6 +1,7 @@ using System.IO.Compression; using System.Net; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using System.Xml.Linq; using Logging; using static System.IO.UnixFileMode; @@ -111,7 +112,20 @@ public abstract class Connector /// true if chapter is present 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); } /// @@ -120,7 +134,7 @@ public abstract class Connector /// Filepath 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"); } ///