2
0

Add Manga to cached on parsing

This commit is contained in:
glax 2023-09-02 22:12:49 +02:00
parent 99ad702163
commit 32fd75bdae
5 changed files with 26 additions and 13 deletions

View File

@ -65,8 +65,6 @@ public class MangaDex : MangaConnector
retManga.Add(manga); //Add Publication (Manga) to result retManga.Add(manga); //Add Publication (Manga) to result
} }
} }
cachedPublications.AddRange(retManga);
Log($"Retrieved {retManga.Count} publications. Term=\"{publicationTitle}\""); Log($"Retrieved {retManga.Count} publications. Term=\"{publicationTitle}\"");
return retManga.ToArray(); return retManga.ToArray();
} }
@ -170,6 +168,7 @@ public class MangaDex : MangaConnector
status, status,
publicationId publicationId
); );
cachedPublications.Add(pub);
return pub; return pub;
} }

View File

@ -39,7 +39,6 @@ public class MangaKatana : MangaConnector
} }
Manga[] publications = ParsePublicationsFromHtml(requestResult.result); Manga[] publications = ParsePublicationsFromHtml(requestResult.result);
cachedPublications.AddRange(publications);
Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\"");
return publications; return publications;
} }
@ -140,8 +139,10 @@ public class MangaKatana : MangaConnector
year = Convert.ToInt32(yearString); year = Convert.ToInt32(yearString);
} }
return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId); year, originalLanguage, status, publicationId);
cachedPublications.Add(manga);
return manga;
} }
public override Chapter[] GetChapters(Manga manga, string language="en") public override Chapter[] GetChapters(Manga manga, string language="en")

View File

@ -30,7 +30,6 @@ public class Manganato : MangaConnector
return Array.Empty<Manga>(); return Array.Empty<Manga>();
Manga[] publications = ParsePublicationsFromHtml(requestResult.result); Manga[] publications = ParsePublicationsFromHtml(requestResult.result);
cachedPublications.AddRange(publications);
Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\"");
return publications; return publications;
} }
@ -129,8 +128,10 @@ public class Manganato : MangaConnector
.First(s => s.HasClass("chapter-time")).InnerText; .First(s => s.HasClass("chapter-time")).InnerText;
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000; int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId); year, originalLanguage, status, publicationId);
cachedPublications.Add(manga);
return manga;
} }
public override Chapter[] GetChapters(Manga manga, string language="en") public override Chapter[] GetChapters(Manga manga, string language="en")

View File

@ -79,7 +79,6 @@ public class Mangasee : MangaConnector
return Array.Empty<Manga>(); return Array.Empty<Manga>();
Manga[] publications = ParsePublicationsFromHtml(requestResult.result, publicationTitle); Manga[] publications = ParsePublicationsFromHtml(requestResult.result, publicationTitle);
cachedPublications.AddRange(publications);
Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\""); Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\"");
return publications; return publications;
} }
@ -148,8 +147,8 @@ public class Mangasee : MangaConnector
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1); string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//h1"); HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//h1");
string title = titleNode.InnerText; string sortName = titleNode.InnerText;
string publicationId = title; string publicationId = sortName;
HtmlNode[] authorsNodes = document.DocumentNode.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Author(s):']/..").Descendants("a").ToArray(); HtmlNode[] authorsNodes = document.DocumentNode.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Author(s):']/..").Descendants("a").ToArray();
List<string> authors = new(); List<string> authors = new();
@ -171,8 +170,10 @@ public class Mangasee : MangaConnector
HtmlNode descriptionNode = document.DocumentNode.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..").Descendants("div").First(); HtmlNode descriptionNode = document.DocumentNode.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..").Descendants("div").First();
string description = descriptionNode.InnerText; string description = descriptionNode.InnerText;
return new Manga(title, authors, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId); year, originalLanguage, status, publicationId);
cachedPublications.Add(manga);
return manga;
} }
// ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization // ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization

View File

@ -134,14 +134,25 @@ public class Server : GlobalBase
} }
break; break;
case "Manga/FromConnector": case "Manga/FromConnector":
requestVariables.TryGetValue("title", out string? title);
requestVariables.TryGetValue("url", out string? url);
if (!requestVariables.TryGetValue("connector", out connectorName) || if (!requestVariables.TryGetValue("connector", out connectorName) ||
!requestVariables.TryGetValue("title", out string? title) || !_parent.TryGetConnector(connectorName, out connector) ||
!_parent.TryGetConnector(connectorName, out connector)) (title is null && url is null))
{ {
SendResponse(HttpStatusCode.BadRequest, response); SendResponse(HttpStatusCode.BadRequest, response);
break; break;
} }
SendResponse(HttpStatusCode.OK, response, connector!.GetManga(title));
if (url is not null)
{
HashSet<Manga> ret = new();
manga = connector!.GetMangaFromUrl(url);
if (manga is not null)
ret.Add((Manga)manga);
SendResponse(HttpStatusCode.OK, response, ret);
}else
SendResponse(HttpStatusCode.OK, response, connector!.GetManga(title!));
break; break;
case "Manga/Chapters": case "Manga/Chapters":
if(!requestVariables.TryGetValue("connector", out connectorName) || if(!requestVariables.TryGetValue("connector", out connectorName) ||