Update SY fetchMangaInfo and getchChapterList to use the new 1.x functions
This commit is contained in:
parent
28fca8c839
commit
ce0726d863
@ -4,6 +4,7 @@ import com.elvishew.xlog.XLog
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
@ -12,10 +13,11 @@ import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.source.online.SuspendHttpSource
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.await
|
||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||
import eu.kanade.tachiyomi.util.lang.awaitSingleOrNull
|
||||
import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
|
||||
import exh.MERGED_SOURCE_ID
|
||||
@ -138,7 +140,8 @@ class MergedSource : SuspendHttpSource() {
|
||||
}.mapNotNull { loadedManga ->
|
||||
withContext(Dispatchers.IO) {
|
||||
if (loadedManga.manga != null && loadedManga.reference.getChapterUpdates) {
|
||||
loadedManga.source.fetchChapterList(loadedManga.manga).awaitSingle()
|
||||
loadedManga.source.getChapterList(loadedManga.manga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
.let { syncChaptersWithSource(db, it, loadedManga.manga, loadedManga.source) }
|
||||
.also {
|
||||
if (ifDownloadNewChapters && loadedManga.reference.downloadChapters) {
|
||||
@ -169,7 +172,7 @@ class MergedSource : SuspendHttpSource() {
|
||||
manga = Manga.create(reference.mangaSourceId).apply {
|
||||
url = reference.mangaUrl
|
||||
}
|
||||
manga.copyFrom(source.fetchMangaDetails(manga).awaitSingle())
|
||||
manga.copyFrom(source.getMangaDetails(manga.toMangaInfo()).toSManga())
|
||||
try {
|
||||
manga.id = db.insertManga(manga).await().insertedId()
|
||||
reference.mangaId = manga.id
|
||||
|
@ -2,13 +2,16 @@ package eu.kanade.tachiyomi.ui.browse.latest
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@ -170,13 +173,13 @@ open class LatestPresenter(
|
||||
* @return an observable of the manga to initialize
|
||||
*/
|
||||
private fun getMangaDetailsObservable(manga: Manga, source: Source): Observable<Manga> {
|
||||
return source.fetchMangaDetails(manga)
|
||||
.flatMap { networkManga ->
|
||||
manga.copyFrom(networkManga)
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
Observable.just(manga)
|
||||
}
|
||||
return runAsObservable({
|
||||
val networkManga = source.getMangaDetails(manga.toMangaInfo())
|
||||
manga.copyFrom(networkManga.toSManga())
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
manga
|
||||
})
|
||||
.onErrorResumeNext { Observable.just(manga) }
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,14 @@ import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.databinding.MigrationListControllerBinding
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
@ -33,7 +36,6 @@ import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.await
|
||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
@ -176,9 +178,9 @@ class MigrationListController(bundle: Bundle? = null) :
|
||||
searchResult,
|
||||
source.id
|
||||
)
|
||||
val chapters = (if (source is EHentai) source.fetchChapterList(localManga, throttleManager::throttle) else source.fetchChapterList(localManga)).awaitSingle()
|
||||
val chapters = (if (source is EHentai) source.getChapterList(localManga.toMangaInfo(), throttleManager::throttle) else source.getChapterList(localManga.toMangaInfo()))
|
||||
try {
|
||||
syncChaptersWithSource(db, chapters, localManga, source)
|
||||
syncChaptersWithSource(db, chapters.map { it.toSChapter() }, localManga, source)
|
||||
} catch (e: Exception) {
|
||||
return@async2 null
|
||||
}
|
||||
@ -208,7 +210,11 @@ class MigrationListController(bundle: Bundle? = null) :
|
||||
if (searchResult != null) {
|
||||
val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id)
|
||||
val chapters = try {
|
||||
(if (source is EHentai) source.fetchChapterList(localManga, throttleManager::throttle) else source.fetchChapterList(localManga)).awaitSingle()
|
||||
if (source is EHentai) {
|
||||
source.getChapterList(localManga.toMangaInfo(), throttleManager::throttle)
|
||||
} else {
|
||||
source.getChapterList(localManga.toMangaInfo())
|
||||
}.map { it.toSChapter() }
|
||||
} catch (e: java.lang.Exception) {
|
||||
Timber.e(e)
|
||||
emptyList()
|
||||
@ -238,8 +244,8 @@ class MigrationListController(bundle: Bundle? = null) :
|
||||
|
||||
if (result != null && result.thumbnail_url == null) {
|
||||
try {
|
||||
val newManga = sourceManager.getOrStub(result.source).fetchMangaDetails(result).awaitSingle()
|
||||
result.copyFrom(newManga)
|
||||
val newManga = sourceManager.getOrStub(result.source).getMangaDetails(result.toMangaInfo())
|
||||
result.copyFrom(newManga.toSManga())
|
||||
|
||||
db.insertManga(result).await()
|
||||
} catch (e: CancellationException) {
|
||||
@ -342,7 +348,8 @@ class MigrationListController(bundle: Bundle? = null) :
|
||||
val result = CoroutineScope(migratingManga.manga.migrationJob).async {
|
||||
val localManga = smartSearchEngine.networkToLocalManga(manga, source.id)
|
||||
try {
|
||||
val chapters = source.fetchChapterList(localManga).awaitSingle()
|
||||
val chapters = source.getChapterList(localManga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
syncChaptersWithSource(db, chapters, localManga, source)
|
||||
} catch (e: Exception) {
|
||||
return@async null
|
||||
@ -352,8 +359,8 @@ class MigrationListController(bundle: Bundle? = null) :
|
||||
|
||||
if (result != null) {
|
||||
try {
|
||||
val newManga = sourceManager.getOrStub(result.source).fetchMangaDetails(result).awaitSingle()
|
||||
result.copyFrom(newManga)
|
||||
val newManga = sourceManager.getOrStub(result.source).getMangaDetails(result.toMangaInfo())
|
||||
result.copyFrom(newManga.toSManga())
|
||||
|
||||
db.insertManga(result).await()
|
||||
} catch (e: CancellationException) {
|
||||
|
@ -4,12 +4,15 @@ import android.os.Bundle
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import exh.debug.DebugFunctions.sourceManager
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@ -42,7 +45,7 @@ class MigrationMangaPresenter(
|
||||
fun migrateManga(prevManga: Manga, manga: Manga, replace: Boolean) {
|
||||
val source = sourceManager.get(manga.source) ?: return
|
||||
|
||||
Observable.defer { source.fetchChapterList(manga) }.onErrorReturn { emptyList() }
|
||||
Observable.defer { runAsObservable({ source.getChapterList(manga.toMangaInfo()).map { it.toSChapter() } }) }.onErrorReturn { emptyList() }
|
||||
.doOnNext { migrateMangaInternal(source, it, prevManga, manga, replace) }
|
||||
.onErrorReturn { emptyList() }.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -4,14 +4,17 @@ import android.os.Bundle
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter.Companion.toItems
|
||||
import eu.kanade.tachiyomi.util.lang.asFlow
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import exh.savedsearches.EXHSavedSearch
|
||||
import exh.savedsearches.JsonSavedSearch
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -194,13 +197,13 @@ open class IndexPresenter(
|
||||
* @return an observable of the manga to initialize
|
||||
*/
|
||||
private fun getMangaDetailsObservable(manga: Manga, source: Source, isLatest: Boolean): Observable<Pair<Manga, Boolean>> {
|
||||
return source.fetchMangaDetails(manga)
|
||||
.flatMap { networkManga ->
|
||||
manga.copyFrom(networkManga)
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
Observable.just(manga to isLatest)
|
||||
}
|
||||
return runAsObservable({
|
||||
val networkManga = source.getMangaDetails(manga.toMangaInfo())
|
||||
manga.copyFrom(networkManga.toSManga())
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
manga to isLatest
|
||||
})
|
||||
.onErrorResumeNext { Observable.just(manga to isLatest) }
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,14 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.source.online.UrlImportableSource
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||
import exh.source.getMainSource
|
||||
import exh.util.executeOnIO
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@ -131,8 +133,8 @@ class GalleryAdder {
|
||||
}
|
||||
|
||||
// Fetch and copy details
|
||||
val newManga = source.fetchMangaDetails(manga).awaitSingle()
|
||||
manga.copyFrom(newManga)
|
||||
val newManga = source.getMangaDetails(manga.toMangaInfo())
|
||||
manga.copyFrom(newManga.toSManga())
|
||||
manga.initialized = true
|
||||
|
||||
if (fav) {
|
||||
@ -144,16 +146,15 @@ class GalleryAdder {
|
||||
|
||||
// Fetch and copy chapters
|
||||
try {
|
||||
val chapterListObs = if (source is EHentai) {
|
||||
source.fetchChapterList(manga, throttleFunc)
|
||||
val chapterList = if (source is EHentai) {
|
||||
source.getChapterList(manga.toMangaInfo(), throttleFunc)
|
||||
} else {
|
||||
source.fetchChapterList(manga)
|
||||
source.getChapterList(manga.toMangaInfo())
|
||||
}.map { it.toSChapter() }
|
||||
|
||||
if (chapterList.isNotEmpty()) {
|
||||
syncChaptersWithSource(db, chapterList, manga, source)
|
||||
}
|
||||
chapterListObs.map {
|
||||
if (it.isNotEmpty()) {
|
||||
syncChaptersWithSource(db, it, manga, source)
|
||||
} else emptyList<Chapter>() to emptyList()
|
||||
}.awaitSingle()
|
||||
} catch (e: Exception) {
|
||||
logger.w(context.getString(R.string.gallery_adder_chapter_fetch_error, manga.title), e)
|
||||
return GalleryAddEvent.Fail.Error(url, context.getString(R.string.gallery_adder_chapter_fetch_error, url))
|
||||
|
@ -4,10 +4,12 @@ import android.app.Application
|
||||
import com.elvishew.xlog.XLog
|
||||
import com.pushtorefresh.storio.sqlite.queries.RawQuery
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.database.tables.MangaTable
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.util.lang.await
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXHMigrations
|
||||
@ -90,8 +92,8 @@ object DebugFunctions {
|
||||
EXH_SOURCE_ID -> ex
|
||||
else -> return@forEach
|
||||
}
|
||||
)?.fetchMangaDetails(manga)?.map { networkManga ->
|
||||
manga.copyFrom(networkManga)
|
||||
)?.getMangaDetails(manga.toMangaInfo())?.let { networkManga ->
|
||||
manga.copyFrom(networkManga.toSManga())
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
}
|
||||
|
@ -11,13 +11,15 @@ import com.elvishew.xlog.XLog
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.toMangaInfo
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
||||
import eu.kanade.tachiyomi.util.lang.await
|
||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
import exh.debug.DebugToggles
|
||||
@ -261,11 +263,12 @@ class EHentaiUpdateWorker : JobService(), CoroutineScope {
|
||||
?: throw GalleryNotUpdatedException(false, IllegalStateException("Missing EH-based source (${manga.source})!"))
|
||||
|
||||
try {
|
||||
val updatedManga = source.fetchMangaDetails(manga).awaitSingle()
|
||||
manga.copyFrom(updatedManga)
|
||||
val updatedManga = source.getMangaDetails(manga.toMangaInfo())
|
||||
manga.copyFrom(updatedManga.toSManga())
|
||||
db.insertManga(manga).await()
|
||||
|
||||
val newChapters = source.fetchChapterList(manga).awaitSingle()
|
||||
val newChapters = source.getChapterList(manga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
|
||||
val (new, _) = syncChaptersWithSource(db, newChapters, manga, source) // Not suspending, but does block, maybe fix this?
|
||||
return new to db.getChapters(manga).await()
|
||||
|
Loading…
x
Reference in New Issue
Block a user