From 9bb31fca23be60122a1b77602ce3e64bfabf304f Mon Sep 17 00:00:00 2001 From: Claudemirovsky <63046606+Claudemirovsky@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:03:04 -0300 Subject: [PATCH] refactor: Fix more codefactor issues --- .../animeshouse/src/extractors/JsUnpacker.kt | 2 +- .../animeextension/all/jellyfin/Jellyfin.kt | 91 +++++++++---------- .../animeextension/all/kamyroll/Yomiroll.kt | 42 ++++----- .../anime4up/extractors/MoshahdaExtractor.kt | 33 ------- .../animeextension/ar/okanime/Okanime.kt | 2 +- .../de/moflixstream/MoflixStream.kt | 2 +- .../animeextension/en/putlocker/JSONUtil.java | 91 ------------------- .../animeextension/en/putlocker/JSONUtil.kt | 76 ++++++++++++++++ .../extractors/ProteaExtractor.kt | 3 +- .../animeextension/it/vvvvid/VVVVID.kt | 2 +- 10 files changed, 144 insertions(+), 200 deletions(-) delete mode 100644 src/ar/anime4up/src/eu/kanade/tachiyomi/animeextension/ar/anime4up/extractors/MoshahdaExtractor.kt delete mode 100644 src/en/putlocker/src/eu/kanade/tachiyomi/animeextension/en/putlocker/JSONUtil.java create mode 100644 src/en/putlocker/src/eu/kanade/tachiyomi/animeextension/en/putlocker/JSONUtil.kt diff --git a/multisrc/overrides/dooplay/animeshouse/src/extractors/JsUnpacker.kt b/multisrc/overrides/dooplay/animeshouse/src/extractors/JsUnpacker.kt index f893983a67..45cb9696ff 100644 --- a/multisrc/overrides/dooplay/animeshouse/src/extractors/JsUnpacker.kt +++ b/multisrc/overrides/dooplay/animeshouse/src/extractors/JsUnpacker.kt @@ -27,7 +27,7 @@ object JsUnpacker { val count = args[3].toInt() val origList = args[4].split("|") - val replaceMap = (0..(count - 1)).map { + val replaceMap = (0..count - 1).map { val key = convert(base, it) key to try { origList[it] } catch (e: Exception) { key } }.toMap() diff --git a/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/Jellyfin.kt b/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/Jellyfin.kt index 3d1391647c..e8ef557f33 100644 --- a/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/Jellyfin.kt +++ b/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/Jellyfin.kt @@ -663,60 +663,59 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS } private fun medialibPreference(screen: PreferenceScreen) = - ( - object : MediaLibPreference(screen.context) { - override fun reload() { - this.apply { - key = JFConstants.MEDIALIB_KEY - title = JFConstants.MEDIALIB_TITLE - summary = "%s" - - Thread { - try { - val mediaLibsResponse = client.newCall( - GET("$baseUrl/Users/$userId/Items?api_key=$apiKey"), - ).execute() - val mediaJson = mediaLibsResponse.body.let { json.decodeFromString(it.string()) }?.Items - - val entriesArray = mutableListOf() - val entriesValueArray = mutableListOf() - - if (mediaJson != null) { - for (media in mediaJson) { - entriesArray.add(media.Name) - entriesValueArray.add(media.Id) - } + object : MediaLibPreference(screen.context) { + override fun reload() { + this.apply { + key = JFConstants.MEDIALIB_KEY + title = JFConstants.MEDIALIB_TITLE + summary = "%s" + + Thread { + try { + val mediaLibsResponse = client.newCall( + GET("$baseUrl/Users/$userId/Items?api_key=$apiKey"), + ).execute() + val mediaJson = mediaLibsResponse.body.let { json.decodeFromString(it.string()) }?.Items + + val entriesArray = mutableListOf() + val entriesValueArray = mutableListOf() + + if (mediaJson != null) { + for (media in mediaJson) { + entriesArray.add(media.Name) + entriesValueArray.add(media.Id) } - - entries = entriesArray.toTypedArray() - entryValues = entriesValueArray.toTypedArray() - } catch (ex: Exception) { - entries = emptyArray() - entryValues = emptyArray() } - }.start() - - setOnPreferenceChangeListener { _, newValue -> - val selected = newValue as String - val index = findIndexOfValue(selected) - val entry = entryValues[index] as String - parentId = entry - preferences.edit().putString(key, entry).commit() + + entries = entriesArray.toTypedArray() + entryValues = entriesValueArray.toTypedArray() + } catch (ex: Exception) { + entries = emptyArray() + entryValues = emptyArray() } + }.start() + + setOnPreferenceChangeListener { _, newValue -> + val selected = newValue as String + val index = findIndexOfValue(selected) + val entry = entryValues[index] as String + parentId = entry + preferences.edit().putString(key, entry).commit() } } } - ).apply { reload() } + }.apply { reload() } + + private fun getSummary(isPassword: Boolean, value: String, placeholder: String) = when { + isPassword && value.isNotEmpty() || !isPassword && value.isEmpty() -> placeholder + else -> value + } private fun PreferenceScreen.editTextPreference(key: String, title: String, default: String, value: String, isPassword: Boolean = false, placeholder: String, mediaLibPref: MediaLibPreference): EditTextPreference { return EditTextPreference(context).apply { this.key = key this.title = title - summary = if ((isPassword && value.isNotEmpty()) || (!isPassword && value.isEmpty())) { - placeholder - } else { - value - } + summary = getSummary(isPassword, value, placeholder) this.setDefaultValue(default) dialogTitle = title @@ -732,11 +731,7 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS try { val newValueString = newValue as String val res = preferences.edit().putString(key, newValueString).commit() - summary = if ((isPassword && newValueString.isNotEmpty()) || (!isPassword && newValueString.isEmpty())) { - placeholder - } else { - newValueString - } + summary = getSummary(isPassword, newValueString, placeholder) val loginRes = login(true, context) if (loginRes == true) { mediaLibPref.reload() diff --git a/src/all/kamyroll/src/eu/kanade/tachiyomi/animeextension/all/kamyroll/Yomiroll.kt b/src/all/kamyroll/src/eu/kanade/tachiyomi/animeextension/all/kamyroll/Yomiroll.kt index 540da21834..96e28d865b 100644 --- a/src/all/kamyroll/src/eu/kanade/tachiyomi/animeextension/all/kamyroll/Yomiroll.kt +++ b/src/all/kamyroll/src/eu/kanade/tachiyomi/animeextension/all/kamyroll/Yomiroll.kt @@ -379,7 +379,7 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() { } ) + ( - if ((series_metadata?.audio_locales?.size ?: 0) > 1 || + if (series_metadata?.audio_locales?.size ?: 0 > 1 || movie_metadata?.is_dubbed == true ) { " Dub" @@ -501,33 +501,31 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() { } private fun localSubsPreference(screen: PreferenceScreen) = - ( - object : LocalSubsPreference(screen.context) { - override fun reload() { - this.apply { - key = PREF_USE_LOCAL_TOKEN_KEY - title = PREF_USE_LOCAL_TOKEN_TITLE - summary = runBlocking { - withContext(Dispatchers.IO) { getTokenDetail() } - } - setDefaultValue(false) - setOnPreferenceChangeListener { _, newValue -> - val new = newValue as Boolean - preferences.edit().putBoolean(key, new).commit().also { - Thread { - summary = runBlocking { - withContext(Dispatchers.IO) { getTokenDetail(true) } - } - }.start() - } + object : LocalSubsPreference(screen.context) { + override fun reload() { + this.apply { + key = PREF_USE_LOCAL_TOKEN_KEY + title = PREF_USE_LOCAL_TOKEN_TITLE + summary = runBlocking { + withContext(Dispatchers.IO) { getTokenDetail() } + } + setDefaultValue(false) + setOnPreferenceChangeListener { _, newValue -> + val new = newValue as Boolean + preferences.edit().putBoolean(key, new).commit().also { + Thread { + summary = runBlocking { + withContext(Dispatchers.IO) { getTokenDetail(true) } + } + }.start() } } } } - ).apply { reload() } + }.apply { reload() } // From Dopebox - private fun Iterable.parallelMap(f: suspend (A) -> B): List = + private inline fun Iterable.parallelMap(crossinline f: suspend (A) -> B): List = runBlocking { map { async(Dispatchers.Default) { f(it) } }.awaitAll() } diff --git a/src/ar/anime4up/src/eu/kanade/tachiyomi/animeextension/ar/anime4up/extractors/MoshahdaExtractor.kt b/src/ar/anime4up/src/eu/kanade/tachiyomi/animeextension/ar/anime4up/extractors/MoshahdaExtractor.kt deleted file mode 100644 index 225122bee8..0000000000 --- a/src/ar/anime4up/src/eu/kanade/tachiyomi/animeextension/ar/anime4up/extractors/MoshahdaExtractor.kt +++ /dev/null @@ -1,33 +0,0 @@ -package eu.kanade.tachiyomi.animeextension.ar.anime4up.extractors - -import android.util.Log -import eu.kanade.tachiyomi.animesource.model.Video -import eu.kanade.tachiyomi.network.GET -import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.Headers -import okhttp3.OkHttpClient - -class MoshahdaExtractor(private val client: OkHttpClient) { - fun videosFromUrl(url: String, headers: Headers): List