Skip to content

Commit

Permalink
feat(all/jellyfin): Add option to hide extension affixes (#3361)
Browse files Browse the repository at this point in the history
  • Loading branch information
quickdesh authored Jun 28, 2024
1 parent cc6cffd commit 0410007
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
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 - ${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()
}
}
}

Expand Down

0 comments on commit 0410007

Please sign in to comment.