From ae715b7812cb5a202b6d3c6fc9a663535c5a0347 Mon Sep 17 00:00:00 2001 From: Nguyen Dan Phuong Date: Mon, 1 Aug 2016 10:49:11 +0700 Subject: [PATCH] Fix #5 mangahere.co: chapter name is empty, image path is not well formated. --- MangaRipper.Core/MangaHereService.cs | 4 ++-- MangaRipper.Core/Parser.cs | 6 +++--- MangaRipper.Test/UnitTest.cs | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/MangaRipper.Core/MangaHereService.cs b/MangaRipper.Core/MangaHereService.cs index 65018ba..db9a2dc 100644 --- a/MangaRipper.Core/MangaHereService.cs +++ b/MangaRipper.Core/MangaHereService.cs @@ -19,7 +19,7 @@ public async Task> FindChapters(string manga, IProgress prog progress.Report(0); // find all chapters in a manga string input = await downloader.DownloadStringAsync(manga); - var chaps = parser.ParseGroup("http://[^\"]+)\"[^<]+>(?[^<]+)", input, "Name", "Value"); + var chaps = parser.ParseGroup("http://[^\"]+)\"[^<]+>(?[^<]+)", input, "Name", "Value"); progress.Report(100); return chaps; } @@ -47,7 +47,7 @@ public async Task> FindImanges(Chapter chapter, IProgress pro int i = Convert.ToInt32(f * 100); progress.Report(i); }), cancellationToken); - var images = parser.Parse("[^\"]+)\"[ ]+onerror", pageData, "Value"); + var images = parser.Parse("[^?]+)?[^\"]+\"[ ]+onerror", pageData, "Value"); return images; } diff --git a/MangaRipper.Core/Parser.cs b/MangaRipper.Core/Parser.cs index 94d72cd..5497988 100644 --- a/MangaRipper.Core/Parser.cs +++ b/MangaRipper.Core/Parser.cs @@ -21,8 +21,8 @@ public IList ParseGroup(string regExp, string input, string nameGroup, foreach (Match match in matches) { - var value = match.Groups[valueGroup].Value; - string name = match.Groups[nameGroup].Value; + var value = match.Groups[valueGroup].Value.Trim(); + string name = match.Groups[nameGroup].Value.Trim(); var chapter = new Chapter(name, value); list.Add(chapter); } @@ -39,7 +39,7 @@ public IList Parse(string regExp, string input, string groupName) foreach (Match match in matches) { - var value = match.Groups[groupName].Value; + var value = match.Groups[groupName].Value.Trim(); list.Add(value); } diff --git a/MangaRipper.Test/UnitTest.cs b/MangaRipper.Test/UnitTest.cs index 6bd0b6e..80c4981 100644 --- a/MangaRipper.Test/UnitTest.cs +++ b/MangaRipper.Test/UnitTest.cs @@ -63,7 +63,8 @@ public async Task MangaHere_Test() var service = Framework.GetService(url); var chapters = await service.FindChapters(url, new Progress(), source.Token); Assert.IsTrue(chapters.Count > 0, "Cannot find chapters."); - var chapter = chapters[0]; + var chapter = chapters.First(); + Assert.IsTrue(chapter.Name.Length > 0, "Chapter's name is empty string."); var images = await service.FindImanges(chapter, new Progress(), source.Token); Assert.IsTrue(images.Count > 0, "Cannot find images."); }