diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index b5ddf32..4af7722 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -10,7 +10,7 @@ namespace Tranga; public readonly struct Chapter { // ReSharper disable once MemberCanBePrivate.Global - public Publication parentPublication { get; } + public Manga parentManga { get; } public string? name { get; } public string? volumeNumber { get; } public string chapterNumber { get; } @@ -20,9 +20,9 @@ public readonly struct Chapter private static readonly Regex LegalCharacters = new (@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*"); private static readonly Regex IllegalStrings = new(@"Vol(ume)?.?", RegexOptions.IgnoreCase); - public Chapter(Publication parentPublication, string? name, string? volumeNumber, string chapterNumber, string url) + public Chapter(Manga parentManga, string? name, string? volumeNumber, string chapterNumber, string url) { - this.parentPublication = parentPublication; + this.parentManga = parentManga; this.name = name; this.volumeNumber = volumeNumber; this.chapterNumber = chapterNumber; @@ -38,7 +38,7 @@ public readonly struct Chapter public override string ToString() { - return $"Chapter {parentPublication.sortName} {parentPublication.internalId} {chapterNumber} {name}"; + return $"Chapter {parentManga.sortName} {parentManga.internalId} {chapterNumber} {name}"; } /// @@ -48,9 +48,9 @@ public readonly struct Chapter internal bool CheckChapterIsDownloaded(string downloadLocation) { string newFilePath = GetArchiveFilePath(downloadLocation); - if (!Directory.Exists(Path.Join(downloadLocation, parentPublication.folderName))) + if (!Directory.Exists(Path.Join(downloadLocation, parentManga.folderName))) return false; - FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentPublication.folderName)).GetFiles(); + FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles(); Regex chapterInfoRex = new(@"Ch\.[0-9.]+"); Regex chapterRex = new(@"[0-9]+(\.[0-9]+)?"); @@ -71,7 +71,7 @@ public readonly struct Chapter /// Filepath internal string GetArchiveFilePath(string downloadLocation) { - return Path.Join(downloadLocation, parentPublication.folderName, $"{parentPublication.folderName} - {this.fileName}.cbz"); + return Path.Join(downloadLocation, parentManga.folderName, $"{parentManga.folderName} - {this.fileName}.cbz"); } /// @@ -82,10 +82,10 @@ public readonly struct Chapter internal string GetComicInfoXmlString() { XElement comicInfo = new XElement("ComicInfo", - new XElement("Tags", string.Join(',', parentPublication.tags)), - new XElement("LanguageISO", parentPublication.originalLanguage), + new XElement("Tags", string.Join(',', parentManga.tags)), + new XElement("LanguageISO", parentManga.originalLanguage), new XElement("Title", this.name), - new XElement("Writer", string.Join(',', parentPublication.authors)), + new XElement("Writer", string.Join(',', parentManga.authors)), new XElement("Volume", this.volumeNumber), new XElement("Number", this.chapterNumber) ); diff --git a/Tranga/GlobalBase.cs b/Tranga/GlobalBase.cs index 20e41b5..8cad5c6 100644 --- a/Tranga/GlobalBase.cs +++ b/Tranga/GlobalBase.cs @@ -11,7 +11,7 @@ public abstract class GlobalBase protected TrangaSettings settings { get; init; } protected HashSet notificationConnectors { get; init; } protected HashSet libraryConnectors { get; init; } - protected List cachedPublications { get; init; } + protected List cachedPublications { get; init; } protected GlobalBase(GlobalBase clone) { diff --git a/Tranga/Jobs/DownloadChapter.cs b/Tranga/Jobs/DownloadChapter.cs index 2bab2ec..9cfb23f 100644 --- a/Tranga/Jobs/DownloadChapter.cs +++ b/Tranga/Jobs/DownloadChapter.cs @@ -14,7 +14,7 @@ public class DownloadChapter : Job protected override string GetId() { - return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), chapter.parentPublication.internalId, chapter.chapterNumber))); + return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), chapter.parentManga.internalId, chapter.chapterNumber))); } public override string ToString() @@ -28,7 +28,7 @@ public class DownloadChapter : Job { mangaConnector.DownloadChapter(chapter, this.progressToken); UpdateLibraries(); - SendNotifications("Chapter downloaded", $"{chapter.parentPublication.sortName} - {chapter.chapterNumber}"); + SendNotifications("Chapter downloaded", $"{chapter.parentManga.sortName} - {chapter.chapterNumber}"); }); downloadTask.Start(); return Array.Empty(); diff --git a/Tranga/Jobs/DownloadNewChapters.cs b/Tranga/Jobs/DownloadNewChapters.cs index 13381e3..bfe2ddc 100644 --- a/Tranga/Jobs/DownloadNewChapters.cs +++ b/Tranga/Jobs/DownloadNewChapters.cs @@ -5,26 +5,26 @@ namespace Tranga.Jobs; public class DownloadNewChapters : Job { - public Publication publication { get; init; } + public Manga manga { get; init; } - public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Publication publication, bool recurring = false, TimeSpan? recurrence = null) : base (clone, connector, recurring, recurrence) + public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, bool recurring = false, TimeSpan? recurrence = null) : base (clone, connector, recurring, recurrence) { - this.publication = publication; + this.manga = manga; } protected override string GetId() { - return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), publication.internalId))); + return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), manga.internalId))); } public override string ToString() { - return $"DownloadChapter {id} {publication}"; + return $"DownloadChapter {id} {manga}"; } protected override IEnumerable ExecuteReturnSubTasksInternal() { - Chapter[] chapters = mangaConnector.GetNewChapters(publication); + Chapter[] chapters = mangaConnector.GetNewChapters(manga); this.progressToken.increments = chapters.Length; List subJobs = new(); foreach (Chapter chapter in chapters) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 614f85f..384b899 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -44,7 +44,7 @@ public class JobBoss : GlobalBase { if (jjob is not DownloadChapter job) return false; - return job.chapter.parentPublication.internalId == internalId && + return job.chapter.parentManga.internalId == internalId && job.chapter.chapterNumber == chapterNumber; }); else if (internalId is not null) @@ -52,12 +52,12 @@ public class JobBoss : GlobalBase { if (jjob is not DownloadNewChapters job) return false; - return job.publication.internalId == internalId; + return job.manga.internalId == internalId; }); return ret; } - public IEnumerable GetJobsLike(MangaConnector? mangaConnector = null, Publication? publication = null, + public IEnumerable GetJobsLike(MangaConnector? mangaConnector = null, Manga? publication = null, Chapter? chapter = null) { return GetJobsLike(mangaConnector?.name, publication?.internalId, chapter?.chapterNumber); diff --git a/Tranga/Publication.cs b/Tranga/Manga.cs similarity index 94% rename from Tranga/Publication.cs rename to Tranga/Manga.cs index 668fe3f..2f1ba06 100644 --- a/Tranga/Publication.cs +++ b/Tranga/Manga.cs @@ -9,7 +9,7 @@ namespace Tranga; /// /// Contains information on a Publication (Manga) /// -public struct Publication +public struct Manga { public string sortName { get; } public List authors { get; } @@ -36,7 +36,7 @@ public struct Publication private static readonly Regex LegalCharacters = new (@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*"); [JsonConstructor] - public Publication(string sortName, List authors, string? description, Dictionary altTitles, string[] tags, string? coverUrl, Dictionary? links, int? year, string? originalLanguage, string status, string publicationId, string? folderName = null, float? ignoreChaptersBelow = 0) + public Manga(string sortName, List authors, string? description, Dictionary altTitles, string[] tags, string? coverUrl, Dictionary? links, int? year, string? originalLanguage, string status, string publicationId, string? folderName = null, float? ignoreChaptersBelow = 0) { this.sortName = sortName; this.authors = authors; diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index cc54a0a..4ebfa46 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -29,40 +29,40 @@ public abstract class MangaConnector : GlobalBase /// /// Search-Query /// Publications matching the query - public abstract Publication[] GetPublications(string publicationTitle = ""); + public abstract Manga[] GetPublications(string publicationTitle = ""); /// /// Returns all Chapters of the publication in the provided language. /// If the language is empty or null, returns all Chapters in all Languages. /// - /// Publication to get Chapters for + /// Publication to get Chapters for /// Language of the Chapters /// Array of Chapters matching Publication and Language - public abstract Chapter[] GetChapters(Publication publication, string language="en"); + public abstract Chapter[] GetChapters(Manga manga, string language="en"); /// /// Updates the available Chapters of a Publication /// - /// Publication to check + /// Publication to check /// Language to receive chapters for /// List of Chapters that were previously not in collection - public Chapter[] GetNewChapters(Publication publication, string language = "en") + public Chapter[] GetNewChapters(Manga manga, string language = "en") { - Log($"Getting new Chapters for {publication}"); - Chapter[] newChapters = this.GetChapters(publication, language); + Log($"Getting new Chapters for {manga}"); + Chapter[] newChapters = this.GetChapters(manga, language); NumberFormatInfo decimalPoint = new (){ NumberDecimalSeparator = "." }; - Log($"Checking for duplicates {publication}"); + Log($"Checking for duplicates {manga}"); List newChaptersList = newChapters.Where(nChapter => - float.Parse(nChapter.chapterNumber, decimalPoint) > publication.ignoreChaptersBelow && + float.Parse(nChapter.chapterNumber, decimalPoint) > manga.ignoreChaptersBelow && !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList(); - Log($"{newChaptersList.Count} new chapters. {publication}"); + Log($"{newChaptersList.Count} new chapters. {manga}"); return newChaptersList.ToArray(); } - public Chapter[] SelectChapters(Publication publication, string searchTerm, string? language = null) + public Chapter[] SelectChapters(Manga manga, string searchTerm, string? language = null) { - Chapter[] availableChapters = this.GetChapters(publication, language??"en"); + Chapter[] availableChapters = this.GetChapters(manga, language??"en"); Regex volumeRegex = new ("((v(ol)*(olume)*){1} *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase); Regex chapterRegex = new ("((c(h)*(hapter)*){1} *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase); Regex singleResultRegex = new("([0-9]+)", RegexOptions.IgnoreCase); @@ -138,20 +138,20 @@ public abstract class MangaConnector : GlobalBase /// /// Copies the already downloaded cover from cache to downloadLocation /// - /// Publication to retrieve Cover for - public void CopyCoverFromCacheToDownloadLocation(Publication publication) + /// Publication to retrieve Cover for + public void CopyCoverFromCacheToDownloadLocation(Manga manga) { - Log($"Copy cover {publication}"); + Log($"Copy cover {manga}"); //Check if Publication already has a Folder and cover - string publicationFolder = publication.CreatePublicationFolder(settings.downloadLocation); + string publicationFolder = manga.CreatePublicationFolder(settings.downloadLocation); DirectoryInfo dirInfo = new (publicationFolder); if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase))) { - Log($"Cover exists {publication}"); + Log($"Cover exists {manga}"); return; } - string fileInCache = Path.Join(settings.coverImageCache, publication.coverFileNameInCache); + string fileInCache = Path.Join(settings.coverImageCache, manga.coverFileNameInCache); string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" ); Log($"Cloning cover {fileInCache} -> {newFilePath}"); File.Copy(fileInCache, newFilePath, true); diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index 40d3000..c413ff5 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -31,13 +31,13 @@ public class MangaDex : MangaConnector }); } - public override Publication[] GetPublications(string publicationTitle = "") + public override Manga[] GetPublications(string publicationTitle = "") { Log($"Searching Publications. Term=\"{publicationTitle}\""); const int limit = 100; //How many values we want returned at once int offset = 0; //"Page" int total = int.MaxValue; //How many total results are there, is updated on first request - HashSet publications = new(); + HashSet publications = new(); int loadedPublicationData = 0; while (offset < total) //As long as we haven't requested all "Pages" { @@ -125,7 +125,7 @@ public class MangaDex : MangaConnector string status = attributes["status"]!.GetValue(); - Publication pub = new ( + Manga pub = new ( title, authors, description, @@ -147,9 +147,9 @@ public class MangaDex : MangaConnector return publications.ToArray(); } - public override Chapter[] GetChapters(Publication publication, string language="en") + public override Chapter[] GetChapters(Manga manga, string language="en") { - Log($"Getting chapters {publication}"); + Log($"Getting chapters {manga}"); const int limit = 100; //How many values we want returned at once int offset = 0; //"Page" int total = int.MaxValue; //How many total results are there, is updated on first request @@ -160,7 +160,7 @@ public class MangaDex : MangaConnector //Request next "Page" DownloadClient.RequestResult requestResult = downloadClient.MakeRequest( - $"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed); + $"https://api.mangadex.org/manga/{manga.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) break; JsonObject? result = JsonSerializer.Deserialize(requestResult.result); @@ -191,13 +191,13 @@ public class MangaDex : MangaConnector : "null"; if(chapterNum is not "null") - chapters.Add(new Chapter(publication, title, volume, chapterNum, chapterId)); + chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId)); } } //Return Chapters ordered by Chapter-Number NumberFormatInfo chapterNumberFormatInfo = new() { NumberDecimalSeparator = "." }; - Log($"Got {chapters.Count} chapters. {publication}"); + Log($"Got {chapters.Count} chapters. {manga}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } @@ -205,8 +205,8 @@ public class MangaDex : MangaConnector { if (progressToken?.cancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - Publication chapterParentPublication = chapter.parentPublication; - Log($"Retrieving chapter-info {chapter} {chapterParentPublication}"); + Manga chapterParentManga = chapter.parentManga; + Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); //Request URLs for Chapter-Images DownloadClient.RequestResult requestResult = downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer); @@ -227,8 +227,8 @@ public class MangaDex : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentPublication.coverUrl is not null) - chapterParentPublication.coverFileNameInCache = SaveCoverImageToCache(chapterParentPublication.coverUrl, (byte)RequestType.AtHomeServer); + if (chapterParentManga.coverUrl is not null) + chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, (byte)RequestType.AtHomeServer); //Download Chapter-Images return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), (byte)RequestType.AtHomeServer, comicInfoPath, progressToken:progressToken); } diff --git a/Tranga/MangaConnectors/MangaKatana.cs b/Tranga/MangaConnectors/MangaKatana.cs index 8f8dfbb..e88f776 100644 --- a/Tranga/MangaConnectors/MangaKatana.cs +++ b/Tranga/MangaConnectors/MangaKatana.cs @@ -19,7 +19,7 @@ public class MangaKatana : MangaConnector }); } - public override Publication[] GetPublications(string publicationTitle = "") + public override Manga[] GetPublications(string publicationTitle = "") { Log($"Searching Publications. Term=\"{publicationTitle}\""); string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower(); @@ -27,7 +27,7 @@ public class MangaKatana : MangaConnector DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) - return Array.Empty(); + return Array.Empty(); // ReSharper disable once MergeIntoPattern // If a single result is found, the user will be redirected to the results directly instead of a result page @@ -38,13 +38,13 @@ public class MangaKatana : MangaConnector return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1]) }; } - Publication[] publications = ParsePublicationsFromHtml(requestResult.result); + Manga[] publications = ParsePublicationsFromHtml(requestResult.result); cachedPublications.AddRange(publications); Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); return publications; } - private Publication[] ParsePublicationsFromHtml(Stream html) + private Manga[] ParsePublicationsFromHtml(Stream html) { StreamReader reader = new(html); string htmlString = reader.ReadToEnd(); @@ -52,7 +52,7 @@ public class MangaKatana : MangaConnector document.LoadHtml(htmlString); IEnumerable searchResults = document.DocumentNode.SelectNodes("//*[@id='book_list']/div"); if (searchResults is null || !searchResults.Any()) - return Array.Empty(); + return Array.Empty(); List urls = new(); foreach (HtmlNode mangaResult in searchResults) { @@ -60,13 +60,13 @@ public class MangaKatana : MangaConnector .First(a => a.Name == "href").Value); } - HashSet ret = new(); + HashSet ret = new(); foreach (string url in urls) { DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(url, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) - return Array.Empty(); + return Array.Empty(); ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1])); } @@ -74,7 +74,7 @@ public class MangaKatana : MangaConnector return ret.ToArray(); } - private Publication ParseSinglePublicationFromHtml(Stream html, string publicationId) + private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId) { StreamReader reader = new(html); string htmlString = reader.ReadToEnd(); @@ -132,14 +132,14 @@ public class MangaKatana : MangaConnector year = Convert.ToInt32(yearString); } - return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, links, + return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, links, year, originalLanguage, status, publicationId); } - public override Chapter[] GetChapters(Publication publication, string language="en") + public override Chapter[] GetChapters(Manga manga, string language="en") { - Log($"Getting chapters {publication}"); - string requestUrl = $"https://mangakatana.com/manga/{publication.publicationId}"; + Log($"Getting chapters {manga}"); + string requestUrl = $"https://mangakatana.com/manga/{manga.publicationId}"; // Leaving this in for verification if the page exists DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, 1); @@ -151,12 +151,12 @@ public class MangaKatana : MangaConnector { NumberDecimalSeparator = "." }; - List chapters = ParseChaptersFromHtml(publication, requestUrl); - Log($"Got {chapters.Count} chapters. {publication}"); + List chapters = ParseChaptersFromHtml(manga, requestUrl); + Log($"Got {chapters.Count} chapters. {manga}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } - private List ParseChaptersFromHtml(Publication publication, string mangaUrl) + private List ParseChaptersFromHtml(Manga manga, string mangaUrl) { // Using HtmlWeb will include the chapters since they are loaded with js HtmlWeb web = new(); @@ -175,7 +175,7 @@ public class MangaKatana : MangaConnector string chapterName = string.Concat(fullString.Split(':')[1..]); string url = chapterInfo.Descendants("a").First() .GetAttributeValue("href", ""); - ret.Add(new Chapter(publication, chapterName, volumeNumber, chapterNumber, url)); + ret.Add(new Chapter(manga, chapterName, volumeNumber, chapterNumber, url)); } return ret; @@ -185,8 +185,8 @@ public class MangaKatana : MangaConnector { if (progressToken?.cancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - Publication chapterParentPublication = chapter.parentPublication; - Log($"Retrieving chapter-info {chapter} {chapterParentPublication}"); + Manga chapterParentManga = chapter.parentManga; + Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); string requestUrl = chapter.url; // Leaving this in to check if the page exists DownloadClient.RequestResult requestResult = @@ -199,8 +199,8 @@ public class MangaKatana : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentPublication.coverUrl is not null) - chapterParentPublication.coverFileNameInCache = SaveCoverImageToCache(chapterParentPublication.coverUrl, 1); + if (chapterParentManga.coverUrl is not null) + chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, 1); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken); } diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index 0568995..9711fd8 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -19,7 +19,7 @@ public class Manganato : MangaConnector }); } - public override Publication[] GetPublications(string publicationTitle = "") + public override Manga[] GetPublications(string publicationTitle = "") { Log($"Searching Publications. Term=\"{publicationTitle}\""); string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower(); @@ -27,15 +27,15 @@ public class Manganato : MangaConnector DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) - return Array.Empty(); + return Array.Empty(); - Publication[] publications = ParsePublicationsFromHtml(requestResult.result); + Manga[] publications = ParsePublicationsFromHtml(requestResult.result); cachedPublications.AddRange(publications); Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); return publications; } - private Publication[] ParsePublicationsFromHtml(Stream html) + private Manga[] ParsePublicationsFromHtml(Stream html) { StreamReader reader = new (html); string htmlString = reader.ReadToEnd(); @@ -49,13 +49,13 @@ public class Manganato : MangaConnector .First(a => a.Name == "href").Value); } - HashSet ret = new(); + HashSet ret = new(); foreach (string url in urls) { DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(url, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) - return Array.Empty(); + return Array.Empty(); ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1])); } @@ -63,7 +63,7 @@ public class Manganato : MangaConnector return ret.ToArray(); } - private Publication ParseSinglePublicationFromHtml(Stream html, string publicationId) + private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId) { StreamReader reader = new (html); string htmlString = reader.ReadToEnd(); @@ -120,14 +120,14 @@ public class Manganato : MangaConnector .First(s => s.HasClass("chapter-time")).InnerText; int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000; - return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, links, + return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, links, year, originalLanguage, status, publicationId); } - public override Chapter[] GetChapters(Publication publication, string language="en") + public override Chapter[] GetChapters(Manga manga, string language="en") { - Log($"Getting chapters {publication}"); - string requestUrl = $"https://chapmanganato.com/{publication.publicationId}"; + Log($"Getting chapters {manga}"); + string requestUrl = $"https://chapmanganato.com/{manga.publicationId}"; DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) @@ -138,12 +138,12 @@ public class Manganato : MangaConnector { NumberDecimalSeparator = "." }; - List chapters = ParseChaptersFromHtml(publication, requestResult.result); - Log($"Got {chapters.Count} chapters. {publication}"); + List chapters = ParseChaptersFromHtml(manga, requestResult.result); + Log($"Got {chapters.Count} chapters. {manga}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } - private List ParseChaptersFromHtml(Publication publication, Stream html) + private List ParseChaptersFromHtml(Manga manga, Stream html) { StreamReader reader = new (html); string htmlString = reader.ReadToEnd(); @@ -162,7 +162,7 @@ public class Manganato : MangaConnector string chapterName = string.Concat(fullString.Split(':')[1..]); string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")) .GetAttributeValue("href", ""); - ret.Add(new Chapter(publication, chapterName, volumeNumber, chapterNumber, url)); + ret.Add(new Chapter(manga, chapterName, volumeNumber, chapterNumber, url)); } ret.Reverse(); return ret; @@ -172,8 +172,8 @@ public class Manganato : MangaConnector { if (progressToken?.cancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - Publication chapterParentPublication = chapter.parentPublication; - Log($"Retrieving chapter-info {chapter} {chapterParentPublication}"); + Manga chapterParentManga = chapter.parentManga; + Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); string requestUrl = chapter.url; DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, 1); @@ -185,8 +185,8 @@ public class Manganato : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentPublication.coverUrl is not null) - chapterParentPublication.coverFileNameInCache = SaveCoverImageToCache(chapterParentPublication.coverUrl, 1); + if (chapterParentManga.coverUrl is not null) + chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, 1); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken); } diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index c470eaf..3e67760 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -69,22 +69,22 @@ public class Mangasee : MangaConnector }); } - public override Publication[] GetPublications(string publicationTitle = "") + public override Manga[] GetPublications(string publicationTitle = "") { Log($"Searching Publications. Term=\"{publicationTitle}\""); string requestUrl = $"https://mangasee123.com/_search.php"; DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) - return Array.Empty(); + return Array.Empty(); - Publication[] publications = ParsePublicationsFromHtml(requestResult.result, publicationTitle); + Manga[] publications = ParsePublicationsFromHtml(requestResult.result, publicationTitle); cachedPublications.AddRange(publications); Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); return publications; } - private Publication[] ParsePublicationsFromHtml(Stream html, string publicationTitle) + private Manga[] ParsePublicationsFromHtml(Stream html, string publicationTitle) { string jsonString = new StreamReader(html).ReadToEnd(); List result = JsonConvert.DeserializeObject>(jsonString)!; @@ -101,7 +101,7 @@ public class Mangasee : MangaConnector Log($"Retrieved {queryFiltered.Count} publications."); - HashSet ret = new(); + HashSet ret = new(); List orderedFiltered = queryFiltered.OrderBy(item => item.Value).ToDictionary(item => item.Key, item => item.Value).Keys.ToList(); @@ -120,7 +120,7 @@ public class Mangasee : MangaConnector } - private Publication ParseSinglePublicationFromHtml(Stream html, string sortName, string publicationId, string[] a) + private Manga ParseSinglePublicationFromHtml(Stream html, string sortName, string publicationId, string[] a) { StreamReader reader = new (html); HtmlDocument document = new (); @@ -170,7 +170,7 @@ public class Mangasee : MangaConnector foreach(string at in a) altTitles.Add((i++).ToString(), at); - return new Publication(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, links, + return new Manga(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, links, year, originalLanguage, status, publicationId); } @@ -214,10 +214,10 @@ public class Mangasee : MangaConnector } } - public override Chapter[] GetChapters(Publication publication, string language="en") + public override Chapter[] GetChapters(Manga manga, string language="en") { - Log($"Getting chapters {publication}"); - XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{publication.publicationId}.xml"); + Log($"Getting chapters {manga}"); + XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{manga.publicationId}.xml"); XElement[] chapterItems = doc.Descendants("item").ToArray(); List chapters = new(); foreach (XElement chapter in chapterItems) @@ -228,7 +228,7 @@ public class Mangasee : MangaConnector string url = chapter.Descendants("link").First().Value; url = url.Replace(Regex.Matches(url,"(-page-[0-9])")[0].ToString(),""); - chapters.Add(new Chapter(publication, "", volumeNumber, chapterNumber, url)); + chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, url)); } //Return Chapters ordered by Chapter-Number @@ -236,7 +236,7 @@ public class Mangasee : MangaConnector { NumberDecimalSeparator = "." }; - Log($"Got {chapters.Count} chapters. {publication}"); + Log($"Got {chapters.Count} chapters. {manga}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } @@ -244,7 +244,7 @@ public class Mangasee : MangaConnector { if (progressToken?.cancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - Publication chapterParentPublication = chapter.parentPublication; + Manga chapterParentManga = chapter.parentManga; while (this._browser is null && !(progressToken?.cancellationRequested??false)) { Log("Waiting for headless browser to download..."); @@ -253,7 +253,7 @@ public class Mangasee : MangaConnector if (progressToken?.cancellationRequested??false) return HttpStatusCode.RequestTimeout; - Log($"Retrieving chapter-info {chapter} {chapterParentPublication}"); + Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); IPage page = _browser!.NewPageAsync().Result; IResponse response = page.GoToAsync(chapter.url).Result; if (response.Ok) @@ -270,8 +270,8 @@ public class Mangasee : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentPublication.coverUrl is not null) - chapterParentPublication.coverFileNameInCache = SaveCoverImageToCache(chapterParentPublication.coverUrl, 1); + if (chapterParentManga.coverUrl is not null) + chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, 1); return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, progressToken:progressToken); } diff --git a/Tranga/Server.cs b/Tranga/Server.cs index 71b92c9..d223562 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -113,7 +113,7 @@ public class Server : GlobalBase case "Connectors": SendResponse(HttpStatusCode.OK, response, _parent.GetConnectors().Select(con => con.name).ToArray()); break; - case "Publications/FromConnector": + case "Manga/FromConnector": if (!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("title", out string? title) || _parent.GetConnector(connectorName) is null) @@ -124,7 +124,7 @@ public class Server : GlobalBase connector = _parent.GetConnector(connectorName)!; SendResponse(HttpStatusCode.OK, response, connector.GetPublications(title)); break; - case "Publications/Chapters": + case "Manga/Chapters": if(!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("internalId", out string? internalId) || _parent.GetConnector(connectorName) is null || @@ -134,10 +134,10 @@ public class Server : GlobalBase break; } connector = _parent.GetConnector(connectorName)!; - Publication publication = (Publication)_parent.GetPublicationById(internalId)!; - SendResponse(HttpStatusCode.OK, response, connector.GetChapters(publication)); + Manga manga = (Manga)_parent.GetPublicationById(internalId)!; + SendResponse(HttpStatusCode.OK, response, connector.GetChapters(manga)); break; - case "Tasks": + case "Jobs": if (!requestVariables.TryGetValue("jobId", out jobId)) { if(!_parent._jobBoss.jobs.Any(jjob => jjob.id == jobId)) @@ -148,7 +148,7 @@ public class Server : GlobalBase } SendResponse(HttpStatusCode.OK, response, _parent._jobBoss.jobs); break; - case "Tasks/Progress": + case "Jobs/Progress": if (!requestVariables.TryGetValue("jobId", out jobId)) { if(!_parent._jobBoss.jobs.Any(jjob => jjob.id == jobId)) @@ -159,10 +159,10 @@ public class Server : GlobalBase } SendResponse(HttpStatusCode.OK, response, _parent._jobBoss.jobs.Select(jjob => jjob.progressToken)); break; - case "Tasks/Running": + case "Jobs/Running": SendResponse(HttpStatusCode.OK, response, _parent._jobBoss.jobs.Where(jjob => jjob.progressToken.state is ProgressToken.State.Running)); break; - case "Tasks/Waiting": + case "Jobs/Waiting": SendResponse(HttpStatusCode.OK, response, _parent._jobBoss.jobs.Where(jjob => jjob.progressToken.state is ProgressToken.State.Standby)); break; case "Settings": @@ -191,11 +191,11 @@ public class Server : GlobalBase Dictionary requestVariables = GetRequestVariables(request.Url!.Query); string? connectorName, internalId; MangaConnector connector; - Publication publication; + Manga manga; string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value; switch (path) { - case "Tasks/MonitorManga": + case "Jobs/MonitorManga": if(!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("internalId", out internalId) || !requestVariables.TryGetValue("interval", out string? intervalStr) || @@ -207,11 +207,11 @@ public class Server : GlobalBase break; } connector = _parent.GetConnector(connectorName)!; - publication = (Publication)_parent.GetPublicationById(internalId)!; - _parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, publication, true, interval)); + manga = (Manga)_parent.GetPublicationById(internalId)!; + _parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, manga, true, interval)); SendResponse(HttpStatusCode.Accepted, response); break; - case "Tasks/DownloadNewChapters": + case "Jobs/DownloadNewChapters": if(!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("internalId", out internalId) || _parent.GetConnector(connectorName) is null || @@ -221,8 +221,8 @@ public class Server : GlobalBase break; } connector = _parent.GetConnector(connectorName)!; - publication = (Publication)_parent.GetPublicationById(internalId)!; - _parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, publication, false)); + manga = (Manga)_parent.GetPublicationById(internalId)!; + _parent._jobBoss.AddJob(new DownloadNewChapters(this, connector, manga, false)); SendResponse(HttpStatusCode.Accepted, response); break; case "Settings/UpdateDownloadLocation": @@ -325,11 +325,11 @@ public class Server : GlobalBase Dictionary requestVariables = GetRequestVariables(request.Url!.Query); string? connectorName, internalId; MangaConnector connector; - Publication publication; + Manga manga; string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value; switch (path) { - case "Tasks/DownloadChapter": + case "Jobs/DownloadChapter": if(!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("internalId", out internalId) || !requestVariables.TryGetValue("chapterNumber", out string? chapterNumber) || @@ -342,7 +342,7 @@ public class Server : GlobalBase _parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connectorName, internalId, chapterNumber)); SendResponse(HttpStatusCode.Accepted, response); break; - case "Tasks/MonitorManga": + case "Jobs/MonitorManga": if(!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("internalId", out internalId) || _parent.GetConnector(connectorName) is null || @@ -352,11 +352,11 @@ public class Server : GlobalBase break; } connector = _parent.GetConnector(connectorName)!; - publication = (Publication)_parent.GetPublicationById(internalId)!; - _parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connector, publication)); + manga = (Manga)_parent.GetPublicationById(internalId)!; + _parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connector, manga)); SendResponse(HttpStatusCode.Accepted, response); break; - case "Tasks/DownloadNewChapters": + case "Jobs/DownloadNewChapters": if(!requestVariables.TryGetValue("connector", out connectorName) || !requestVariables.TryGetValue("internalId", out internalId) || _parent.GetConnector(connectorName) is null || @@ -366,8 +366,8 @@ public class Server : GlobalBase break; } connector = _parent.GetConnector(connectorName)!; - publication = (Publication)_parent.GetPublicationById(internalId)!; - _parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connector, publication)); + manga = (Manga)_parent.GetPublicationById(internalId)!; + _parent._jobBoss.RemoveJobs(_parent._jobBoss.GetJobsLike(connector, manga)); SendResponse(HttpStatusCode.Accepted, response); break; case "NotificationConnectors": diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index 0034a70..7ed14b3 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -39,7 +39,7 @@ public partial class Tranga : GlobalBase return connectors; } - public Publication? GetPublicationById(string internalId) + public Manga? GetPublicationById(string internalId) { if (cachedPublications.Exists(publication => publication.internalId == internalId)) return cachedPublications.First(publication => publication.internalId == internalId);