Browse Source

Allow custom parsing of chapter number on sources

inorichi 9 years ago
parent
commit
d4bb092543

+ 3 - 1
app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.java

@@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable;
 import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable;
 import eu.kanade.tachiyomi.data.database.tables.MangaTable;
 import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService;
+import eu.kanade.tachiyomi.data.source.base.Source;
 import eu.kanade.tachiyomi.util.ChapterRecognition;
 import rx.Observable;
 
@@ -240,13 +241,14 @@ public class DatabaseHelper {
     }
 
     // Add new chapters or delete if the source deletes them
-    public Observable<Pair<Integer, Integer>> insertOrRemoveChapters(Manga manga, List<Chapter> sourceChapters) {
+    public Observable<Pair<Integer, Integer>> insertOrRemoveChapters(Manga manga, List<Chapter> sourceChapters, Source source) {
         List<Chapter> dbChapters = getChapters(manga).executeAsBlocking();
 
         Observable<List<Chapter>> newChapters = Observable.from(sourceChapters)
                 .filter(c -> !dbChapters.contains(c))
                 .doOnNext(c -> {
                     c.manga_id = manga.id;
+                    source.parseChapterNumber(c);
                     ChapterRecognition.parseChapterNumber(c, manga);
                 })
                 .toList();

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt

@@ -201,9 +201,10 @@ class LibraryUpdateService : Service() {
      * @return a pair of the inserted and removed chapters.
      */
     fun updateManga(manga: Manga): Observable<Pair<Int, Int>> {
-        return sourceManager.get(manga.source)!!
+        val source = sourceManager.get(manga.source)
+        return source!!
                 .pullChaptersFromNetwork(manga.url)
-                .flatMap { db.insertOrRemoveChapters(manga, it) }
+                .flatMap { db.insertOrRemoveChapters(manga, it, source) }
     }
 
     /**

+ 5 - 0
app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java

@@ -235,6 +235,11 @@ public abstract class Source extends BaseSource {
         return getId() + chapterUrl;
     }
 
+    // Overridable method to allow custom parsing.
+    public void parseChapterNumber(Chapter chapter) {
+
+    }
+
     protected LazyHeaders.Builder glideHeadersBuilder() {
         LazyHeaders.Builder builder = new LazyHeaders.Builder();
         for (Map.Entry<String, List<String>> entry : requestHeaders.toMultimap().entrySet()) {

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java

@@ -119,7 +119,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
     private Observable<Pair<Integer, Integer>> getOnlineChaptersObs() {
         return source.pullChaptersFromNetwork(manga.url)
                 .subscribeOn(Schedulers.io())
-                .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters))
+                .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters, source))
                 .observeOn(AndroidSchedulers.mainThread());
     }