From a100cb87473f489d424c150a4f3cc6e92651ccb4 Mon Sep 17 00:00:00 2001 From: Nguyen Dan Phuong Date: Wed, 7 Sep 2016 10:58:34 +0700 Subject: [PATCH] Fix #8 403 when download from MangaFox --- MangaRipper.Core/Downloader.cs | 1 - MangaRipper.Core/IMangaService.cs | 3 +++ MangaRipper.Core/Worker.cs | 2 +- MangaRipper.Test/UnitTest.cs | 30 +++++++++++++++++++++++------- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/MangaRipper.Core/Downloader.cs b/MangaRipper.Core/Downloader.cs index 4e634fa..12c0a8f 100644 --- a/MangaRipper.Core/Downloader.cs +++ b/MangaRipper.Core/Downloader.cs @@ -21,7 +21,6 @@ private HttpWebRequest CreateRequest(string url) HttpWebRequest request = WebRequest.CreateHttp(uri); request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; request.Credentials = CredentialCache.DefaultCredentials; - request.Referer = uri.AbsoluteUri; return request; } diff --git a/MangaRipper.Core/IMangaService.cs b/MangaRipper.Core/IMangaService.cs index 7b3054d..acbb052 100644 --- a/MangaRipper.Core/IMangaService.cs +++ b/MangaRipper.Core/IMangaService.cs @@ -7,6 +7,9 @@ namespace MangaRipper.Core { + /// + /// We have many manga services, each service support downloading from one site. + /// public interface IMangaService { SiteInformation GetInformation(); diff --git a/MangaRipper.Core/Worker.cs b/MangaRipper.Core/Worker.cs index 03d3ff3..ac7adce 100644 --- a/MangaRipper.Core/Worker.cs +++ b/MangaRipper.Core/Worker.cs @@ -87,7 +87,7 @@ private async Task DownloadChapterInternal(Chapter chapter, string mangaLocalPat // create folder to keep images var downloader = new Downloader(); var folderName = chapter.Name.RemoveFileNameInvalidChar(); - var destinationPath = Path.Combine(mangaLocalPath, folderName); ; + var destinationPath = Path.Combine(mangaLocalPath, folderName); Directory.CreateDirectory(destinationPath); // download images int countImage = 0; diff --git a/MangaRipper.Test/UnitTest.cs b/MangaRipper.Test/UnitTest.cs index c59ab58..0087d5a 100644 --- a/MangaRipper.Test/UnitTest.cs +++ b/MangaRipper.Test/UnitTest.cs @@ -42,6 +42,10 @@ public async Task MangaReader_Test() Assert.AreEqual("http://i10.mangareader.net/naruto/1/naruto-1564773.jpg", images[0]); Assert.AreEqual("http://i4.mangareader.net/naruto/1/naruto-1564774.jpg", images[1]); Assert.AreEqual("http://i1.mangareader.net/naruto/1/naruto-1564825.jpg", images[52]); + + var downloader = new Downloader(); + string imageString = await downloader.DownloadStringAsync(images[0]); + Assert.IsNotNull(imageString, "Cannot download image!"); } [TestMethod] @@ -61,6 +65,10 @@ public async Task MangaFox_Test() Assert.AreEqual("http://h.mfcdn.net/store/manga/19803/001.0/compressed/q001.jpg", images[0]); Assert.AreEqual("http://h.mfcdn.net/store/manga/19803/001.0/compressed/q002.jpg", images[1]); Assert.AreEqual("http://h.mfcdn.net/store/manga/19803/001.0/compressed/q015.jpg", images[14]); + + var downloader = new Downloader(); + string imageString = await downloader.DownloadStringAsync(images[0]); + Assert.IsNotNull(imageString, "Cannot download image!"); } [TestMethod] @@ -78,23 +86,31 @@ public async Task MangaHere_Test() Assert.AreEqual("http://h.mhcdn.net/store/manga/9275/001.0/compressed/m001.01.jpg", images[0]); Assert.AreEqual("http://h.mhcdn.net/store/manga/9275/001.0/compressed/m001.02.jpg", images[1]); Assert.AreEqual("http://h.mhcdn.net/store/manga/9275/001.0/compressed/m001.55.jpg", images[54]); + + var downloader = new Downloader(); + string imageString = await downloader.DownloadStringAsync(images[0]); + Assert.IsNotNull(imageString, "Cannot download image!"); } [TestMethod] public async Task MangaShare_Test() { - string url = "http://read.mangashare.com/Beelzebub"; + string url = "http://read.mangashare.com/Gantz"; 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.Last(); - Assert.AreEqual("Beelzebub 1", chapter.Name); - Assert.AreEqual("http://read.mangashare.com/Beelzebub/chapter-001/page001.html", chapter.Link); + Assert.AreEqual("Gantz 1", chapter.Name); + Assert.AreEqual("http://read.mangashare.com/Gantz/chapter-001/page001.html", chapter.Link); var images = await service.FindImanges(chapter, new Progress(), source.Token); - Assert.AreEqual(58, images.Count); - Assert.AreEqual("http://dl01.mangashare.com/manga/Beelzebub/001/001.jpg", images[0]); - Assert.AreEqual("http://dl01.mangashare.com/manga/Beelzebub/001/002.jpg", images[1]); - Assert.AreEqual("http://dl01.mangashare.com/manga/Beelzebub/001/058.jpg", images[57]); + Assert.AreEqual(43, images.Count); + Assert.AreEqual("http://dl01.mangashare.com/manga/Gantz/001/001.jpg", images[0]); + Assert.AreEqual("http://dl01.mangashare.com/manga/Gantz/001/002.jpg", images[1]); + Assert.AreEqual("http://dl01.mangashare.com/manga/Gantz/001/043.jpg", images[42]); + + var downloader = new Downloader(); + string imageString = await downloader.DownloadStringAsync(images[0]); + Assert.IsNotNull(imageString, "Cannot download image!"); } } }