Tighten suggestion rules and request the fields they check (0.46.0 in testing)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId = "tv.orbit.classic"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 46
|
||||
versionName = "0.45.0-toonami-vortex"
|
||||
versionCode = 47
|
||||
versionName = "0.46.0-suggestion-rules"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
|
||||
|
||||
@@ -21,9 +21,11 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
||||
|
||||
/** Toonami-inspired: Paul's picks and the earlier shortlist, split into cartoons by day and anime from the evening. */
|
||||
private val VortexDaytime = listOf("Batman Beyond", "Batman: The Animated Series", "Superman: The Animated Series", "ThunderCats", "The Powerpuff Girls", "Jonny Quest",
|
||||
"Samurai Jack", "Justice League", "Voltron", "ReBoot", "Beast Wars")
|
||||
private val VortexEvening = listOf("Dragon Ball Z", "Dragon Ball", "Dragon Ball GT", "Naruto", "Yu Yu Hakusho", "Gundam Wing", "Sailor Moon", "Robotech", "Ronin Warriors",
|
||||
"Tenchi Muyo", "Outlaw Star", "The Big O", "Cardcaptors", "Zoids")
|
||||
"Samurai Jack", "Justice League", "Justice League Unlimited", "Voltron", "Voltron: Defender of the Universe", "ReBoot", "Beast Wars: Transformers")
|
||||
private val VortexEvening = listOf("Dragon Ball Z", "Dragon Ball", "Dragon Ball GT", "Naruto", "Yu Yu Hakusho", "Gundam Wing", "Mobile Suit Gundam Wing", "Sailor Moon", "Robotech", "Ronin Warriors",
|
||||
"Tenchi Muyo", "Tenchi Muyo! Ryo-Ohki", "Tenchi Universe", "Outlaw Star", "The Big O", "Cardcaptors", "Cardcaptor Sakura", "Zoids", "Zoids: Chaotic Century")
|
||||
|
||||
private val NotCultCinema = setOf("Family", "Animation", "Documentary", "Music")
|
||||
|
||||
internal val SmartChannels = listOf(
|
||||
ChannelProgramming(102, "After Dark", listOf("The Thing", "The Evil Dead", "Re-Animator", "Hellraiser", "Videodrome", "An American Werewolf in London",
|
||||
@@ -34,11 +36,12 @@ internal val SmartChannels = listOf(
|
||||
"Escape from New York", "They Live", "Repo Man", "Donnie Darko", "From Dusk Till Dawn", "Creepshow", "Near Dark", "Halloween", "The Fog", "Blue Velvet",
|
||||
"The Wicker Man", "An American Werewolf in London", "Prince of Darkness"), group = "day")),
|
||||
suggestionRules = listOf(
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Horror", "Comedy"), 1975..2010, 6f, setOf("NC-17", "X"), 40),
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Science Fiction", "Action"), 1975..2005, 6.5f, setOf("NC-17", "X"), 40),
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Thriller", "Mystery"), 1975..2005, 6.5f, setOf("NC-17", "X"), 30),
|
||||
SuggestionRule("late", "Late night", "Movie", listOf("Horror"), 1970..2010, 6f, emptySet(), 90))),
|
||||
ChannelProgramming(103, "Vortex", VortexDaytime + VortexEvening, seriesCount = 30, finishTogether = true,
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Horror", "Comedy"), 1975..2010, 6f, setOf("NC-17", "X"), 40, NotCultCinema, 70),
|
||||
// Capped so the biggest blockbusters stay out: this channel is cult cinema.
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Science Fiction", "Action"), 1975..2005, 6.5f, setOf("NC-17", "X"), 40, NotCultCinema, 70, 7.9f),
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Thriller", "Mystery"), 1975..2005, 6.5f, setOf("NC-17", "X"), 30, NotCultCinema, 70, 7.9f),
|
||||
SuggestionRule("late", "Late night", "Movie", listOf("Horror"), 1970..2010, 6f, emptySet(), 90, NotCultCinema, 70))),
|
||||
ChannelProgramming(103, "Vortex", VortexDaytime + VortexEvening, seriesCount = 40, finishTogether = true, exactTitles = true,
|
||||
dayParts = listOf(DayPart(6, 18, VortexDaytime, group = "day"), DayPart(18, 6, VortexEvening, group = "night")),
|
||||
suggestionRules = listOf(
|
||||
SuggestionRule("day", "Daytime", "Series", listOf("Animation", "Action"), 1985..2015, 7f, setOf("TV-MA"), 30),
|
||||
|
||||
@@ -16,7 +16,8 @@ import java.net.URLEncoder
|
||||
|
||||
/** A plain rule for what suits a channel. Every suggestion it makes can be explained from these fields alone. */
|
||||
internal data class SuggestionRule(val group: String, val label: String, val type: String, val genres: List<String>,
|
||||
val years: IntRange, val minRating: Float, val excludeRatings: Set<String> = emptySet(), val limit: Int)
|
||||
val years: IntRange, val minRating: Float, val excludeRatings: Set<String> = emptySet(), val limit: Int,
|
||||
val excludeGenres: Set<String> = emptySet(), val minMinutes: Int = 0, val maxRating: Float = 10f)
|
||||
|
||||
internal data class Suggestion(val id: String, val title: String, val year: Int?, val type: String, val group: String, val reason: String,
|
||||
val sourceId: String? = null, val durationMs: Long? = null)
|
||||
@@ -57,7 +58,7 @@ internal fun findSuggestions(transport: EmbyTransport, userId: String, token: ()
|
||||
val genre = URLEncoder.encode(rule.genres.first(), "UTF-8")
|
||||
val reply = transport.execute(EmbyRequest("GET", "/Items?UserId=$userId&Recursive=true&IncludeItemTypes=${rule.type}&Genres=$genre&Years=${rule.years.joinToString(",")}" +
|
||||
"&MinCommunityRating=${rule.minRating}&SortBy=CommunityRating&SortOrder=Descending&StartIndex=${page * SUGGESTION_PAGE}&Limit=$SUGGESTION_PAGE" +
|
||||
"&Fields=Genres,MediaSources&EnableImages=false&EnableUserData=false", token = token(), readTimeoutMs = WHOLE_SERIES_TIMEOUT_MS))
|
||||
"&Fields=Genres,MediaSources,ProductionYear,OfficialRating,CommunityRating&EnableImages=false&EnableUserData=false", token = token(), readTimeoutMs = WHOLE_SERIES_TIMEOUT_MS))
|
||||
EmbyClient.expectSuccess(reply.status, false)
|
||||
val rows = EmbyClient.parse(reply.body).optJSONArray("Items") ?: break
|
||||
for (index in 0 until rows.length()) {
|
||||
@@ -69,11 +70,13 @@ internal fun findSuggestions(transport: EmbyTransport, userId: String, token: ()
|
||||
if (!EmbyClient.validId(id) || title.isBlank() || row.optString("Type") != rule.type || id in alreadyInPool || id in rejected || id in found) continue
|
||||
val tags = row.optJSONArray("Genres")
|
||||
val genres = (0 until (tags?.length() ?: 0)).mapNotNull { tags?.optString(it) }.map { it.lowercase() }
|
||||
if (rule.genres.any { it.lowercase() !in genres }) continue
|
||||
if (rule.genres.any { it.lowercase() !in genres } || rule.excludeGenres.any { it.lowercase() in genres }) continue
|
||||
val score = row.optDouble("CommunityRating", 0.0)
|
||||
if (score > rule.maxRating) continue
|
||||
if (row.optString("OfficialRating") in rule.excludeRatings) continue
|
||||
if (!seen.add("${seriesKey(title)}#$year")) continue
|
||||
val source = if (rule.type == "Movie") playableSource(row) ?: continue else null
|
||||
val score = row.optDouble("CommunityRating", 0.0)
|
||||
if (source != null && source.second < rule.minMinutes * 60_000L) continue
|
||||
val reason = "${rule.label}: ${rule.genres.joinToString(" and ")}, ${year ?: "year unknown"}, rated ${"%.1f".format(java.util.Locale.UK, score)}"
|
||||
found[id] = Suggestion(id, title, year, rule.type, rule.group, reason, source?.first, source?.second)
|
||||
taken++
|
||||
|
||||
@@ -41,7 +41,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
|
||||
connection.connectTimeout = 10_000
|
||||
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
|
||||
connection.setRequestProperty("Accept", "application/json")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.45.0\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.46.0\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -99,6 +99,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
var scheduledChannels by remember { mutableStateOf<Map<Int, ScheduledChannel>>(emptyMap()) }
|
||||
var suggesting by remember { mutableStateOf<ChannelProgramming?>(null) }
|
||||
var suggestions by remember { mutableStateOf<List<Suggestion>>(emptyList()) }
|
||||
var savingSuggestions by remember { mutableStateOf(false) }
|
||||
var tickedSuggestions by remember { mutableStateOf<Set<String>>(emptySet()) }
|
||||
var lastSmartPress by remember { mutableLongStateOf(0L) }
|
||||
fun onAir(loop: SampleChannel) = scheduledChannels[loop.number]?.takeIf { it.loop === loop } ?: loop
|
||||
@@ -503,7 +504,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
val active = session ?: return
|
||||
val loop = smartLoop(programming) ?: return
|
||||
if (busy) return
|
||||
busy = true; message = "Saving your choices and reading what's new…"
|
||||
busy = true; savingSuggestions = true; message = "Saving your choices and reading what's new. This can take a minute or two…"
|
||||
val accepted = suggestions.filter { it.id in tickedSuggestions }
|
||||
val left = suggestions.filter { it.id !in tickedSuggestions }.map { it.id }
|
||||
job = scope.launch {
|
||||
@@ -521,9 +522,11 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
suggesting = null
|
||||
message = "${programming.name} now has ${report.shows.size} titles and ${report.programmes} programmes planned. ${report.requests} requests, ${report.fetchMs / 1000} s to read, ${report.bytes / 1024} KB stored."
|
||||
} catch (cancelled: CancellationException) { throw cancelled }
|
||||
catch (failure: EmbyCheckException) { message = failure.message }
|
||||
catch (_: Exception) { message = "Your choices were saved, but ${programming.name} couldn't be updated. Try again later." }
|
||||
finally { busy = false }
|
||||
catch (failure: Exception) {
|
||||
android.util.Log.w("OrbitSchedule", "channel=${programming.number} saveFailed=${failure.javaClass.simpleName}")
|
||||
message = "Your choices were saved, but ${programming.name} couldn't be updated. It will try again by itself within the hour."
|
||||
}
|
||||
finally { busy = false; savingSuggestions = false }
|
||||
}
|
||||
}
|
||||
fun checkMoreSeries() {
|
||||
@@ -551,7 +554,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
onToggle = { id -> tickedSuggestions = if (id in tickedSuggestions) tickedSuggestions - id else tickedSuggestions + id },
|
||||
onAll = { all -> tickedSuggestions = if (all) suggestions.map { it.id }.toSet() else emptySet() },
|
||||
onSave = { changeNow -> saveSuggestions(programming, changeNow) },
|
||||
onBack = { job?.cancel(); busy = false; suggesting = null })
|
||||
// Leaving while saving lets it finish, so your choices still reach the channel.
|
||||
onBack = { if (!savingSuggestions) { job?.cancel(); busy = false }; suggesting = null })
|
||||
return
|
||||
}
|
||||
if (reviewingSeries) {
|
||||
|
||||
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
|
||||
next.instanceFollowRedirects = false
|
||||
next.connectTimeout = 10_000
|
||||
next.readTimeout = 20_000
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.45.0")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.46.0")
|
||||
next.setRequestProperty("Accept-Encoding", "identity")
|
||||
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
|
||||
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
|
||||
|
||||
@@ -94,4 +94,24 @@ class ChannelSuggestionsTest {
|
||||
assertEquals(vortex.searches.size, vortex.searches.distinct().size)
|
||||
assertTrue(vortex.seriesCount >= vortex.searches.size)
|
||||
}
|
||||
|
||||
@Test fun theRequestAsksForEverythingTheRuleChecks() {
|
||||
val requests = mutableListOf<EmbyRequest>()
|
||||
findSuggestions(EmbyTransport { requests += it; EmbyReply(200, JSONObject().put("Items", JSONArray()).toString()) }, user, { "t" }, listOf(rule), emptySet(), emptySet())
|
||||
listOf("ProductionYear", "OfficialRating", "CommunityRating", "Genres", "MediaSources").forEach { assertTrue(requests.single().path.contains(it)) }
|
||||
}
|
||||
|
||||
@Test fun familyFilmsShortsAndBlockbustersAreLeftOut() {
|
||||
val strict = rule.copy(excludeGenres = setOf("Family", "Animation"), minMinutes = 70, maxRating = 7.9f)
|
||||
val rows = arrayOf(row("fits", "Fits", listOf("Horror", "Comedy")),
|
||||
row("family", "Family", listOf("Horror", "Comedy", "Family")),
|
||||
row("cartoon", "Cartoon", listOf("Horror", "Comedy", "Animation")),
|
||||
row("big", "Blockbuster", listOf("Horror", "Comedy"), rating = 8.6),
|
||||
row("short", "Short", listOf("Horror", "Comedy")).put("RunTimeTicks", 12_000_000_000L))
|
||||
assertEquals(listOf("fits"), findSuggestions(reply(*rows), user, { "t" }, listOf(strict), emptySet(), emptySet()).suggestions.map { it.id })
|
||||
}
|
||||
|
||||
@Test fun vortexOnlyTakesExactTitles() {
|
||||
assertTrue(SmartChannels.first { it.number == 103 }.exactTitles)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user