Compare commits
10 Commits
f78bec43d6
...
3381909afd
Author | SHA1 | Date | |
---|---|---|---|
3381909afd | |||
7219641859 | |||
f63851d95d | |||
e72301d062 | |||
2302e1009b | |||
40fea6cc7f | |||
5458c43f21 | |||
88876fb8f4 | |||
c71aec8882 | |||
ddfba0d864 |
@ -58,6 +58,7 @@ Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
|||||||
- [MangaKatana.com](https://mangakatana.com) (en)
|
- [MangaKatana.com](https://mangakatana.com) (en)
|
||||||
- [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)
|
||||||
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
|
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
|
||||||
|
|
||||||
and trigger an scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).
|
and trigger an scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).
|
||||||
|
@ -127,26 +127,29 @@ public class Bato : MangaConnector
|
|||||||
|
|
||||||
private List<Chapter> ParseChaptersFromHtml(Manga manga, string mangaUrl)
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, string mangaUrl)
|
||||||
{
|
{
|
||||||
// Using HtmlWeb will include the chapters since they are loaded with js
|
DownloadClient.RequestResult result = downloadClient.MakeRequest(mangaUrl, 1);
|
||||||
HtmlWeb web = new();
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
HtmlDocument document = web.Load(mangaUrl);
|
{
|
||||||
|
Log("Failed to load site");
|
||||||
|
return new List<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
List<Chapter> ret = new();
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
HtmlNode chapterList =
|
HtmlNode chapterList =
|
||||||
document.DocumentNode.SelectSingleNode("/html/body/div/main/div[3]/astro-island/div/div[2]/div/div/astro-slot");
|
result.htmlDocument.DocumentNode.SelectSingleNode("/html/body/div/main/div[3]/astro-island/div/div[2]/div/div/astro-slot");
|
||||||
|
|
||||||
Regex chapterNumberRex = new(@"Chapter ([0-9\.]+)");
|
Regex chapterNumberRex = new(@"\/title\/.+\/[0-9]+-ch_([0-9\.]+)");
|
||||||
|
|
||||||
foreach (HtmlNode chapterInfo in chapterList.SelectNodes("div"))
|
foreach (HtmlNode chapterInfo in chapterList.SelectNodes("div"))
|
||||||
{
|
{
|
||||||
HtmlNode infoNode = chapterInfo.FirstChild.FirstChild;
|
HtmlNode infoNode = chapterInfo.FirstChild.FirstChild;
|
||||||
string fullString = infoNode.InnerText;
|
string chapterUrl = infoNode.GetAttributeValue("href", "");
|
||||||
|
|
||||||
string? volumeNumber = null;
|
string? volumeNumber = null;
|
||||||
string chapterNumber = chapterNumberRex.Match(fullString).Groups[1].Value;
|
string chapterNumber = chapterNumberRex.Match(chapterUrl).Groups[1].Value;
|
||||||
string chapterName = chapterNumber;
|
string chapterName = chapterNumber;
|
||||||
string url = $"https://bato.to{infoNode.GetAttributeValue("href", "")}?load=2";
|
string url = $"https://bato.to{chapterUrl}?load=2";
|
||||||
ret.Add(new Chapter(manga, chapterName, volumeNumber, chapterNumber, url));
|
ret.Add(new Chapter(manga, chapterName, volumeNumber, chapterNumber, url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
{
|
{
|
||||||
IPage page = this.browser.NewPageAsync().Result;
|
IPage page = this.browser.NewPageAsync().Result;
|
||||||
page.DefaultTimeout = 10000;
|
page.DefaultTimeout = 10000;
|
||||||
IResponse response = page.GoToAsync(url, WaitUntilNavigation.DOMContentLoaded).Result;
|
IResponse response = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
|
||||||
Log("Page loaded.");
|
Log("Page loaded.");
|
||||||
|
|
||||||
Stream stream = Stream.Null;
|
Stream stream = Stream.Null;
|
||||||
|
@ -36,6 +36,8 @@ public class MangaConnectorJsonConverter : JsonConverter
|
|||||||
return this._connectors.First(c => c is Mangaworld);
|
return this._connectors.First(c => c is Mangaworld);
|
||||||
case "Bato":
|
case "Bato":
|
||||||
return this._connectors.First(c => c is Bato);
|
return this._connectors.First(c => c is Bato);
|
||||||
|
case "Manga4Life":
|
||||||
|
return this._connectors.First(c => c is MangaLife);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
@ -167,15 +167,20 @@ public class MangaKatana : MangaConnector
|
|||||||
|
|
||||||
HtmlNode chapterList = document.DocumentNode.SelectSingleNode("//div[contains(@class, 'chapters')]/table/tbody");
|
HtmlNode chapterList = document.DocumentNode.SelectSingleNode("//div[contains(@class, 'chapters')]/table/tbody");
|
||||||
|
|
||||||
|
Regex volumeRex = new(@"Volume ([0-9]+)");
|
||||||
|
Regex chapterNumRex = new(@"https:\/\/mangakatana\.com\/manga\/.+\/c([0-9\.]+)");
|
||||||
|
Regex chapterNameRex = new(@"Chapter [0-9\.]+: (.*)");
|
||||||
|
|
||||||
|
|
||||||
foreach (HtmlNode chapterInfo in chapterList.Descendants("tr"))
|
foreach (HtmlNode chapterInfo in chapterList.Descendants("tr"))
|
||||||
{
|
{
|
||||||
string fullString = chapterInfo.Descendants("a").First().InnerText;
|
string fullString = chapterInfo.Descendants("a").First().InnerText;
|
||||||
|
|
||||||
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
|
|
||||||
string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Split(" ")[0].Replace('-', '.');
|
|
||||||
string chapterName = string.Concat(fullString.Split(':')[1..]);
|
|
||||||
string url = chapterInfo.Descendants("a").First()
|
string url = chapterInfo.Descendants("a").First()
|
||||||
.GetAttributeValue("href", "");
|
.GetAttributeValue("href", "");
|
||||||
|
|
||||||
|
string? volumeNumber = volumeRex.IsMatch(fullString) ? volumeRex.Match(fullString).Groups[1].Value : null;
|
||||||
|
string chapterNumber = chapterNumRex.Match(url).Groups[1].Value;
|
||||||
|
string chapterName = chapterNameRex.Match(fullString).Groups[1].Value;
|
||||||
ret.Add(new Chapter(manga, chapterName, volumeNumber, chapterNumber, url));
|
ret.Add(new Chapter(manga, chapterName, volumeNumber, chapterNumber, url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
184
Tranga/MangaConnectors/MangaLife.cs
Normal file
184
Tranga/MangaConnectors/MangaLife.cs
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Tranga.Jobs;
|
||||||
|
|
||||||
|
namespace Tranga.MangaConnectors;
|
||||||
|
|
||||||
|
public class MangaLife : MangaConnector
|
||||||
|
{
|
||||||
|
public MangaLife(GlobalBase clone) : base(clone, "Manga4Life")
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient(clone, new Dictionary<byte, int>()
|
||||||
|
{
|
||||||
|
{ 1, 60 }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Manga[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||||
|
string sanitizedTitle = WebUtility.UrlEncode(publicationTitle);
|
||||||
|
string requestUrl = $"https://manga4life.com/search/?name={sanitizedTitle}";
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, 1);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Manga? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Regex publicationIdRex = new(@"https:\/\/manga4life.com\/manga\/(.*)(\/.*)*");
|
||||||
|
string publicationId = publicationIdRex.Match(url).Groups[1].Value;
|
||||||
|
|
||||||
|
DownloadClient.RequestResult requestResult = this.downloadClient.MakeRequest(url, 1);
|
||||||
|
if(requestResult.htmlDocument is not null)
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Manga[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
HtmlNode resultsNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']/div[last()]/div[1]/div");
|
||||||
|
if (resultsNode.Descendants("div").Count() == 1 && resultsNode.Descendants("div").First().HasClass("NoResults"))
|
||||||
|
{
|
||||||
|
Log("No results.");
|
||||||
|
return Array.Empty<Manga>();
|
||||||
|
}
|
||||||
|
Log($"{resultsNode.SelectNodes("div").Count} items.");
|
||||||
|
|
||||||
|
HashSet<Manga> ret = new();
|
||||||
|
|
||||||
|
foreach (HtmlNode resultNode in resultsNode.SelectNodes("div"))
|
||||||
|
{
|
||||||
|
string url = resultNode.Descendants().First(d => d.HasClass("SeriesName")).GetAttributeValue("href", "");
|
||||||
|
Manga? manga = GetMangaFromUrl($"https://manga4life.com{url}");
|
||||||
|
if (manga is not null)
|
||||||
|
ret.Add((Manga)manga);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId)
|
||||||
|
{
|
||||||
|
string originalLanguage = "", status = "";
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
|
||||||
|
HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img");
|
||||||
|
string posterUrl = posterNode.GetAttributeValue("src", "");
|
||||||
|
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||||
|
|
||||||
|
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//h1");
|
||||||
|
string sortName = titleNode.InnerText;
|
||||||
|
|
||||||
|
HtmlNode[] authorsNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Author(s):']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
List<string> authors = new();
|
||||||
|
foreach (HtmlNode authorNode in authorsNodes)
|
||||||
|
authors.Add(authorNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode[] genreNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Genre(s):']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode genreNode in genreNodes)
|
||||||
|
tags.Add(genreNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode yearNode = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Released:']/..").Descendants("a")
|
||||||
|
.First();
|
||||||
|
int year = Convert.ToInt32(yearNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode[] statusNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Status:']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode statusNode in statusNodes)
|
||||||
|
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
status = statusNode.InnerText.Split(' ')[0];
|
||||||
|
|
||||||
|
HtmlNode descriptionNode = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..")
|
||||||
|
.Descendants("div").First();
|
||||||
|
string description = descriptionNode.InnerText;
|
||||||
|
|
||||||
|
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
||||||
|
coverFileNameInCache, links,
|
||||||
|
year, originalLanguage, status, publicationId);
|
||||||
|
cachedPublications.Add(manga);
|
||||||
|
return manga;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
Log($"Getting chapters {manga}");
|
||||||
|
DownloadClient.RequestResult result = downloadClient.MakeRequest($"https://manga4life.com/manga/{manga.publicationId}", 1);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNodeCollection chapterNodes = result.htmlDocument.DocumentNode.SelectNodes(
|
||||||
|
"//a[contains(concat(' ',normalize-space(@class),' '),' ChapterLink ')]");
|
||||||
|
string[] urls = chapterNodes.Select(node => node.GetAttributeValue("href", "")).ToArray();
|
||||||
|
|
||||||
|
List<Chapter> chapters = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
string volumeNumber = "1";
|
||||||
|
string chapterNumber = Regex.Match(url, @"-chapter-([0-9\.]+)").Groups[1].ToString();
|
||||||
|
string fullUrl = $"https://manga4life.com{url}";
|
||||||
|
fullUrl = fullUrl.Replace(Regex.Match(url,"(-page-[0-9])").Value,"");
|
||||||
|
chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl));
|
||||||
|
}
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
Log($"Got {chapters.Count} chapters. {manga}");
|
||||||
|
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, numberFormatDecimalPoint)).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}");
|
||||||
|
|
||||||
|
DownloadClient.RequestResult requestResult = this.downloadClient.MakeRequest(chapter.url, 1);
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
progressToken?.Cancel();
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlDocument document = requestResult.htmlDocument;
|
||||||
|
|
||||||
|
HtmlNode gallery = document.DocumentNode.Descendants("div").First(div => div.HasClass("ImageGallery"));
|
||||||
|
HtmlNode[] images = gallery.Descendants("img").Where(img => img.HasClass("img-fluid")).ToArray();
|
||||||
|
List<string> urls = new();
|
||||||
|
foreach(HtmlNode galleryImage in images)
|
||||||
|
urls.Add(galleryImage.GetAttributeValue("src", ""));
|
||||||
|
|
||||||
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
|
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, progressToken:progressToken);
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,8 @@ public partial class Tranga : GlobalBase
|
|||||||
new MangaDex(this),
|
new MangaDex(this),
|
||||||
new MangaKatana(this),
|
new MangaKatana(this),
|
||||||
new Mangaworld(this),
|
new Mangaworld(this),
|
||||||
new Bato(this)
|
new Bato(this),
|
||||||
|
new MangaLife(this)
|
||||||
};
|
};
|
||||||
jobBoss = new(this, this._connectors);
|
jobBoss = new(this, this._connectors);
|
||||||
StartJobBoss();
|
StartJobBoss();
|
||||||
|
Loading…
Reference in New Issue
Block a user