From 3b6417eff2eb359129a6472bca2f54da4704d43b Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 31 Jul 2024 17:48:05 +0200 Subject: [PATCH 1/7] Fix #214 HTML encoded Characters --- Tranga/Manga.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 171daad..eb9e5d8 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -1,6 +1,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; +using System.Web; using Newtonsoft.Json; using static System.IO.UnixFileMode; @@ -51,11 +52,11 @@ public struct Manga [JsonConstructor] public Manga(string sortName, List authors, string? description, Dictionary altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary? links, int? year, string? originalLanguage, string publicationId, ReleaseStatusByte releaseStatus, string? websiteUrl = null, string? folderName = null, float? ignoreChaptersBelow = 0) { - this.sortName = sortName; - this.authors = authors; - this.description = description; - this.altTitles = altTitles; - this.tags = tags; + this.sortName = HttpUtility.HtmlDecode(sortName); + this.authors = authors.Select(HttpUtility.HtmlDecode).ToList()!; + this.description = HttpUtility.HtmlDecode(description); + this.altTitles = altTitles.ToDictionary(a => HttpUtility.HtmlDecode(a.Key), a => HttpUtility.HtmlDecode(a.Value)); + this.tags = tags.Select(HttpUtility.HtmlDecode).ToArray()!; this.coverFileNameInCache = coverFileNameInCache; this.coverUrl = coverUrl; this.links = links ?? new Dictionary(); From 926c0d5833ef0aa500a72154d05744ae3f552fb8 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 31 Jul 2024 19:24:59 +0200 Subject: [PATCH 2/7] fix #214 foldernames --- Tranga/Manga.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index eb9e5d8..22fc99a 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -63,7 +63,7 @@ public struct Manga this.year = year; this.originalLanguage = originalLanguage; this.publicationId = publicationId; - this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(sortName)); + this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(HttpUtility.HtmlDecode(sortName))); while (this.folderName.EndsWith('.')) this.folderName = this.folderName.Substring(0, this.folderName.Length - 1); string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter)); From 72bc7ec07bde0889b795533c39ebd739f9521e3f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 05:08:32 +0000 Subject: [PATCH 3/7] Bump docker/build-push-action from 6.5.0 to 6.6.1 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.5.0 to 6.6.1. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v6.5.0...v6.6.1) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/docker-base.yml | 2 +- .github/workflows/docker-image-cuttingedge.yml | 2 +- .github/workflows/docker-image-dev.yml | 2 +- .github/workflows/docker-image-master.yml | 2 +- .github/workflows/docker-image-serverv2.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-base.yml b/.github/workflows/docker-base.yml index 72f2559..7caba73 100644 --- a/.github/workflows/docker-base.yml +++ b/.github/workflows/docker-base.yml @@ -31,7 +31,7 @@ jobs: # https://github.com/docker/build-push-action#multi-platform-image - name: Build and push base - uses: docker/build-push-action@v6.5.0 + uses: docker/build-push-action@v6.6.1 with: context: ./ file: ./Dockerfile-base diff --git a/.github/workflows/docker-image-cuttingedge.yml b/.github/workflows/docker-image-cuttingedge.yml index 175e384..712f2ff 100644 --- a/.github/workflows/docker-image-cuttingedge.yml +++ b/.github/workflows/docker-image-cuttingedge.yml @@ -33,7 +33,7 @@ jobs: # https://github.com/docker/build-push-action#multi-platform-image - name: Build and push API - uses: docker/build-push-action@v6.5.0 + uses: docker/build-push-action@v6.6.1 with: context: ./ file: ./Dockerfile diff --git a/.github/workflows/docker-image-dev.yml b/.github/workflows/docker-image-dev.yml index 28ce4da..36e7350 100644 --- a/.github/workflows/docker-image-dev.yml +++ b/.github/workflows/docker-image-dev.yml @@ -33,7 +33,7 @@ jobs: # https://github.com/docker/build-push-action#multi-platform-image - name: Build and push API - uses: docker/build-push-action@v6.5.0 + uses: docker/build-push-action@v6.6.1 with: context: ./ file: ./Dockerfile diff --git a/.github/workflows/docker-image-master.yml b/.github/workflows/docker-image-master.yml index d51931c..5d9adf9 100644 --- a/.github/workflows/docker-image-master.yml +++ b/.github/workflows/docker-image-master.yml @@ -33,7 +33,7 @@ jobs: # https://github.com/docker/build-push-action#multi-platform-image - name: Build and push API - uses: docker/build-push-action@v6.5.0 + uses: docker/build-push-action@v6.6.1 with: context: ./ file: ./Dockerfile diff --git a/.github/workflows/docker-image-serverv2.yml b/.github/workflows/docker-image-serverv2.yml index 4e869ae..4a3608b 100644 --- a/.github/workflows/docker-image-serverv2.yml +++ b/.github/workflows/docker-image-serverv2.yml @@ -33,7 +33,7 @@ jobs: # https://github.com/docker/build-push-action#multi-platform-image - name: Build and push API - uses: docker/build-push-action@v6.5.0 + uses: docker/build-push-action@v6.6.1 with: context: ./ file: ./Dockerfile From d00881e611cf5f239d5f592fde2d581507436830 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 8 Aug 2024 18:58:40 +0200 Subject: [PATCH 4/7] Add Connector ManhuaPlus https://github.com/C9Glax/tranga/issues/213 --- .../MangaConnectorJsonConverter.cs | 2 + Tranga/MangaConnectors/ManhuaPlus.cs | 184 ++++++++++++++++++ Tranga/Tranga.cs | 3 +- 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 Tranga/MangaConnectors/ManhuaPlus.cs diff --git a/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs b/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs index bde2818..0e3dd78 100644 --- a/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs +++ b/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs @@ -38,6 +38,8 @@ public class MangaConnectorJsonConverter : JsonConverter return this._connectors.First(c => c is Bato); case "Manga4Life": return this._connectors.First(c => c is MangaLife); + case "ManhuaPlus": + return this._connectors.First(c => c is ManhuaPlus); } throw new Exception(); diff --git a/Tranga/MangaConnectors/ManhuaPlus.cs b/Tranga/MangaConnectors/ManhuaPlus.cs new file mode 100644 index 0000000..3fe392c --- /dev/null +++ b/Tranga/MangaConnectors/ManhuaPlus.cs @@ -0,0 +1,184 @@ +using System.Net; +using System.Text.RegularExpressions; +using HtmlAgilityPack; +using Tranga.Jobs; + +namespace Tranga.MangaConnectors; + +public class ManhuaPlus : MangaConnector +{ + public ManhuaPlus(GlobalBase clone) : base(clone, "ManhuaPlus") + { + this.downloadClient = new ChromiumDownloadClient(clone); + } + + public override Manga[] GetManga(string publicationTitle = "") + { + Log($"Searching Publications. Term=\"{publicationTitle}\""); + string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower(); + string requestUrl = $"https://manhuaplus.org/search?keyword={sanitizedTitle}"; + RequestResult requestResult = + downloadClient.MakeRequest(requestUrl, RequestType.Default); + if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) + return Array.Empty(); + + if (requestResult.htmlDocument is null) + return Array.Empty(); + Manga[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument); + Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); + return publications; + } + + private Manga[] ParsePublicationsFromHtml(HtmlDocument document) + { + if (document.DocumentNode.SelectSingleNode("//h1/../..").ChildNodes//I already want to not. + .Any(node => node.InnerText.Contains("No manga found"))) + return Array.Empty(); + + List urls = document.DocumentNode + .SelectNodes("//h1/../..//a[contains(@href, 'https://manhuaplus.org/manga/') and contains(concat(' ',normalize-space(@class),' '),' clamp ') and not(contains(@href, '/chapter'))]") + .Select(mangaNode => mangaNode.GetAttributeValue("href", "")).ToList(); + logger?.WriteLine($"Got {urls.Count} urls."); + + HashSet ret = new(); + foreach (string url in urls) + { + Manga? manga = GetMangaFromUrl(url); + if (manga is not null) + ret.Add((Manga)manga); + } + + return ret.ToArray(); + } + + public override Manga? GetMangaFromId(string publicationId) + { + return GetMangaFromUrl($"https://manhuaplus.org/manga/{publicationId}"); + } + + public override Manga? GetMangaFromUrl(string url) + { + Regex publicationIdRex = new(@"https:\/\/manhuaplus.org\/manga\/(.*)(\/.*)*"); + string publicationId = publicationIdRex.Match(url).Groups[1].Value; + + RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo); + if((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 && requestResult.htmlDocument is not null && requestResult.redirectedToUrl != "https://manhuaplus.org/home") //When manga doesnt exists it redirects to home + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url); + return null; + } + + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) + { + string originalLanguage = "", status = ""; + Dictionary altTitles = new(), links = new(); + HashSet tags = new(); + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; + + HtmlNode posterNode = document.DocumentNode.SelectSingleNode("/html/body/main/div/div/div[2]/div[1]/figure/a/img");//BRUH + Regex posterRex = new(@".*(\/uploads/covers/[a-zA-Z0-9\-\._\~\!\$\&\'\(\)\*\+\,\;\=\:\@]+).*"); + string posterUrl = $"https://manhuaplus.org/{posterRex.Match(posterNode.GetAttributeValue("src", "")).Groups[1].Value}"; + string coverFileNameInCache = SaveCoverImageToCache(posterUrl, publicationId, RequestType.MangaCover); + + HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//h1"); + string sortName = titleNode.InnerText.Replace("\n", ""); + + HtmlNode[] authorsNodes = document.DocumentNode + .SelectNodes("//a[contains(@href, 'https://manhuaplus.org/authors/')]") + .ToArray(); + List authors = new(); + foreach (HtmlNode authorNode in authorsNodes) + authors.Add(authorNode.InnerText); + + HtmlNode[] genreNodes = document.DocumentNode + .SelectNodes("//a[contains(@href, 'https://manhuaplus.org/genres/')]").ToArray(); + foreach (HtmlNode genreNode in genreNodes) + tags.Add(genreNode.InnerText.Replace("\n", "")); + + string yearNodeStr = document.DocumentNode + .SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span").InnerText.Replace("\n", ""); + int year = int.Parse(yearNodeStr.Split(' ')[0].Split('/')[^1]); + + status = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-rss ')]/../span").InnerText.Replace("\n", ""); + switch (status.ToLower()) + { + case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + } + + HtmlNode descriptionNode = document.DocumentNode + .SelectSingleNode("//div[@id='syn-target']"); + string description = descriptionNode.InnerText; + + Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, + coverFileNameInCache, links, + year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); + AddMangaToCache(manga); + return manga; + } + + public override Chapter[] GetChapters(Manga manga, string language="en") + { + Log($"Getting chapters {manga}"); + RequestResult result = downloadClient.MakeRequest($"https://manhuaplus.org/manga/{manga.publicationId}", RequestType.Default); + if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null) + { + return Array.Empty(); + } + + HtmlNodeCollection chapterNodes = result.htmlDocument.DocumentNode.SelectNodes("//li[contains(concat(' ',normalize-space(@class),' '),' chapter ')]//a"); + string[] urls = chapterNodes.Select(node => node.GetAttributeValue("href", "")).ToArray(); + Regex urlRex = new (@".*\/chapter-([0-9\-]+).*"); + + List chapters = new(); + foreach (string url in urls) + { + Match rexMatch = urlRex.Match(url); + + string volumeNumber = "1"; + string chapterNumber = rexMatch.Groups[1].Value; + string fullUrl = url; + chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl)); + } + //Return Chapters ordered by Chapter-Number + Log($"Got {chapters.Count} chapters. {manga}"); + return chapters.Order().ToArray(); + } + + public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null) + { + if (progressToken?.cancellationRequested ?? false) + { + progressToken.Cancel(); + return HttpStatusCode.RequestTimeout; + } + + Manga chapterParentManga = chapter.parentManga; + if (progressToken?.cancellationRequested ?? false) + { + progressToken.Cancel(); + return HttpStatusCode.RequestTimeout; + } + + Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); + + RequestResult requestResult = this.downloadClient.MakeRequest(chapter.url, RequestType.Default); + if (requestResult.htmlDocument is null) + { + progressToken?.Cancel(); + return HttpStatusCode.RequestTimeout; + } + + HtmlDocument document = requestResult.htmlDocument; + + HtmlNode[] images = document.DocumentNode.SelectNodes("//a[contains(concat(' ',normalize-space(@class),' '),' readImg ')]/img").ToArray(); + List urls = images.Select(node => node.GetAttributeValue("src", "")).ToList(); + + string comicInfoPath = Path.GetTempFileName(); + File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); + + return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken); + } +} \ No newline at end of file diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index 5413fa5..b19720e 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -24,7 +24,8 @@ public partial class Tranga : GlobalBase new MangaKatana(this), new Mangaworld(this), new Bato(this), - new MangaLife(this) + new MangaLife(this), + new ManhuaPlus(this) }; foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders dir.Delete(); From bc101363319836aa9b3564c6b78c070b20f81b45 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 8 Aug 2024 21:00:37 +0200 Subject: [PATCH 5/7] MangaHere image download sucks, you have to iterate all over all images one by one. Have some extra traffic then, idc. https://github.com/C9Glax/tranga/issues/69 --- Tranga/MangaConnectors/MangaConnector.cs | 4 +- .../MangaConnectorJsonConverter.cs | 2 + Tranga/MangaConnectors/MangaHere.cs | 202 ++++++++++++++++++ Tranga/Tranga.cs | 3 +- 4 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 Tranga/MangaConnectors/MangaHere.cs diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index 6dbcb45..5c71de8 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -222,8 +222,8 @@ public abstract class MangaConnector : GlobalBase if (progressToken?.cancellationRequested ?? false) return HttpStatusCode.RequestTimeout; Log($"Downloading Images for {saveArchiveFilePath}"); - if(progressToken is not null) - progressToken.increments = imageUrls.Length; + if (progressToken is not null) + progressToken.increments += imageUrls.Length; //Check if Publication Directory already exists string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!; if (!Directory.Exists(directoryPath)) diff --git a/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs b/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs index 0e3dd78..2213a48 100644 --- a/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs +++ b/Tranga/MangaConnectors/MangaConnectorJsonConverter.cs @@ -40,6 +40,8 @@ public class MangaConnectorJsonConverter : JsonConverter return this._connectors.First(c => c is MangaLife); case "ManhuaPlus": return this._connectors.First(c => c is ManhuaPlus); + case "MangaHere": + return this._connectors.First(c => c is MangaHere); } throw new Exception(); diff --git a/Tranga/MangaConnectors/MangaHere.cs b/Tranga/MangaConnectors/MangaHere.cs new file mode 100644 index 0000000..7b13d4d --- /dev/null +++ b/Tranga/MangaConnectors/MangaHere.cs @@ -0,0 +1,202 @@ +using System.Net; +using System.Text.RegularExpressions; +using HtmlAgilityPack; +using Tranga.Jobs; + +namespace Tranga.MangaConnectors; + +public class MangaHere : MangaConnector +{ + public MangaHere(GlobalBase clone) : base(clone, "MangaHere") + { + this.downloadClient = new ChromiumDownloadClient(clone); + } + + public override Manga[] GetManga(string publicationTitle = "") + { + Log($"Searching Publications. Term=\"{publicationTitle}\""); + string sanitizedTitle = string.Join('+', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower(); + string requestUrl = $"https://www.mangahere.cc/search?title={sanitizedTitle}"; + RequestResult requestResult = + downloadClient.MakeRequest(requestUrl, RequestType.Default); + if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null) + return Array.Empty(); + + Manga[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument); + Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); + return publications; + } + + private Manga[] ParsePublicationsFromHtml(HtmlDocument document) + { + if (document.DocumentNode.SelectNodes("//div[contains(concat(' ',normalize-space(@class),' '),' container ')]").Any(node => node.ChildNodes.Any(cNode => cNode.HasClass("search-keywords")))) + return Array.Empty(); + + List urls = document.DocumentNode + .SelectNodes("//a[contains(@href, '/manga/') and not(contains(@href, '.html'))]") + .Select(thumb => $"https://www.mangahere.cc{thumb.GetAttributeValue("href", "")}").Distinct().ToList(); + + HashSet ret = new(); + foreach (string url in urls) + { + Manga? manga = GetMangaFromUrl(url); + if (manga is not null) + ret.Add((Manga)manga); + } + + return ret.ToArray(); + } + + public override Manga? GetMangaFromId(string publicationId) + { + return GetMangaFromUrl($"https://www.mangahere.cc/manga/{publicationId}"); + } + + public override Manga? GetMangaFromUrl(string url) + { + RequestResult requestResult = + downloadClient.MakeRequest(url, RequestType.MangaInfo); + if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null) + return null; + + Regex idRex = new (@"https:\/\/www\.mangahere\.[a-z]{0,63}\/manga\/([0-9A-z\-]+).*"); + string id = idRex.Match(url).Groups[1].Value; + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id, url); + } + + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) + { + string originalLanguage = "", status = ""; + Dictionary altTitles = new(), links = new(); + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; + + //We dont get posters, because same origin bs HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//img[contains(concat(' ',normalize-space(@class),' '),' detail-info-cover-img ')]"); + string posterUrl = "http://static.mangahere.cc/v20230914/mangahere/images/nopicture.jpg"; + string coverFileNameInCache = SaveCoverImageToCache(posterUrl, publicationId, RequestType.MangaCover); + + HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//span[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-title-font ')]"); + string sortName = titleNode.InnerText; + + List authors = document.DocumentNode + .SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-say ')]/a") + .Select(node => node.InnerText) + .ToList(); + + HashSet tags = document.DocumentNode + .SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-tag-list ')]/a") + .Select(node => node.InnerText) + .ToHashSet(); + + status = document.DocumentNode.SelectSingleNode("//span[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-title-tip ')]").InnerText; + switch (status.ToLower()) + { + case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + } + + HtmlNode descriptionNode = document.DocumentNode + .SelectSingleNode("//p[contains(concat(' ',normalize-space(@class),' '),' fullcontent ')]"); + string description = descriptionNode.InnerText; + + Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, + coverFileNameInCache, links, + null, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); + AddMangaToCache(manga); + return manga; + } + + public override Chapter[] GetChapters(Manga manga, string language="en") + { + Log($"Getting chapters {manga}"); + string requestUrl = $"https://www.mangahere.cc/manga/{manga.publicationId}"; + RequestResult requestResult = + downloadClient.MakeRequest(requestUrl, RequestType.Default); + if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null) + return Array.Empty(); + + List urls = requestResult.htmlDocument.DocumentNode.SelectNodes("//div[@id='list-2']/ul//li//a[contains(@href, '/manga/')]") + .Select(node => node.GetAttributeValue("href", "")).ToList(); + Regex chapterRex = new(@".*\/manga\/[a-zA-Z0-9\-\._\~\!\$\&\'\(\)\*\+\,\;\=\:\@]+\/v([0-9(TBD)]+)\/c([0-9\.]+)\/.*"); + + List chapters = new(); + foreach (string url in urls) + { + Match rexMatch = chapterRex.Match(url); + + string volumeNumber = rexMatch.Groups[1].Value == "TBD" ? "0" : rexMatch.Groups[1].Value; + string chapterNumber = rexMatch.Groups[2].Value; + string fullUrl = $"https://www.mangahere.cc{url}"; + chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl)); + } + //Return Chapters ordered by Chapter-Number + Log($"Got {chapters.Count} chapters. {manga}"); + return chapters.Order().ToArray(); + } + + public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null) + { + if (progressToken?.cancellationRequested ?? false) + { + progressToken.Cancel(); + return HttpStatusCode.RequestTimeout; + } + + Manga chapterParentManga = chapter.parentManga; + Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); + + List imageUrls = new(); + + int downloaded = 1; + int images = 1; + string url = string.Join('/', chapter.url.Split('/')[..^1]); + do + { + RequestResult requestResult = + downloadClient.MakeRequest($"{url}/{downloaded}.html", RequestType.Default); + if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) + { + progressToken?.Cancel(); + return requestResult.statusCode; + } + + if (requestResult.htmlDocument is null) + { + progressToken?.Cancel(); + return HttpStatusCode.InternalServerError; + } + + imageUrls.AddRange(ParseImageUrlsFromHtml(requestResult.htmlDocument)); + + images = requestResult.htmlDocument.DocumentNode + .SelectNodes("//a[contains(@href, '/manga/')]") + .MaxBy(node => node.GetAttributeValue("data-page", 0))!.GetAttributeValue("data-page", 0); + if (progressToken is not null) + { + progressToken.increments = images * 2;//we also have to download the images later + progressToken.Increment(); + } + } while (downloaded++ <= images); + + string comicInfoPath = Path.GetTempFileName(); + File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); + + if (progressToken is not null) + progressToken.increments = images;//we blip to normal length, in downloadchapterimages it is increasaed by the amount of urls again + return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken); + } + + private string[] ParseImageUrlsFromHtml(HtmlDocument document) + { + return document.DocumentNode + .SelectNodes("//img[contains(concat(' ',normalize-space(@class),' '),' reader-main-img ')]") + .Select(node => + { + string url = node.GetAttributeValue("src", ""); + return url.StartsWith("//") ? $"https:{url}" : url; + }) + .ToArray(); + } +} \ No newline at end of file diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index b19720e..1471365 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -25,7 +25,8 @@ public partial class Tranga : GlobalBase new Mangaworld(this), new Bato(this), new MangaLife(this), - new ManhuaPlus(this) + new ManhuaPlus(this), + new MangaHere(this), }; foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders dir.Delete(); From 200a22228f3dcedfc21d22eb14e7cbf2079aa230 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 8 Aug 2024 21:02:13 +0200 Subject: [PATCH 6/7] add log output for Mangahere https://github.com/C9Glax/tranga/issues/69 --- Tranga/MangaConnectors/MangaHere.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Tranga/MangaConnectors/MangaHere.cs b/Tranga/MangaConnectors/MangaHere.cs index 7b13d4d..fc9406e 100644 --- a/Tranga/MangaConnectors/MangaHere.cs +++ b/Tranga/MangaConnectors/MangaHere.cs @@ -173,6 +173,7 @@ public class MangaHere : MangaConnector images = requestResult.htmlDocument.DocumentNode .SelectNodes("//a[contains(@href, '/manga/')]") .MaxBy(node => node.GetAttributeValue("data-page", 0))!.GetAttributeValue("data-page", 0); + logger?.WriteLine($"MangaHere speciality: Get Image-url {downloaded}/{images}"); if (progressToken is not null) { progressToken.increments = images * 2;//we also have to download the images later From 34dd78810dfd6c5af58cf9ce5ca9a4bb84c08fa2 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 8 Aug 2024 21:09:08 +0200 Subject: [PATCH 7/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6137396..05a0d79 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Tranga can download Chapters and Metadata from "Scanlation" sites such as - [Mangaworld.bz](https://www.mangaworld.bz/) (it) - [Bato.to](https://bato.to/v3x) (en) - [Manga4Life](https://manga4life.com) (en) +- [ManhuaPlus](https://manhuaplus.org/) (en) +- [MangaHere](https://www.mangahere.cc/) (en) (Their covers suck) - ❓ Open an [issue](https://github.com/C9Glax/tranga/issues) and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).