Throttle E-Hentai migrations
This commit is contained in:
parent
510ae46fbf
commit
a481f3239c
@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.databinding.MigrationListControllerBinding
|
|||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
|
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.browse.migration.MigrationMangaDialog
|
import eu.kanade.tachiyomi.ui.browse.migration.MigrationMangaDialog
|
||||||
@ -33,6 +34,7 @@ import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
|
|||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
|
import exh.eh.EHentaiThrottleManager
|
||||||
import exh.smartsearch.SmartSearchEngine
|
import exh.smartsearch.SmartSearchEngine
|
||||||
import exh.util.await
|
import exh.util.await
|
||||||
import exh.util.executeOnIO
|
import exh.util.executeOnIO
|
||||||
@ -78,6 +80,8 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||||||
private var selectedPosition: Int? = null
|
private var selectedPosition: Int? = null
|
||||||
private var manualMigrations = 0
|
private var manualMigrations = 0
|
||||||
|
|
||||||
|
private val throttleManager = EHentaiThrottleManager()
|
||||||
|
|
||||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||||
binding = MigrationListControllerBinding.inflate(inflater)
|
binding = MigrationListControllerBinding.inflate(inflater)
|
||||||
return binding.root
|
return binding.root
|
||||||
@ -119,6 +123,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
private suspend fun runMigrations(mangas: List<MigratingManga>) {
|
private suspend fun runMigrations(mangas: List<MigratingManga>) {
|
||||||
|
throttleManager.resetThrottle()
|
||||||
if (config == null) return
|
if (config == null) return
|
||||||
val useSourceWithMost = preferences.useSourceWithMost().get()
|
val useSourceWithMost = preferences.useSourceWithMost().get()
|
||||||
val useSmartSearch = preferences.smartMigration().get()
|
val useSmartSearch = preferences.smartMigration().get()
|
||||||
@ -172,7 +177,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||||||
searchResult,
|
searchResult,
|
||||||
source.id
|
source.id
|
||||||
)
|
)
|
||||||
val chapters = source.fetchChapterList(localManga).toSingle().await(Schedulers.io())
|
val chapters = (if (source is EHentai) source.fetchChapterList(localManga, throttleManager::throttle) else source.fetchChapterList(localManga)).toSingle().await(Schedulers.io())
|
||||||
try {
|
try {
|
||||||
syncChaptersWithSource(db, chapters, localManga, source)
|
syncChaptersWithSource(db, chapters, localManga, source)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -204,7 +209,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||||||
if (searchResult != null) {
|
if (searchResult != null) {
|
||||||
val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id)
|
val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id)
|
||||||
val chapters = try {
|
val chapters = try {
|
||||||
source.fetchChapterList(localManga).toSingle().await(Schedulers.io()) ?: emptyList()
|
(if (source is EHentai) source.fetchChapterList(localManga, throttleManager::throttle) else source.fetchChapterList(localManga)).toSingle().await(Schedulers.io()) ?: emptyList()
|
||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
emptyList()
|
emptyList()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user