Compare commits
No commits in common. "fc884adc9fd3294335e9385db5eef21779036582" and "6b9ddca711dead3787bdc9412f17f3e0ee8be977" have entirely different histories.
fc884adc9f
...
6b9ddca711
2
.github/workflows/docker-base.yml
vendored
2
.github/workflows/docker-base.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push base
|
- name: Build and push base
|
||||||
uses: docker/build-push-action@v6.6.1
|
uses: docker/build-push-action@v6.5.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile-base
|
file: ./Dockerfile-base
|
||||||
|
@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.6.1
|
uses: docker/build-push-action@v6.5.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
2
.github/workflows/docker-image-dev.yml
vendored
2
.github/workflows/docker-image-dev.yml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.6.1
|
uses: docker/build-push-action@v6.5.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
2
.github/workflows/docker-image-master.yml
vendored
2
.github/workflows/docker-image-master.yml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.6.1
|
uses: docker/build-push-action@v6.5.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
2
.github/workflows/docker-image-serverv2.yml
vendored
2
.github/workflows/docker-image-serverv2.yml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.6.1
|
uses: docker/build-push-action@v6.5.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
@ -50,8 +50,6 @@ Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
|||||||
- [Mangaworld.bz](https://www.mangaworld.bz/) (it)
|
- [Mangaworld.bz](https://www.mangaworld.bz/) (it)
|
||||||
- [Bato.to](https://bato.to/v3x) (en)
|
- [Bato.to](https://bato.to/v3x) (en)
|
||||||
- [Manga4Life](https://manga4life.com) (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)
|
- ❓ 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/).
|
and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).
|
||||||
|
@ -74,6 +74,11 @@ public abstract class GlobalBase
|
|||||||
internal void ImportManga()
|
internal void ImportManga()
|
||||||
{
|
{
|
||||||
string folder = settings.mangaCacheFolderPath;
|
string folder = settings.mangaCacheFolderPath;
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
Directory.CreateDirectory(folder,
|
||||||
|
UnixFileMode.GroupRead | UnixFileMode.GroupWrite | UnixFileMode.OtherRead | UnixFileMode.OtherWrite |
|
||||||
|
UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
||||||
|
else
|
||||||
Directory.CreateDirectory(folder);
|
Directory.CreateDirectory(folder);
|
||||||
|
|
||||||
foreach (FileInfo fileInfo in new DirectoryInfo(folder).GetFiles())
|
foreach (FileInfo fileInfo in new DirectoryInfo(folder).GetFiles())
|
||||||
@ -95,6 +100,11 @@ public abstract class GlobalBase
|
|||||||
private void ExportManga()
|
private void ExportManga()
|
||||||
{
|
{
|
||||||
string folder = settings.mangaCacheFolderPath;
|
string folder = settings.mangaCacheFolderPath;
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
Directory.CreateDirectory(folder,
|
||||||
|
UnixFileMode.GroupRead | UnixFileMode.GroupWrite | UnixFileMode.OtherRead | UnixFileMode.OtherWrite |
|
||||||
|
UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
||||||
|
else
|
||||||
Directory.CreateDirectory(folder);
|
Directory.CreateDirectory(folder);
|
||||||
foreach (Manga manga in cachedPublications.Values)
|
foreach (Manga manga in cachedPublications.Values)
|
||||||
{
|
{
|
||||||
|
@ -195,9 +195,6 @@ public class JobBoss : GlobalBase
|
|||||||
string[] coverFiles = Directory.GetFiles(settings.coverImageCache);
|
string[] coverFiles = Directory.GetFiles(settings.coverImageCache);
|
||||||
foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName)))
|
foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName)))
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
string[] mangaFiles = Directory.GetFiles(settings.mangaCacheFolderPath);
|
|
||||||
foreach(string fileName in mangaFiles.Where(fileName => !GetAllCachedManga().Any(manga => fileName.Split('.')[0] == manga.internalId)))
|
|
||||||
File.Delete(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UpdateJobFile(Job job, string? oldFile = null)
|
internal void UpdateJobFile(Job job, string? oldFile = null)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Web;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.MangaConnectors;
|
using Tranga.MangaConnectors;
|
||||||
using static System.IO.UnixFileMode;
|
using static System.IO.UnixFileMode;
|
||||||
@ -52,18 +51,18 @@ public struct Manga
|
|||||||
public Manga(MangaConnector mangaConnector, string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string publicationId, ReleaseStatusByte releaseStatus, string? websiteUrl, string? folderName = null, float? ignoreChaptersBelow = 0)
|
public Manga(MangaConnector mangaConnector, string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string publicationId, ReleaseStatusByte releaseStatus, string? websiteUrl, string? folderName = null, float? ignoreChaptersBelow = 0)
|
||||||
{
|
{
|
||||||
this.mangaConnector = mangaConnector;
|
this.mangaConnector = mangaConnector;
|
||||||
this.sortName = HttpUtility.HtmlDecode(sortName);
|
this.sortName = sortName;
|
||||||
this.authors = authors.Select(HttpUtility.HtmlDecode).ToList()!;
|
this.authors = authors;
|
||||||
this.description = HttpUtility.HtmlDecode(description);
|
this.description = description;
|
||||||
this.altTitles = altTitles.ToDictionary(a => HttpUtility.HtmlDecode(a.Key), a => HttpUtility.HtmlDecode(a.Value));
|
this.altTitles = altTitles;
|
||||||
this.tags = tags.Select(HttpUtility.HtmlDecode).ToArray()!;
|
this.tags = tags;
|
||||||
this.coverFileNameInCache = coverFileNameInCache;
|
this.coverFileNameInCache = coverFileNameInCache;
|
||||||
this.coverUrl = coverUrl;
|
this.coverUrl = coverUrl;
|
||||||
this.links = links ?? new Dictionary<string, string>();
|
this.links = links ?? new Dictionary<string, string>();
|
||||||
this.year = year;
|
this.year = year;
|
||||||
this.originalLanguage = originalLanguage;
|
this.originalLanguage = originalLanguage;
|
||||||
this.publicationId = publicationId;
|
this.publicationId = publicationId;
|
||||||
this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(HttpUtility.HtmlDecode(sortName)));
|
this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(sortName));
|
||||||
while (this.folderName.EndsWith('.'))
|
while (this.folderName.EndsWith('.'))
|
||||||
this.folderName = this.folderName.Substring(0, this.folderName.Length - 1);
|
this.folderName = this.folderName.Substring(0, this.folderName.Length - 1);
|
||||||
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
|
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
|
||||||
|
@ -223,7 +223,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
return HttpStatusCode.RequestTimeout;
|
return HttpStatusCode.RequestTimeout;
|
||||||
Log($"Downloading Images for {saveArchiveFilePath}");
|
Log($"Downloading Images for {saveArchiveFilePath}");
|
||||||
if(progressToken is not null)
|
if(progressToken is not null)
|
||||||
progressToken.increments += imageUrls.Length;
|
progressToken.increments = imageUrls.Length;
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||||
if (!Directory.Exists(directoryPath))
|
if (!Directory.Exists(directoryPath))
|
||||||
|
@ -38,10 +38,6 @@ public class MangaConnectorJsonConverter : JsonConverter
|
|||||||
return this._connectors.First(c => c is Bato);
|
return this._connectors.First(c => c is Bato);
|
||||||
case "Manga4Life":
|
case "Manga4Life":
|
||||||
return this._connectors.First(c => c is MangaLife);
|
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();
|
throw new Exception();
|
||||||
|
@ -1,203 +0,0 @@
|
|||||||
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>();
|
|
||||||
|
|
||||||
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<Manga>();
|
|
||||||
|
|
||||||
List<string> 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<Manga> 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<string, string> 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<string> authors = document.DocumentNode
|
|
||||||
.SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-say ')]/a")
|
|
||||||
.Select(node => node.InnerText)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
HashSet<string> 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(this, 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<Chapter>();
|
|
||||||
|
|
||||||
List<string> 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<Chapter> 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<string> 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);
|
|
||||||
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
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,184 +0,0 @@
|
|||||||
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<Manga>();
|
|
||||||
|
|
||||||
if (requestResult.htmlDocument is null)
|
|
||||||
return Array.Empty<Manga>();
|
|
||||||
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<Manga>();
|
|
||||||
|
|
||||||
List<string> 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<Manga> 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<string, string> altTitles = new(), links = new();
|
|
||||||
HashSet<string> 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<string> 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(this, 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<Chapter>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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<Chapter> 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<string> 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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -37,7 +37,7 @@ public partial class Server : GlobalBase, IDisposable
|
|||||||
new ("GET", @"/v2/Jobs/Running", GetV2JobsRunning),
|
new ("GET", @"/v2/Jobs/Running", GetV2JobsRunning),
|
||||||
new ("GET", @"/v2/Jobs/Waiting", GetV2JobsWaiting),
|
new ("GET", @"/v2/Jobs/Waiting", GetV2JobsWaiting),
|
||||||
new ("GET", @"/v2/Jobs/Monitoring", GetV2JobsMonitoring),
|
new ("GET", @"/v2/Jobs/Monitoring", GetV2JobsMonitoring),
|
||||||
new ("GET", @"/v2/Job/Types", GetV2JobTypes),
|
new ("Get", @"/v2/Job/Types", GetV2JobTypes),
|
||||||
new ("POST", @"/v2/Job/Create/([a-zA-Z]+)", PostV2JobCreateType),
|
new ("POST", @"/v2/Job/Create/([a-zA-Z]+)", PostV2JobCreateType),
|
||||||
new ("GET", @"/v2/Job", GetV2Job),
|
new ("GET", @"/v2/Job", GetV2Job),
|
||||||
new ("GET", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)", GetV2JobJobId),
|
new ("GET", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)", GetV2JobJobId),
|
||||||
@ -114,15 +114,9 @@ public partial class Server : GlobalBase, IDisposable
|
|||||||
HttpListenerRequest request = context.Request;
|
HttpListenerRequest request = context.Request;
|
||||||
HttpListenerResponse response = context.Response;
|
HttpListenerResponse response = context.Response;
|
||||||
if (request.HttpMethod == "OPTIONS")
|
if (request.HttpMethod == "OPTIONS")
|
||||||
{
|
SendResponse(HttpStatusCode.OK, context.Response); //Response always contains all valid Request-Methods
|
||||||
SendResponse(HttpStatusCode.NoContent, response);//Response always contains all valid Request-Methods
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (request.Url!.LocalPath.Contains("favicon"))
|
if (request.Url!.LocalPath.Contains("favicon"))
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.NoContent, response);
|
SendResponse(HttpStatusCode.NoContent, response);
|
||||||
return;
|
|
||||||
}
|
|
||||||
string path = Regex.Match(request.Url.LocalPath, @"\/[a-zA-Z0-9\.+/=-]+(\/[a-zA-Z0-9\.+/=-]+)*").Value; //Local Path
|
string path = Regex.Match(request.Url.LocalPath, @"\/[a-zA-Z0-9\.+/=-]+(\/[a-zA-Z0-9\.+/=-]+)*").Value; //Local Path
|
||||||
|
|
||||||
if (!Regex.IsMatch(path, "/v2(/.*)?")) //Use only v2 API
|
if (!Regex.IsMatch(path, "/v2(/.*)?")) //Use only v2 API
|
||||||
@ -171,7 +165,7 @@ public partial class Server : GlobalBase, IDisposable
|
|||||||
{
|
{
|
||||||
if (!request.HasEntityBody)
|
if (!request.HasEntityBody)
|
||||||
{
|
{
|
||||||
//Nospam Log("No request body");
|
Log("No request body");
|
||||||
return new Dictionary<string, string>();
|
return new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
Stream body = request.InputStream;
|
Stream body = request.InputStream;
|
||||||
|
@ -76,7 +76,7 @@ public partial class Server
|
|||||||
!_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) ||
|
!_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) ||
|
||||||
manga is null)
|
manga is null)
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
|
||||||
string filePath = manga.Value.coverFileNameInCache!;
|
string filePath = settings.GetFullCoverPath((Manga)manga!);
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
FileStream coverStream = new(filePath, FileMode.Open);
|
FileStream coverStream = new(filePath, FileMode.Open);
|
||||||
|
@ -23,9 +23,7 @@ public partial class Tranga : GlobalBase
|
|||||||
new MangaKatana(this),
|
new MangaKatana(this),
|
||||||
new Mangaworld(this),
|
new Mangaworld(this),
|
||||||
new Bato(this),
|
new Bato(this),
|
||||||
new MangaLife(this),
|
new MangaLife(this)
|
||||||
new ManhuaPlus(this),
|
|
||||||
new MangaHere(this),
|
|
||||||
};
|
};
|
||||||
foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders
|
foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders
|
||||||
dir.Delete();
|
dir.Delete();
|
||||||
|
@ -38,7 +38,7 @@ public partial class Tranga : GlobalBase
|
|||||||
|
|
||||||
TrangaSettings? settings = null;
|
TrangaSettings? settings = null;
|
||||||
bool dlp = fetched.TryGetValue(downloadLocation, out string[]? downloadLocationPath);
|
bool dlp = fetched.TryGetValue(downloadLocation, out string[]? downloadLocationPath);
|
||||||
bool wdp = fetched.TryGetValue(workingDirectory, out string[]? workingDirectoryPath);
|
bool wdp = fetched.TryGetValue(downloadLocation, out string[]? workingDirectoryPath);
|
||||||
|
|
||||||
if (dlp && wdp)
|
if (dlp && wdp)
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ public partial class Tranga : GlobalBase
|
|||||||
}else if (wdp)
|
}else if (wdp)
|
||||||
{
|
{
|
||||||
if (settings is null)
|
if (settings is null)
|
||||||
settings = new TrangaSettings(workingDirectory: workingDirectoryPath![0]);
|
settings = new TrangaSettings(downloadLocation: workingDirectoryPath![0]);
|
||||||
else
|
else
|
||||||
settings = new TrangaSettings(settings.downloadLocation, workingDirectoryPath![0]);
|
settings = new TrangaSettings(settings.downloadLocation, workingDirectoryPath![0]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user