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))
.doOnNext(c -> {
c.manga_id = manga.id;
c.date_fetch = new Date().getTime();
ChapterRecognition.parseChapterNumber(c, manga);
})
.toList();

View file

@ -164,7 +164,7 @@ public class DownloadManager {
// Check that all the images are downloaded
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
@ -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);
}

View file

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