Compare commits

..

3 Commits

Author SHA1 Message Date
38df54baff Exception handling on request failed HttpDownloadClient 2023-10-25 18:22:00 +02:00
98d187d133 Possible fix #72
Volume Numbers broke Regex
Now can also parse volume numbers!
2023-10-25 18:16:26 +02:00
5352cca058 Possible fix for #72
RegexMatching was off for last element sometimes on bato
2023-10-23 17:01:26 +02:00
2 changed files with 16 additions and 7 deletions

View File

@ -139,15 +139,16 @@ public class Bato : MangaConnector
HtmlNode chapterList = HtmlNode chapterList =
result.htmlDocument.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(@"\/title\/.+\/[0-9]+-ch_([0-9\.]+)"); Regex numberRex = new(@"\/title\/.+\/[0-9]+(-vol_([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 chapterUrl = infoNode.GetAttributeValue("href", ""); string chapterUrl = infoNode.GetAttributeValue("href", "");
string? volumeNumber = null; Match match = numberRex.Match(chapterUrl);
string chapterNumber = chapterNumberRex.Match(chapterUrl).Groups[1].Value; string? volumeNumber = match.Groups[2].Success ? match.Groups[2].Value : null;
string chapterNumber = match.Groups[3].Value;
string chapterName = chapterNumber; string chapterName = chapterNumber;
string url = $"https://bato.to{chapterUrl}?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));
@ -205,7 +206,8 @@ public class Bato : MangaConnector
string weirdString = images.OuterHtml; string weirdString = images.OuterHtml;
string weirdString2 = Regex.Match(weirdString, @"props=\""(.*)}\""").Groups[1].Value; string weirdString2 = Regex.Match(weirdString, @"props=\""(.*)}\""").Groups[1].Value;
string[] urls = Regex.Matches(weirdString2, @"https:\/\/[A-z\-0-9\.\?\&\;\=\/]*").Select(m => m.Value.Replace("\\"]", "").Replace("amp;", "")).ToArray(); string[] urls = Regex.Matches(weirdString2, @"(https:\/\/[A-z\-0-9\.\?\&\;\=\/]+)\\")
.Select(match => match.Groups[1].Value.Replace("&", "&")).ToArray();
return urls; return urls;
} }

View File

@ -37,10 +37,17 @@ internal class HttpDownloadClient : DownloadClient
{ {
response = Client.Send(requestMessage); response = Client.Send(requestMessage);
} }
catch (TaskCanceledException e) catch (Exception e)
{ {
Log($"Request timed out.\n\r{e}"); switch (e)
return new RequestResult(HttpStatusCode.RequestTimeout, null, Stream.Null); {
case TaskCanceledException:
Log($"Request timed out.\n\r{e}");
return new RequestResult(HttpStatusCode.RequestTimeout, null, Stream.Null);
case HttpRequestException:
Log($"Request failed\n\r{e}");
return new RequestResult(HttpStatusCode.BadRequest, null, Stream.Null);
}
} }
} }