From 04100074697aa4d9ceafb80911154f8eff70dd42 Mon Sep 17 00:00:00 2001 From: Quickdev Date: Fri, 28 Jun 2024 22:39:59 +0530 Subject: [PATCH] feat(all/jellyfin): Add option to hide extension affixes (#3361) --- src/all/jellyfin/build.gradle | 2 +- .../animeextension/all/jellyfin/Jellyfin.kt | 51 +++++++++++++++++-- .../all/jellyfin/JellyfinDto.kt | 13 +++-- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/all/jellyfin/build.gradle b/src/all/jellyfin/build.gradle index 929bbeddb2..06a13e0512 100644 --- a/src/all/jellyfin/build.gradle +++ b/src/all/jellyfin/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Jellyfin' extClass = '.JellyfinFactory' - extVersionCode = 15 + extVersionCode = 16 } apply from: "$rootDir/common.gradle" 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 8bfeb1b9f0..afd422e396 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 @@ -326,19 +326,46 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS private fun episodeListParse(response: Response, prefix: String): List { val httpUrl = response.request.url val epDetails = preferences.getEpDetails + val removeAffixes = preferences.removeAffixes return if (response.request.url.toString().startsWith("$baseUrl/Users/")) { val data = response.parseAs() - listOf(data.toSEpisode(baseUrl, userId!!, apiKey!!, epDetails, EpisodeType.MOVIE, prefix)) + listOf( + data.toSEpisode( + baseUrl, + userId!!, + apiKey!!, + epDetails, + EpisodeType.MOVIE, + prefix, + removeAffixes, + ), + ) } else if (httpUrl.fragment == "series") { val data = response.parseAs() data.items.map { val name = prefix + (it.seasonName?.let { "$it - " } ?: "") - it.toSEpisode(baseUrl, userId!!, apiKey!!, epDetails, EpisodeType.EPISODE, name) + it.toSEpisode( + baseUrl, + userId!!, + apiKey!!, + epDetails, + EpisodeType.EPISODE, + name, + removeAffixes, + ) } } else { val data = response.parseAs() data.items.map { - it.toSEpisode(baseUrl, userId!!, apiKey!!, epDetails, EpisodeType.EPISODE, prefix) + it.toSEpisode( + baseUrl, + userId!!, + apiKey!!, + epDetails, + EpisodeType.EPISODE, + prefix, + removeAffixes, + ) } }.reversed() } @@ -492,6 +519,9 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS private val PREF_EP_DETAILS = arrayOf("Overview", "Runtime", "Size") private val PREF_EP_DETAILS_DEFAULT = emptySet() + private const val PREF_REMOVE_AFFIXES = "pref_remove_affixes" + private const val PREF_REMOVE_AFFIXES_DEFAULT = false + private const val PREF_SUB_KEY = "preferred_subLang" private const val PREF_SUB_DEFAULT = "eng" @@ -605,6 +635,18 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS } }.also(screen::addPreference) + SwitchPreferenceCompat(screen.context).apply { + key = PREF_REMOVE_AFFIXES + title = "Remove \"Movie\" and \"Ep .\" affixes from episode names" + summary = "Requires refreshing of old episode lists to take effect." + setDefaultValue(PREF_REMOVE_AFFIXES_DEFAULT) + + setOnPreferenceChangeListener { _, newValue -> + val new = newValue as Boolean + preferences.edit().putBoolean(key, new).commit() + } + }.also(screen::addPreference) + ListPreference(screen.context).apply { key = PREF_SUB_KEY title = "Preferred sub language" @@ -704,6 +746,9 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS private val SharedPreferences.getEpDetails get() = getStringSet(PREF_EP_DETAILS_KEY, PREF_EP_DETAILS_DEFAULT)!! + private val SharedPreferences.removeAffixes + get() = getBoolean(PREF_REMOVE_AFFIXES, PREF_REMOVE_AFFIXES_DEFAULT) + private val SharedPreferences.getSubPref get() = getString(PREF_SUB_KEY, PREF_SUB_DEFAULT)!! diff --git a/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/JellyfinDto.kt b/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/JellyfinDto.kt index 76b449dc18..9b5d1a08ce 100644 --- a/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/JellyfinDto.kt +++ b/src/all/jellyfin/src/eu/kanade/tachiyomi/animeextension/all/jellyfin/JellyfinDto.kt @@ -137,15 +137,22 @@ data class ItemDto( epDetails: Set, epType: EpisodeType, prefix: String, + removeAffixes: Boolean, ): SEpisode = SEpisode.create().apply { when (epType) { EpisodeType.MOVIE -> { episode_number = 1F - name = "${prefix}Movie" + name = if (removeAffixes && prefix.isNotBlank()) prefix else "${prefix}Movie" } EpisodeType.EPISODE -> { - episode_number = indexNumber?.toFloat() ?: 1F - name = "${prefix}Ep. $indexNumber - ${this@ItemDto.name}" + name = if (indexNumber == null || removeAffixes) { + "${prefix}${this@ItemDto.name}" + } else { + "${prefix}Ep. $indexNumber - ${this@ItemDto.name}" + } + indexNumber?.let { + episode_number = it.toFloat() + } } }