Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ second release the same day); the household protocol, scheduler, and database ca

## [Unreleased]

### Added

- Guide: press Menu from anywhere in the Guide or Favorites (or Settings on remotes with a Settings key) to jump directly to Settings; press Menu again to return to Guide. Pressing Left from any channel column also jumps focus to the top tab bar without scrolling up (#25).
- Custom channel Library picker: added a **Ratings** multi-select filter (backed by Plex `contentRating` and Jellyfin `OfficialRating`), active filter counts on filter buttons, and content-rating display on title rows (#48).
- Suggest channels: expanded suggestions from 12 to up to 24 channels, adding TV network and movie studio starters alongside reruns, collections, genres, decades, movie channels, and playlists (#15).

## 2026.11.5

### Added
Expand Down
27 changes: 26 additions & 1 deletion app/src/main/kotlin/net/clickarr/ShellScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ fun ShellScreen(
Modifier
.fillMaxSize()
.background(ClickarrColors.BgBase)
.onPreviewKeyEvent { lastKeyAt[0] = SystemClock.uptimeMillis(); false },
.onPreviewKeyEvent { lastKeyAt[0] = SystemClock.uptimeMillis(); false }
.onKeyEvent { e ->
handleShellKey(e, tab) { next, isSwitched ->
switched = isSwitched
tab = next
}
},
) {
ShellTopRow(
tab,
Expand Down Expand Up @@ -260,6 +266,25 @@ private fun ShellTabPill(t: ShellTab, selected: Boolean, onFocus: () -> Unit, on
}
}

private fun handleShellKey(
e: androidx.compose.ui.input.key.KeyEvent,
tab: ShellTab,
onNavigate: (ShellTab, Boolean) -> Unit,
): Boolean {
if (e.type != KeyEventType.KeyDown || e.nativeKeyEvent.repeatCount != 0) return false
return when {
e.key == Key.Menu -> {
if (tab == ShellTab.SETTINGS) onNavigate(ShellTab.GUIDE, false) else onNavigate(ShellTab.SETTINGS, true)
true
}
e.nativeKeyEvent.keyCode == android.view.KeyEvent.KEYCODE_SETTINGS -> {
if (tab != ShellTab.SETTINGS) onNavigate(ShellTab.SETTINGS, true)
true
}
else -> false
}
}

private const val TAG = "Shell"
private const val TAB_FOCUS_WINDOW_MS = 1_500L
private const val CLOCK_TICK_MS = 5_000L
4 changes: 4 additions & 0 deletions core/model/src/main/kotlin/net/clickarr/core/model/Media.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ sealed interface MediaItem {
val artwork: Artwork
val genres: List<String>
val year: Int?
val contentRating: String? get() = null
}

@Suppress("LongParameterList")
@Serializable
data class Show(
override val ref: MediaRef,
Expand All @@ -77,6 +79,7 @@ data class Show(
val episodeCount: Int = 0,
/** The server's synopsis, for the guide's preview card. */
val summary: String? = null,
override val contentRating: String? = null,
) : MediaItem

@Serializable
Expand Down Expand Up @@ -120,6 +123,7 @@ data class Movie(
override val media: List<MediaVersion> = emptyList(),
/** The server's synopsis, for the guide's preview card. */
val summary: String? = null,
override val contentRating: String? = null,
) : MediaItem, Playable

/** [itemCount] is how many titles the server says it holds, when it says (Plex childCount, Jellyfin ChildCount). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ChannelSuggester @Inject constructor(private val registry: ProviderRegistr
}

companion object {
const val MAX = 12
const val MAX = 24
private const val MAX_ITEMS_SCANNED = 2_000
}
}
84 changes: 77 additions & 7 deletions data/src/main/kotlin/net/clickarr/data/SuggestionRules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ data class LibraryScan(
/**
* The rules behind "Suggest channels": what a person with an afternoon would make from this library.
* Rerun channels for the shows with the most episodes, the collections someone bothered to curate,
* the genres and decades with enough to fill a day, one shuffled movie channel, and a playlist. Every
* suggestion plays back to back; padded slots are a choice, not a default. Thresholds scale down for a
* small library, which gets what it has rather than nothing. Pure, so it is unit tested directly.
* the genres, networks, studios, and decades with enough to fill a day, one shuffled movie channel,
* and playlists. Every suggestion plays back to back; padded slots are a choice, not a default.
* Thresholds scale down for a small library, which gets what it has rather than nothing. Pure, so it
* is unit tested directly.
*/
object SuggestionRules {
/** Minimum sizes before a grouping is worth a channel. */
Expand All @@ -39,6 +40,8 @@ object SuggestionRules {
val collectionItems: Int,
val genreShows: Int,
val genreMovies: Int,
val networkShows: Int,
val studioMovies: Int,
val decadeShows: Int,
val decadeMovies: Int,
val allMovies: Int,
Expand All @@ -47,10 +50,12 @@ object SuggestionRules {

val NORMAL = Thresholds(
rerunEpisodes = 12, collectionItems = 2, genreShows = 5, genreMovies = 12,
networkShows = 4, studioMovies = 6,
decadeShows = 6, decadeMovies = 15, allMovies = 20, playlistItems = 3,
)
val SMALL = Thresholds(
rerunEpisodes = 2, collectionItems = 2, genreShows = 2, genreMovies = 2,
networkShows = 2, studioMovies = 2,
decadeShows = 2, decadeMovies = 2, allMovies = 3, playlistItems = 2,
)

Expand All @@ -63,6 +68,8 @@ object SuggestionRules {
out += reruns(scan, t).take(MAX_RERUNS)
out += collections(scan, t).take(MAX_COLLECTIONS)
out += themes(scan, t).take(MAX_THEMES)
out += networks(scan, t).take(MAX_NETWORKS)
out += studios(scan, t).take(MAX_STUDIOS)
out += decades(scan, t).take(MAX_DECADES)
out += movieChannels(scan, t).take(1)
out += playlists(scan, t).take(MAX_PLAYLISTS)
Expand Down Expand Up @@ -112,6 +119,59 @@ object SuggestionRules {
return scored.sortedByDescending { it.first }.map { it.second }
}

/** TV networks with enough shows to sustain a channel, strongest first across show libraries. */
fun networks(scan: LibraryScan, t: Thresholds): List<Suggestion> {
val scored = ArrayList<Pair<Int, Suggestion>>()
for ((lib, shows) in scan.shows) {
val grouped = shows
.mapNotNull { show -> show.network?.trim()?.takeIf(String::isNotEmpty)?.let { it to show } }
.groupBy { (network, _) -> network.lowercase() }
for ((_, entries) in grouped) {
if (entries.size < t.networkShows) continue
val spellings = entries.map { it.first }
val label = spellings.groupingBy { it }.eachCount().maxBy { it.value }.key
val suggestion = Suggestion(
label,
ProgrammingSource.Library(lib.ref, MediaFilter(networks = spellings.toSet())),
glyph("tv"),
OrderingMode.SHUFFLE,
null,
"${entries.size} shows, shuffled",
runs = runsFor("shows"),
)
scored += entries.size to suggestion
}
}
return scored.sortedWith(compareByDescending<Pair<Int, Suggestion>> { it.first }.thenBy { it.second.name.lowercase() })
.map { it.second }
}

/** Movie studios with enough films to sustain a channel, strongest first across movie libraries. */
fun studios(scan: LibraryScan, t: Thresholds): List<Suggestion> {
val scored = ArrayList<Pair<Int, Suggestion>>()
for ((lib, movies) in scan.movies) {
val grouped = movies
.mapNotNull { movie -> movie.studio?.trim()?.takeIf(String::isNotEmpty)?.let { it to movie } }
.groupBy { (studio, _) -> studio.lowercase() }
for ((_, entries) in grouped) {
if (entries.size < t.studioMovies) continue
val spellings = entries.map { it.first }
val label = spellings.groupingBy { it }.eachCount().maxBy { it.value }.key
val suggestion = Suggestion(
studioChannelName(label),
ProgrammingSource.Library(lib.ref, MediaFilter(studios = spellings.toSet())),
glyph("film"),
OrderingMode.SHUFFLE,
null,
"${entries.size} movies, shuffled",
)
scored += entries.size to suggestion
}
}
return scored.sortedWith(compareByDescending<Pair<Int, Suggestion>> { it.first }.thenBy { it.second.name.lowercase() })
.map { it.second }
}

fun decades(scan: LibraryScan, t: Thresholds): List<Suggestion> {
val scored = ArrayList<Pair<Int, Suggestion>>()
for ((lib, shows) in scan.shows) scored += byDecade(lib, shows, t.decadeShows, "Shows", "shows")
Expand Down Expand Up @@ -169,6 +229,13 @@ object SuggestionRules {
/** 1980 reads as "80s"; 2000 and later keep the century ("2000s", "2010s"). */
fun decadeName(decade: Int): String = if (decade < CENTURY_2000) "${decade % CENTURY}s" else "${decade}s"

/** Append "Movies" when a studio name does not already read as a film studio (e.g. "A24" -> "A24 Movies"). */
fun studioChannelName(studio: String): String {
val lower = studio.lowercase()
val alreadyFilm = STUDIO_SUFFIXES.any { lower.endsWith(it) }
return if (alreadyFilm) studio else "$studio Movies"
}

private fun countTagged(items: List<MediaItem>, tags: Set<String>): Int =
items.count { item -> item.genres.any { it.lowercase() in tags } }

Expand All @@ -182,14 +249,17 @@ object SuggestionRules {

const val SMALL_LIBRARY = 40
private const val MAX_RERUNS = 4
private const val MAX_COLLECTIONS = 3
private const val MAX_THEMES = 3
private const val MAX_DECADES = 2
private const val MAX_PLAYLISTS = 1
private const val MAX_COLLECTIONS = 4
private const val MAX_THEMES = 5
private const val MAX_NETWORKS = 4
private const val MAX_STUDIOS = 3
private const val MAX_DECADES = 3
private const val MAX_PLAYLISTS = 2
private const val DECADE = 10
private const val CENTURY = 100
private const val CENTURY_2000 = 2000
private const val SHOW_RUN_MAX = 3
private val STUDIO_SUFFIXES = listOf("pictures", "films", "movies", "cinema", "studios", "animation", "entertainment")

val SHOW_THEMES = listOf(
Theme("Sitcoms", setOf("comedy"), "laugh"),
Expand Down
53 changes: 49 additions & 4 deletions data/src/test/kotlin/net/clickarr/data/SuggestionRulesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class SuggestionRulesTest {
private val tv = Library(ref("tv"), "TV Shows", LibraryKind.SHOWS)
private val films = Library(ref("films"), "Movies", LibraryKind.MOVIES)

private fun show(title: String, episodes: Int, vararg genres: String, year: Int = 2010) =
Show(ref(title), title, genres = genres.toList(), year = year, episodeCount = episodes)
private fun show(title: String, episodes: Int, vararg genres: String, year: Int = 2010, network: String? = null) =
Show(ref(title), title, genres = genres.toList(), year = year, studio = network, network = network, episodeCount = episodes)

private fun movie(title: String, vararg genres: String, year: Int = 2010) =
Movie(ref(title), title, genres = genres.toList(), year = year, runtime = 100.minutes)
private fun movie(title: String, vararg genres: String, year: Int = 2010, studio: String? = null) =
Movie(ref(title), title, genres = genres.toList(), year = year, studio = studio, runtime = 100.minutes)

/** Enough titles to count as a normal library, with no genre strong enough to make a channel on its own. */
private fun ballast(): List<Movie> = (1..40).map { movie("Ballast $it", "Genre$it", year = 1900 + it) }
Expand Down Expand Up @@ -126,4 +126,49 @@ class SuggestionRulesTest {
SuggestionRules.decadeName(2000) shouldBe "2000s"
SuggestionRules.decadeName(2010) shouldBe "2010s"
}

@Test
fun `networks and studios with enough titles become shuffled channels`() {
val shows = (1..5).map { show("NBC Show $it", 8, "Comedy", network = "NBC") } +
(1..2).map { show("Small Net $it", 8, "Drama", network = "CW") }
val movies = (1..6).map { movie("A24 Film $it", "Drama", year = 2015, studio = "A24") } +
(1..6).map { movie("Uni Film $it", "Action", year = 1995, studio = "Universal Pictures") } +
ballast()
val plan = SuggestionRules.plan(scan(shows = shows, movies = movies))
val names = plan.map { it.name }
names shouldContain "NBC"
names shouldNotContain "CW"
names shouldContain "A24 Movies"
names shouldContain "Universal Pictures"

val nbc = plan.first { it.name == "NBC" }
nbc.order shouldBe OrderingMode.SHUFFLE
nbc.runs shouldBe EpisodeRuns(2, 3)
nbc.reason shouldBe "5 shows, shuffled"

val a24 = plan.first { it.name == "A24 Movies" }
a24.order shouldBe OrderingMode.SHUFFLE
a24.runs.shouldBeNull()
a24.reason shouldBe "6 movies, shuffled"
}

@Test
fun `a large diverse library produces more than twelve suggestions up to the cap`() {
val shows = (1..5).map { show("Long Show $it", 100 + it, "Comedy", year = 1990, network = "NBC") } +
(1..5).map { show("SciFi Show $it", 10, "Sci-Fi", year = 2000, network = "HBO") } +
(1..5).map { show("Crime Show $it", 10, "Crime", year = 2010, network = "FX") } +
(1..5).map { show("Toon Show $it", 10, "Animation", year = 2010, network = "Cartoon Network") }
val movies = (1..15).map { movie("Comedy $it", "Comedy", year = 1985, studio = "A24") } +
(1..15).map { movie("Action $it", "Action", year = 1995, studio = "Universal Pictures") } +
(1..15).map { movie("Horror $it", "Horror", year = 2005, studio = "Blumhouse") }
val collections = (1..4).map { films to Collection(ref("c-$it"), "Collection $it", itemCount = 4) }
val playlists = (1..2).map { Playlist(ref("p-$it"), "Playlist $it", itemCount = 5) }

val plan = SuggestionRules.plan(scan(shows, movies, collections, playlists))
(plan.size > 12) shouldBe true
(plan.size <= ChannelSuggester.MAX) shouldBe true
plan.map { it.name } shouldContain "NBC"
plan.map { it.name } shouldContain "A24 Movies"
plan.map { it.name } shouldContain "Universal Pictures"
}
}
Loading
Loading