mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-09 08:22:11 +02:00
Compare commits
No commits in common. "5bb4977876524096b9a2613c12fabe3ef0ad9057" and "ce5538b35209e2759ee83e53be3a8f661f4f5db4" have entirely different histories.
5bb4977876
...
ce5538b352
@ -44,7 +44,7 @@ public readonly struct Chapter : IComparable
|
|||||||
if (name is not null && name.Length > 0)
|
if (name is not null && name.Length > 0)
|
||||||
{
|
{
|
||||||
string chapterName = IllegalStrings.Replace(string.Concat(LegalCharacters.Matches(name)), "");
|
string chapterName = IllegalStrings.Replace(string.Concat(LegalCharacters.Matches(name)), "");
|
||||||
this.fileName = chapterName.Length > 0 ? $"{chapterVolNumStr} - {chapterName}" : chapterVolNumStr;
|
this.fileName = $"{chapterVolNumStr} - {chapterName}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.fileName = chapterVolNumStr;
|
this.fileName = chapterVolNumStr;
|
||||||
@ -96,20 +96,17 @@ public readonly struct Chapter : IComparable
|
|||||||
if(mangaArchive is null)
|
if(mangaArchive is null)
|
||||||
{
|
{
|
||||||
FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz");
|
FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz");
|
||||||
Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)(?: - (.*))?.cbz");
|
Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)");
|
||||||
|
|
||||||
Chapter t = this;
|
Chapter t = this;
|
||||||
mangaArchive = archives.FirstOrDefault(archive =>
|
mangaArchive = archives.FirstOrDefault(archive =>
|
||||||
{
|
{
|
||||||
Match m = volChRex.Match(archive.Name);
|
Match m = volChRex.Match(archive.Name);
|
||||||
/*
|
if (m.Groups[1].Success)
|
||||||
* 1. If the volumeNumber is not present in the filename, it is not checked.
|
return m.Groups[1].Value == t.volumeNumber.ToString(GlobalBase.numberFormatDecimalPoint) &&
|
||||||
* 2. Check the chapterNumber in the chapter against the one in the filename.
|
m.Groups[2].Value == t.chapterNumber.ToString(GlobalBase.numberFormatDecimalPoint);
|
||||||
* 3. The chpaterName has to either be absent both in the chapter and the filename or match.
|
else
|
||||||
*/
|
return m.Groups[2].Value == t.chapterNumber.ToString(GlobalBase.numberFormatDecimalPoint);
|
||||||
return (!m.Groups[1].Success || m.Groups[1].Value == t.volumeNumber.ToString(GlobalBase.numberFormatDecimalPoint)) &&
|
|
||||||
m.Groups[2].Value == t.chapterNumber.ToString(GlobalBase.numberFormatDecimalPoint) &&
|
|
||||||
((!m.Groups[3].Success && string.IsNullOrEmpty(t.name)) || m.Groups[3].Value == t.name);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
using Soenneker.Utils.String.NeedlemanWunsch;
|
||||||
using Tranga.Jobs;
|
using Tranga.Jobs;
|
||||||
|
|
||||||
namespace Tranga.MangaConnectors;
|
namespace Tranga.MangaConnectors;
|
||||||
@ -21,10 +22,10 @@ public class Weebcentral : MangaConnector
|
|||||||
{
|
{
|
||||||
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||||
const int limit = 32; //How many values we want returned at once
|
const int limit = 32; //How many values we want returned at once
|
||||||
int offset = 0; //"Page"
|
var offset = 0; //"Page"
|
||||||
string requestUrl =
|
var requestUrl =
|
||||||
$"{_baseUrl}/search/data?limit={limit}&offset={offset}&text={publicationTitle}&sort=Best+Match&order=Ascending&official=Any&display_mode=Minimal%20Display";
|
$"{_baseUrl}/search/data?limit={limit}&offset={offset}&text={publicationTitle}&sort=Best+Match&order=Ascending&official=Any&display_mode=Minimal%20Display";
|
||||||
RequestResult requestResult =
|
var requestResult =
|
||||||
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 ||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 ||
|
||||||
requestResult.htmlDocument == null)
|
requestResult.htmlDocument == null)
|
||||||
@ -33,7 +34,7 @@ public class Weebcentral : MangaConnector
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Manga[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
var publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\"");
|
Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\"");
|
||||||
|
|
||||||
return publications;
|
return publications;
|
||||||
@ -44,13 +45,13 @@ public class Weebcentral : MangaConnector
|
|||||||
if (document.DocumentNode.SelectNodes("//article") == null)
|
if (document.DocumentNode.SelectNodes("//article") == null)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
List<string> urls = document.DocumentNode.SelectNodes("/html/body/article/a[@class='link link-hover']")
|
var urls = document.DocumentNode.SelectNodes("/html/body/article/a[@class='link link-hover']")
|
||||||
.Select(elem => elem.GetAttributeValue("href", "")).ToList();
|
.Select(elem => elem.GetAttributeValue("href", "")).ToList();
|
||||||
|
|
||||||
HashSet<Manga> ret = new();
|
HashSet<Manga> ret = new();
|
||||||
foreach (string url in urls)
|
foreach (var url in urls)
|
||||||
{
|
{
|
||||||
Manga? manga = GetMangaFromUrl(url);
|
var manga = GetMangaFromUrl(url);
|
||||||
if (manga is not null)
|
if (manga is not null)
|
||||||
ret.Add((Manga)manga);
|
ret.Add((Manga)manga);
|
||||||
}
|
}
|
||||||
@ -61,9 +62,9 @@ public class Weebcentral : MangaConnector
|
|||||||
public override Manga? GetMangaFromUrl(string url)
|
public override Manga? GetMangaFromUrl(string url)
|
||||||
{
|
{
|
||||||
Regex publicationIdRex = new(@"https:\/\/weebcentral\.com\/series\/(\w*)\/(.*)");
|
Regex publicationIdRex = new(@"https:\/\/weebcentral\.com\/series\/(\w*)\/(.*)");
|
||||||
string publicationId = publicationIdRex.Match(url).Groups[1].Value;
|
var publicationId = publicationIdRex.Match(url).Groups[1].Value;
|
||||||
|
|
||||||
RequestResult requestResult = downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
var requestResult = downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
if ((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 &&
|
if ((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 &&
|
||||||
requestResult.htmlDocument is not null)
|
requestResult.htmlDocument is not null)
|
||||||
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||||
@ -72,26 +73,26 @@ public class Weebcentral : MangaConnector
|
|||||||
|
|
||||||
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
{
|
{
|
||||||
HtmlNode? posterNode =
|
var posterNode =
|
||||||
document.DocumentNode.SelectSingleNode("//section[@class='flex items-center justify-center']/picture/img");
|
document.DocumentNode.SelectSingleNode("//section[@class='flex items-center justify-center']/picture/img");
|
||||||
string posterUrl = posterNode?.GetAttributeValue("src", "") ?? "";
|
var posterUrl = posterNode?.GetAttributeValue("src", "") ?? "";
|
||||||
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, publicationId, RequestType.MangaCover);
|
var coverFileNameInCache = SaveCoverImageToCache(posterUrl, publicationId, RequestType.MangaCover);
|
||||||
|
|
||||||
HtmlNode? titleNode = document.DocumentNode.SelectSingleNode("//section/h1");
|
var titleNode = document.DocumentNode.SelectSingleNode("//section/h1");
|
||||||
string sortName = titleNode?.InnerText ?? "Undefined";
|
var sortName = titleNode?.InnerText ?? "Undefined";
|
||||||
|
|
||||||
HtmlNode[] authorsNodes =
|
HtmlNode[] authorsNodes =
|
||||||
document.DocumentNode.SelectNodes("//ul/li[strong/text() = 'Author(s): ']/span")?.ToArray() ?? [];
|
document.DocumentNode.SelectNodes("//ul/li[strong/text() = 'Author(s): ']/span")?.ToArray() ?? [];
|
||||||
List<string> authors = authorsNodes.Select(n => n.InnerText).ToList();
|
var authors = authorsNodes.Select(n => n.InnerText).ToList();
|
||||||
|
|
||||||
HtmlNode[] genreNodes =
|
HtmlNode[] genreNodes =
|
||||||
document.DocumentNode.SelectNodes("//ul/li[strong/text() = 'Tags(s): ']/span")?.ToArray() ?? [];
|
document.DocumentNode.SelectNodes("//ul/li[strong/text() = 'Tags(s): ']/span")?.ToArray() ?? [];
|
||||||
HashSet<string> tags = genreNodes.Select(n => n.InnerText).ToHashSet();
|
HashSet<string> tags = genreNodes.Select(n => n.InnerText).ToHashSet();
|
||||||
|
|
||||||
HtmlNode? statusNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Status: ']/a");
|
var statusNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Status: ']/a");
|
||||||
string status = statusNode?.InnerText ?? "";
|
var status = statusNode?.InnerText ?? "";
|
||||||
Log("unable to parse status");
|
Log("unable to parse status");
|
||||||
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;
|
var releaseStatus = Manga.ReleaseStatusByte.Unreleased;
|
||||||
switch (status.ToLower())
|
switch (status.ToLower())
|
||||||
{
|
{
|
||||||
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
|
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
|
||||||
@ -100,19 +101,19 @@ public class Weebcentral : MangaConnector
|
|||||||
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
|
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlNode? yearNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Released: ']/span");
|
var yearNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Released: ']/span");
|
||||||
int year = Convert.ToInt32(yearNode?.InnerText ?? "0");
|
var year = Convert.ToInt32(yearNode?.InnerText ?? "0");
|
||||||
|
|
||||||
HtmlNode? descriptionNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Description']/p");
|
var descriptionNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Description']/p");
|
||||||
string description = descriptionNode?.InnerText ?? "Undefined";
|
var description = descriptionNode?.InnerText ?? "Undefined";
|
||||||
|
|
||||||
HtmlNode[] altTitleNodes = document.DocumentNode
|
HtmlNode[] altTitleNodes = document.DocumentNode
|
||||||
.SelectNodes("//ul/li[strong/text() = 'Associated Name(s)']/ul/li")?.ToArray() ?? [];
|
.SelectNodes("//ul/li[strong/text() = 'Associated Name(s)']/ul/li")?.ToArray() ?? [];
|
||||||
Dictionary<string, string> altTitles = new(), links = new();
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
for (int i = 0; i < altTitleNodes.Length; i++)
|
for (var i = 0; i < altTitleNodes.Length; i++)
|
||||||
altTitles.Add(i.ToString(), altTitleNodes[i].InnerText);
|
altTitles.Add(i.ToString(), altTitleNodes[i].InnerText);
|
||||||
|
|
||||||
string originalLanguage = "";
|
var originalLanguage = "";
|
||||||
|
|
||||||
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
||||||
coverFileNameInCache, links,
|
coverFileNameInCache, links,
|
||||||
@ -129,8 +130,8 @@ public class Weebcentral : MangaConnector
|
|||||||
public override Chapter[] GetChapters(Manga manga, string language = "en")
|
public override Chapter[] GetChapters(Manga manga, string language = "en")
|
||||||
{
|
{
|
||||||
Log($"Getting chapters {manga}");
|
Log($"Getting chapters {manga}");
|
||||||
string requestUrl = $"{_baseUrl}/series/{manga.publicationId}/full-chapter-list";
|
var requestUrl = $"{_baseUrl}/series/{manga.publicationId}/full-chapter-list";
|
||||||
RequestResult requestResult =
|
var requestResult =
|
||||||
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return [];
|
return [];
|
||||||
@ -138,42 +139,35 @@ public class Weebcentral : MangaConnector
|
|||||||
//Return Chapters ordered by Chapter-Number
|
//Return Chapters ordered by Chapter-Number
|
||||||
if (requestResult.htmlDocument is null)
|
if (requestResult.htmlDocument is null)
|
||||||
return [];
|
return [];
|
||||||
List<Chapter> chapters = ParseChaptersFromHtml(manga, requestResult.htmlDocument);
|
var chapters = ParseChaptersFromHtml(manga, requestResult.htmlDocument);
|
||||||
Log($"Got {chapters.Count} chapters. {manga}");
|
Log($"Got {chapters.Count} chapters. {manga}");
|
||||||
return chapters.OrderByDescending(c => c.name).ThenBy(c => c.volumeNumber).ThenBy(c => c.chapterNumber).ToArray();
|
return chapters.Order().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Chapter> ParseChaptersFromHtml(Manga manga, HtmlDocument document)
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, HtmlDocument document)
|
||||||
{
|
{
|
||||||
HtmlNode? chaptersWrapper = document.DocumentNode.SelectSingleNode("/html/body");
|
var chaptersWrapper = document.DocumentNode.SelectSingleNode("/html/body");
|
||||||
|
|
||||||
Regex chapterRex = new(@"(\d+(?:\.\d+)*)");
|
Regex chapterRex = new(@"(\d+(?:\.\d+)*)");
|
||||||
Regex chapterNameRex = new(@"(\w* )+");
|
|
||||||
Regex idRex = new(@"https:\/\/weebcentral\.com\/chapters\/(\w*)");
|
Regex idRex = new(@"https:\/\/weebcentral\.com\/chapters\/(\w*)");
|
||||||
|
|
||||||
List<Chapter> ret = chaptersWrapper.Descendants("a").Select(elem =>
|
var ret = chaptersWrapper.Descendants("a").Select(elem =>
|
||||||
{
|
{
|
||||||
string url = elem.GetAttributeValue("href", "") ?? "Undefined";
|
var url = elem.GetAttributeValue("href", "") ?? "Undefined";
|
||||||
|
|
||||||
if (!url.StartsWith("https://") && !url.StartsWith("http://"))
|
if (!url.StartsWith("https://") && !url.StartsWith("http://"))
|
||||||
return new Chapter(manga, null, null, "-1", "undefined");
|
return new Chapter(manga, null, null, "-1", "undefined");
|
||||||
|
|
||||||
Match idMatch = idRex.Match(url);
|
var idMatch = idRex.Match(url);
|
||||||
string? id = idMatch.Success ? idMatch.Groups[1].Value : null;
|
var id = idMatch.Success ? idMatch.Groups[1].Value : null;
|
||||||
|
|
||||||
string chapterNode = elem.SelectSingleNode("span[@class='grow flex items-center gap-2']/span")?.InnerText ??
|
var chapterNode = elem.SelectSingleNode("span[@class='grow flex items-center gap-2']/span")?.InnerText ??
|
||||||
"Undefined";
|
"Undefined";
|
||||||
|
|
||||||
MatchCollection chapterNumberMatch = chapterRex.Matches(chapterNode);
|
var chapterNumberMatch = chapterRex.Match(chapterNode);
|
||||||
string chapterNumber = chapterNumberMatch.Count > 0 ? chapterNumberMatch[^1].Groups[1].Value : "-1";
|
var chapterNumber = chapterNumberMatch.Success ? chapterNumberMatch.Groups[1].Value : "-1";
|
||||||
MatchCollection chapterNameMatch = chapterNameRex.Matches(chapterNode);
|
|
||||||
string chapterName = chapterNameMatch.Count > 0
|
|
||||||
? string.Join(" - ",
|
|
||||||
chapterNameMatch.Select(m => m.Groups[1].Value.Trim())
|
|
||||||
.Where(name => name.Length > 0 && !name.Equals("Chapter", StringComparison.OrdinalIgnoreCase)).ToArray()).Trim()
|
|
||||||
: "";
|
|
||||||
|
|
||||||
return new Chapter(manga, chapterName != "" ? chapterName : null, null, chapterNumber, url, id);
|
return new Chapter(manga, null, null, chapterNumber, url, id);
|
||||||
}).Where(elem => elem.chapterNumber != -1 && elem.url != "undefined").ToList();
|
}).Where(elem => elem.chapterNumber != -1 && elem.url != "undefined").ToList();
|
||||||
|
|
||||||
ret.Reverse();
|
ret.Reverse();
|
||||||
@ -188,7 +182,7 @@ public class Weebcentral : MangaConnector
|
|||||||
return HttpStatusCode.RequestTimeout;
|
return HttpStatusCode.RequestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manga chapterParentManga = chapter.parentManga;
|
var chapterParentManga = chapter.parentManga;
|
||||||
if (progressToken?.cancellationRequested ?? false)
|
if (progressToken?.cancellationRequested ?? false)
|
||||||
{
|
{
|
||||||
progressToken.Cancel();
|
progressToken.Cancel();
|
||||||
@ -197,18 +191,18 @@ public class Weebcentral : MangaConnector
|
|||||||
|
|
||||||
Log($"Retrieving chapter-info {chapter} {chapterParentManga}");
|
Log($"Retrieving chapter-info {chapter} {chapterParentManga}");
|
||||||
|
|
||||||
RequestResult requestResult = downloadClient.MakeRequest(chapter.url, RequestType.Default);
|
var requestResult = downloadClient.MakeRequest(chapter.url, RequestType.Default);
|
||||||
if (requestResult.htmlDocument is null)
|
if (requestResult.htmlDocument is null)
|
||||||
{
|
{
|
||||||
progressToken?.Cancel();
|
progressToken?.Cancel();
|
||||||
return HttpStatusCode.RequestTimeout;
|
return HttpStatusCode.RequestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlDocument? document = requestResult.htmlDocument;
|
var document = requestResult.htmlDocument;
|
||||||
|
|
||||||
HtmlNode[] imageNodes =
|
var imageNodes =
|
||||||
document.DocumentNode.SelectNodes($"//section[@hx-get='{chapter.url}/images']/img")?.ToArray() ?? [];
|
document.DocumentNode.SelectNodes($"//section[@hx-get='{chapter.url}/images']/img")?.ToArray() ?? [];
|
||||||
string[] urls = imageNodes.Select(imgNode => imgNode.GetAttributeValue("src", "")).ToArray();
|
var urls = imageNodes.Select(imgNode => imgNode.GetAttributeValue("src", "")).ToArray();
|
||||||
|
|
||||||
return DownloadChapterImages(urls, chapter, RequestType.MangaImage, progressToken: progressToken);
|
return DownloadChapterImages(urls, chapter, RequestType.MangaImage, progressToken: progressToken);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user