Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preference(jellyfin): Add option to hide extension affixes #3361

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/all/jellyfin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Jellyfin'
extClass = '.JellyfinFactory'
extVersionCode = 15
extVersionCode = 16
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,46 @@ class Jellyfin(private val suffix: String) : ConfigurableAnimeSource, AnimeHttpS
private fun episodeListParse(response: Response, prefix: String): List<SEpisode> {
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<ItemDto>()
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<ItemsDto>()
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<ItemsDto>()
data.items.map {
it.toSEpisode(baseUrl, userId!!, apiKey!!, epDetails, EpisodeType.EPISODE, prefix)
it.toSEpisode(
baseUrl,
userId!!,
apiKey!!,
epDetails,
EpisodeType.EPISODE,
prefix,
removeAffixes,
)
}
}.reversed()
}
Expand Down Expand Up @@ -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<String>()

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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,22 @@ data class ItemDto(
epDetails: Set<String>,
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 - ${[email protected]}"
name = if (indexNumber == null || removeAffixes) {
"${prefix}${[email protected]}"
} else {
"${prefix}Ep. $indexNumber - ${[email protected]}"
}
indexNumber?.let {
episode_number = it.toFloat()
}
}
}

Expand Down