Skip to content
Open
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 = 30
extVersionCode = 31
extNames = ["Jellyfin (1)", "Jellyfin (2)", "Jellyfin (3)"]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,29 @@ class Jellyfin(private val suffix: String) :
checkPreferences()

val startIndex = (page - 1) * SERIES_FETCH_LIMIT
val url = getItemsUrl(startIndex).newBuilder().apply {
fun getSearchUrl(searchTerm: String) = getItemsUrl(startIndex).newBuilder().apply {
// Search for series, rather than seasons, since season names can just be "Season 1"
// Add "Episode" to search for episodes too, but this can lead to less relevant results
setQueryParameter(
"IncludeItemTypes",
if (preferences.searchEpisodes) "Movie,Series,Episode" else "Movie,Series",
)
setQueryParameter("Limit", SERIES_FETCH_LIMIT.toString())
setQueryParameter("SearchTerm", query)
setQueryParameter("SearchTerm", searchTerm)
}.build()

val items = client.get(url).parseAs<ItemListDto>(json)
val searchQuery = query.trim()
var items = client.get(getSearchUrl(searchQuery)).parseAs<ItemListDto>(json)
val seriesQuery = searchQuery.replace(SEASON_TITLE_SUFFIX_REGEX, "").ifBlank { searchQuery }
val requestedSeasonTitle = if (
seriesQuery != searchQuery &&
items.items.none { it.name.equals(searchQuery, ignoreCase = true) }
) {
items = client.get(getSearchUrl(seriesQuery)).parseAs<ItemListDto>(json)
searchQuery
} else {
null
}
val animeList = coroutineScope {
items.items.parallelFlatMap { series ->
when (series.type) {
Expand Down Expand Up @@ -215,9 +226,12 @@ class Jellyfin(private val suffix: String) :
}
}

val matchingAnime = requestedSeasonTitle?.let { title ->
animeList.filter { it.title.equals(title, ignoreCase = true) }
} ?: animeList
val hasNextPage = SERIES_FETCH_LIMIT * page < items.totalRecordCount

return AnimesPage(animeList, hasNextPage)
return AnimesPage(matchingAnime, hasNextPage)
}

// =========================== Anime Details ============================
Expand Down Expand Up @@ -581,6 +595,10 @@ class Jellyfin(private val suffix: String) :
companion object {
private const val SEASONS_FETCH_LIMIT = 20
private const val SERIES_FETCH_LIMIT = 5
private val SEASON_TITLE_SUFFIX_REGEX = Regex(
"""\s+(?:Season\s+\d+|Specials)\s*$""",
RegexOption.IGNORE_CASE,
)
private val LIBRARY_BLACKLIST = listOf(
"music",
"musicvideos",
Expand Down