From 226cc6990d77f5a2a980426cae982adcb4f261c2 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 10 Jan 2016 21:16:23 +0100 Subject: [PATCH] Allow whitespaces in downloads path and add chapter id to avoid path conflicts. Throw if page list is empty WARNING: Downloaded chapters from a previous version won't be visible in the app anymore. You will have to manually delete the folder and download them again. --- .../eu/kanade/mangafeed/data/database/DatabaseHelper.java | 1 - .../eu/kanade/mangafeed/data/download/DownloadManager.java | 6 +++--- .../java/eu/kanade/mangafeed/data/source/base/Source.java | 4 +++- .../mangafeed/data/source/online/english/Kissmanga.java | 4 +++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java index 50aab278f..94f36ec70 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java @@ -253,7 +253,6 @@ public class DatabaseHelper { .filter(c -> !dbChapters.contains(c)) .doOnNext(c -> { c.manga_id = manga.id; - c.date_fetch = new Date().getTime(); ChapterRecognition.parseChapterNumber(c, manga); }) .toList(); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java b/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java index 95db35525..40a191715 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/download/DownloadManager.java @@ -164,7 +164,7 @@ public class DownloadManager { // Check that all the images are downloaded private boolean isChapterDownloaded(File directory, List pages) { - return pages != null && pages.size() + 1 == directory.listFiles().length; + return pages != null && !pages.isEmpty() && pages.size() + 1 == directory.listFiles().length; } // Download the entire chapter @@ -359,9 +359,9 @@ public class DownloadManager { public File getAbsoluteChapterDirectory(Source source, Manga manga, Chapter chapter) { String chapterRelativePath = source.getName() + File.separator + - manga.title.replaceAll("[^a-zA-Z0-9.-]", "_") + + manga.title.replaceAll("[^\\sa-zA-Z0-9.-]", "_") + File.separator + - chapter.name.replaceAll("[^a-zA-Z0-9.-]", "_"); + chapter.name.replaceAll("[^\\sa-zA-Z0-9.-]", "_") + " (" + chapter.id + ")"; return new File(preferences.getDownloadsDirectory(), chapterRelativePath); } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java index fd669d3c0..08475b646 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java @@ -105,7 +105,9 @@ public abstract class Source extends BaseSource { .getStringResponse(getBaseUrl() + overrideChapterUrl(chapterUrl), requestHeaders, null) .flatMap(unparsedHtml -> { List pages = convertToPages(parseHtmlToPageUrls(unparsedHtml)); - return Observable.just(parseFirstPage(pages, unparsedHtml)); + return !pages.isEmpty() ? + Observable.just(parseFirstPage(pages, unparsedHtml)) : + Observable.error(new Exception("Page list is empty")); }); } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java index 73851cba7..2cf4a982b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Kissmanga.java @@ -203,7 +203,9 @@ public class Kissmanga extends Source { .flatMap(networkService::mapResponseToString) .flatMap(unparsedHtml -> { List pages = convertToPages(parseHtmlToPageUrls(unparsedHtml)); - return Observable.just(parseFirstPage(pages, unparsedHtml)); + return !pages.isEmpty() ? + Observable.just(parseFirstPage(pages, unparsedHtml)) : + Observable.error(new Exception("Page list is empty")); }); }