Prefer English sound and leave out foreign-only episodes; record Paul's channel ideas (0.62.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,14 @@ internal fun sourceVideoCodec(source: org.json.JSONObject): String? {
|
||||
.firstOrNull { it.optString("Type") == "Video" }?.optString("Codec")?.takeIf { it.isNotBlank() }
|
||||
}
|
||||
|
||||
/** False only when a source's sound is all tagged as other languages. Untagged sound gets the benefit of the doubt. */
|
||||
internal fun hasEnglishAudio(source: org.json.JSONObject): Boolean {
|
||||
val streams = source.optJSONArray("MediaStreams") ?: return true
|
||||
val tags = (0 until minOf(streams.length(), 32)).mapNotNull { streams.optJSONObject(it) }.filter { it.optString("Type") == "Audio" }
|
||||
.map { it.optString("Language").trim().lowercase(java.util.Locale.ROOT) }
|
||||
return tags.isEmpty() || tags.any { it.isEmpty() || it == "und" || it == "en" || it == "eng" || it == "english" }
|
||||
}
|
||||
|
||||
/** The decoders this box actually has, read once. */
|
||||
internal object BoxDecoders {
|
||||
private val types by lazy {
|
||||
|
||||
@@ -17,7 +17,9 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
||||
/** Only the exact title counts, for channels whose short names could match something unrelated. */
|
||||
val exactTitles: Boolean = false,
|
||||
val dayParts: List<DayPart> = emptyList(),
|
||||
val suggestionRules: List<SuggestionRule> = emptyList()) {
|
||||
val suggestionRules: List<SuggestionRule> = emptyList(),
|
||||
/** Leave out episodes with no English sound. Off where subtitled shows belong, like Vortex's anime. */
|
||||
val englishAudio: Boolean = true) {
|
||||
/** Changes when the list does, so the episode cache is read again. What's already committed stays. */
|
||||
val signature get() = "$CHANNEL_POOL_VERSION#${searches.joinToString("|")}#$seriesCount"
|
||||
}
|
||||
@@ -44,7 +46,7 @@ internal val SmartChannels = listOf(
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Science Fiction", "Action"), 1975..2005, 6.5f, setOf("NC-17", "X"), 40, NotCultCinema + "Adventure", 70, 7.9f),
|
||||
SuggestionRule("day", "Daytime", "Movie", listOf("Thriller", "Mystery"), 1975..2005, 6.5f, setOf("NC-17", "X"), 30, NotCultCinema + "Science Fiction", 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,
|
||||
ChannelProgramming(103, "Vortex", VortexDaytime + VortexEvening, seriesCount = 40, finishTogether = true, exactTitles = true, englishAudio = false,
|
||||
dayParts = listOf(DayPart(20, 22, group = "movie", days = setOf(java.time.DayOfWeek.FRIDAY, java.time.DayOfWeek.SATURDAY)),
|
||||
DayPart(6, 18, VortexDaytime, group = "day"), DayPart(18, 6, VortexEvening, group = "night")),
|
||||
suggestionRules = listOf(
|
||||
@@ -99,7 +101,7 @@ internal data class ChannelPlan(val entries: List<ScheduleEntry>, val tail: Sche
|
||||
}
|
||||
|
||||
/** Bump when the way pools are read changes, so each channel reads its once again. */
|
||||
private const val CHANNEL_POOL_VERSION = 3
|
||||
private const val CHANNEL_POOL_VERSION = 4
|
||||
|
||||
internal const val SCHEDULE_AHEAD_MS = 7 * 24 * 60 * 60_000L
|
||||
internal const val SCHEDULE_TOP_UP_MS = 6 * 24 * 60 * 60_000L
|
||||
|
||||
@@ -66,7 +66,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.61.0\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.62.0\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -65,6 +65,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
|
||||
.setSeekBackIncrementMs(10_000).setSeekForwardIncrementMs(10_000).build().apply {
|
||||
setMediaItem(channelMediaItem(plan))
|
||||
if (scheduled != null) seekTo(scheduled.programme.offsetAt(scheduled.nowMs()))
|
||||
trackSelectionParameters = trackSelectionParameters.buildUpon().setPreferredAudioLanguage("en").build()
|
||||
prepare(); playWhenReady = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
|
||||
val match = bestSeriesMatch(search, if (programming.exactTitles) candidates.filter { seriesKey(it.title) == seriesKey(search) } else candidates) ?: continue
|
||||
// A second copy of a show in the library counts as the same show.
|
||||
if (pool.any { it.id == match.id || seriesKey(it.title) == seriesKey(match.title) }) continue
|
||||
val whole = readWholeSeries(transport, userId, ::currentToken, match, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode)
|
||||
val whole = readWholeSeries(transport, userId, ::currentToken, match, checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio)
|
||||
if (whole.episodes.isNotEmpty()) pool += whole
|
||||
}
|
||||
for (accepted in choices.accepted) {
|
||||
@@ -218,7 +218,7 @@ internal class EmbySampleSession(private val transport: EmbyTransport, private v
|
||||
val duration = accepted.durationMs ?: continue
|
||||
pool += PoolSeries(accepted.id, accepted.title, listOf(PoolEpisode(accepted.id, source, EpisodeMark(1, 1), accepted.title, duration)), accepted.group)
|
||||
} else {
|
||||
val whole = readWholeSeries(transport, userId, ::currentToken, SeriesCandidate(accepted.id, accepted.title, accepted.year, ""), checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode)
|
||||
val whole = readWholeSeries(transport, userId, ::currentToken, SeriesCandidate(accepted.id, accepted.title, accepted.year, ""), checkActive, onRequest = { requests++ }, canDecode = BoxDecoders::canDecode, englishAudio = programming.englishAudio)
|
||||
if (whole.episodes.isNotEmpty()) pool += whole.copy(group = accepted.group)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ internal const val WHOLE_SERIES_TIMEOUT_MS = 60_000
|
||||
|
||||
/** A whole series, read in bounded pages one at a time: regular numbered episodes with a playable source, once each, in order. */
|
||||
internal fun readWholeSeries(transport: EmbyTransport, userId: String, token: () -> String, series: SeriesCandidate,
|
||||
checkActive: () -> Unit = {}, onRequest: () -> Unit = {}, canDecode: (String) -> Boolean = { true }): PoolSeries {
|
||||
checkActive: () -> Unit = {}, onRequest: () -> Unit = {}, canDecode: (String) -> Boolean = { true }, englishAudio: Boolean = false): PoolSeries {
|
||||
require(EmbyClient.validId(userId) && EmbyClient.validId(series.id))
|
||||
val episodes = mutableListOf<PoolEpisode>()
|
||||
var start = 0
|
||||
@@ -68,21 +68,21 @@ internal fun readWholeSeries(transport: EmbyTransport, userId: String, token: ()
|
||||
EmbyClient.expectSuccess(reply.status, false)
|
||||
val body = EmbyClient.parse(reply.body)
|
||||
val rows = body.optJSONArray("Items") ?: throw EmbyCheckException("The provider did not return the episode list.")
|
||||
(0 until rows.length()).forEach { index -> rows.optJSONObject(index)?.let { poolEpisode(it, canDecode) }?.let { episodes += it } }
|
||||
(0 until rows.length()).forEach { index -> rows.optJSONObject(index)?.let { poolEpisode(it, canDecode, englishAudio) }?.let { episodes += it } }
|
||||
start += rows.length()
|
||||
if (rows.length() == 0 || start >= body.optInt("TotalRecordCount", 0)) break
|
||||
}
|
||||
return PoolSeries(series.id, series.title, episodes.sortedBy { it.mark }.distinctBy { it.mark })
|
||||
}
|
||||
|
||||
private fun poolEpisode(item: org.json.JSONObject, canDecode: (String) -> Boolean): PoolEpisode? {
|
||||
private fun poolEpisode(item: org.json.JSONObject, canDecode: (String) -> Boolean, englishAudio: Boolean): PoolEpisode? {
|
||||
val id = item.optString("Id")
|
||||
val season = item.optInt("ParentIndexNumber", -1)
|
||||
val number = item.optInt("IndexNumber", -1)
|
||||
if (item.optString("Type") != "Episode" || !EmbyClient.validId(id) || season < 1 || number < 1) return null
|
||||
val sources = item.optJSONArray("MediaSources") ?: return null
|
||||
val source = (0 until minOf(sources.length(), 20)).mapNotNull { sources.optJSONObject(it) }
|
||||
.firstOrNull { supportedDirectContainer(it.optString("Container")) != null && EmbyClient.validId(it.optString("Id")) && sourceVideoCodec(it)?.let(canDecode) != false } ?: return null
|
||||
.firstOrNull { supportedDirectContainer(it.optString("Container")) != null && EmbyClient.validId(it.optString("Id")) && sourceVideoCodec(it)?.let(canDecode) != false && (!englishAudio || hasEnglishAudio(it)) } ?: return null
|
||||
val ticks = source.optLong("RunTimeTicks", 0).takeIf { it > 0 } ?: item.optLong("RunTimeTicks", 0)
|
||||
val duration = (ticks / 10_000).takeIf { it in 1_000..SampleChannel.MAX_DURATION_MS } ?: return null
|
||||
return PoolEpisode(id, source.getString("Id"), EpisodeMark(season, number), EmbyClient.clean(item.optString("Name"), 160).ifBlank { "Untitled episode" }, duration)
|
||||
|
||||
@@ -121,6 +121,7 @@ private fun GuideLivePlayer(session: EmbySampleSession, plan: EmbyPlaybackPlan,
|
||||
ExoPlayer.Builder(context).setMediaSourceFactory(DefaultMediaSourceFactory(factory)).build().apply {
|
||||
setMediaItem(channelMediaItem(plan))
|
||||
seekTo(programme.offsetAt(System.currentTimeMillis()))
|
||||
trackSelectionParameters = trackSelectionParameters.buildUpon().setPreferredAudioLanguage("en").build()
|
||||
prepare(); playWhenReady = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.61.0")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.62.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()) {
|
||||
|
||||
Reference in New Issue
Block a user