From 6844d0a242099856865f84ee138cb6064bb89243 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 15 Oct 2023 12:19:44 +0200 Subject: [PATCH] #67 prevent crash if xml document does not exist --- Tranga/MangaConnectors/Mangasee.cs | 34 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index 508615c..404bac7 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -121,22 +121,30 @@ public class Mangasee : MangaConnector public override Chapter[] GetChapters(Manga manga, string language="en") { Log($"Getting chapters {manga}"); - XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{manga.publicationId}.xml"); - XElement[] chapterItems = doc.Descendants("item").ToArray(); - List chapters = new(); - foreach (XElement chapter in chapterItems) + try { - string volumeNumber = "1"; - string url = chapter.Descendants("link").First().Value; - string chapterNumber = Regex.Match(url, @"-chapter-([0-9\.]+)").Groups[1].ToString(); + XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{manga.publicationId}.xml"); + XElement[] chapterItems = doc.Descendants("item").ToArray(); + List chapters = new(); + foreach (XElement chapter in chapterItems) + { + string volumeNumber = "1"; + string url = chapter.Descendants("link").First().Value; + string chapterNumber = Regex.Match(url, @"-chapter-([0-9\.]+)").Groups[1].ToString(); - url = url.Replace(Regex.Match(url,"(-page-[0-9])").Value,""); - chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, url)); + url = url.Replace(Regex.Match(url,"(-page-[0-9])").Value,""); + chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, url)); + } + + //Return Chapters ordered by Chapter-Number + Log($"Got {chapters.Count} chapters. {manga}"); + return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, numberFormatDecimalPoint)).ToArray(); + } + catch (HttpRequestException e) + { + Log($"Failed to load XML\n\r{e}"); + return Array.Empty(); } - - //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)