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.
This commit is contained in:
inorichi 2016-01-10 21:16:23 +01:00
parent e702be1a8d
commit 226cc6990d
4 changed files with 9 additions and 6 deletions

View File

@ -253,7 +253,6 @@ public class DatabaseHelper {
.filter(c -> !dbChapters.contains(c)) .filter(c -> !dbChapters.contains(c))
.doOnNext(c -> { .doOnNext(c -> {
c.manga_id = manga.id; c.manga_id = manga.id;
c.date_fetch = new Date().getTime();
ChapterRecognition.parseChapterNumber(c, manga); ChapterRecognition.parseChapterNumber(c, manga);
}) })
.toList(); .toList();

View File

@ -164,7 +164,7 @@ public class DownloadManager {
// Check that all the images are downloaded // Check that all the images are downloaded
private boolean isChapterDownloaded(File directory, List<Page> pages) { private boolean isChapterDownloaded(File directory, List<Page> 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 // Download the entire chapter
@ -359,9 +359,9 @@ public class DownloadManager {
public File getAbsoluteChapterDirectory(Source source, Manga manga, Chapter chapter) { public File getAbsoluteChapterDirectory(Source source, Manga manga, Chapter chapter) {
String chapterRelativePath = source.getName() + String chapterRelativePath = source.getName() +
File.separator + File.separator +
manga.title.replaceAll("[^a-zA-Z0-9.-]", "_") + manga.title.replaceAll("[^\\sa-zA-Z0-9.-]", "_") +
File.separator + File.separator +
chapter.name.replaceAll("[^a-zA-Z0-9.-]", "_"); chapter.name.replaceAll("[^\\sa-zA-Z0-9.-]", "_") + " (" + chapter.id + ")";
return new File(preferences.getDownloadsDirectory(), chapterRelativePath); return new File(preferences.getDownloadsDirectory(), chapterRelativePath);
} }

View File

@ -105,7 +105,9 @@ public abstract class Source extends BaseSource {
.getStringResponse(getBaseUrl() + overrideChapterUrl(chapterUrl), requestHeaders, null) .getStringResponse(getBaseUrl() + overrideChapterUrl(chapterUrl), requestHeaders, null)
.flatMap(unparsedHtml -> { .flatMap(unparsedHtml -> {
List<Page> pages = convertToPages(parseHtmlToPageUrls(unparsedHtml)); List<Page> 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"));
}); });
} }

View File

@ -203,7 +203,9 @@ public class Kissmanga extends Source {
.flatMap(networkService::mapResponseToString) .flatMap(networkService::mapResponseToString)
.flatMap(unparsedHtml -> { .flatMap(unparsedHtml -> {
List<Page> pages = convertToPages(parseHtmlToPageUrls(unparsedHtml)); List<Page> 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"));
}); });
} }