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
92 changes: 70 additions & 22 deletions .github/workflows/discord-app-release.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,92 @@
# For app repos (TypeType-Android, TypeType-IOS, TypeType-TV, TypeType-tvOS).
# Pre-releases (-beta.N, -rc.N) go to #🧪・releases-rc, stable releases go to #🚀・releases-main,
# with the release notes. Needs the secrets DISCORD_WEBHOOK_RC and DISCORD_WEBHOOK_MAIN.
#
# A release published by hand fires `release`. A release created by a build workflow with GITHUB_TOKEN never fires
# `release` (GitHub does not start workflows from GITHUB_TOKEN events), so `workflow_run` catches those: when a build
# that ran a release/publish job succeeds, the releases whose tag points at the commit it built are posted.
# `workflow_dispatch` posts one tag by hand.
name: Discord release notify

on:
release:
types: [published]
workflow_run:
workflows: ["iOS", "Android", "Android Beta", "Release"]
types: [completed]
workflow_dispatch:
inputs:
tag:
description: Release tag to post
required: true

permissions:
contents: read
actions: read

jobs:
notify:
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Find the releases to post
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
INPUT_TAG: ${{ inputs.tag }}
RUN_ID: ${{ github.event.workflow_run.id }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
: > tags.txt
case "$EVENT" in
release) echo "$RELEASE_TAG" > tags.txt ;;
workflow_dispatch) echo "$INPUT_TAG" > tags.txt ;;
workflow_run)
ran=$(gh api "repos/$REPO/actions/runs/$RUN_ID/jobs" \
--jq '[.jobs[] | select((.name | test("release|publish"; "i")) and .conclusion == "success")] | length')
[ "$ran" -gt 0 ] || { echo "no release job ran"; exit 0; }
for tag in $(gh api "repos/$REPO/releases?per_page=10" \
--jq '.[] | select(.draft == false and .author.login == "github-actions[bot]") | .tag_name'); do
sha=$(gh api "repos/$REPO/commits/$tag" --jq .sha)
[ "$sha" = "$HEAD_SHA" ] && echo "$tag" >> tags.txt
done
;;
esac
cat tags.txt

- name: Post to Discord
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
WEBHOOK_RC: ${{ secrets.DISCORD_WEBHOOK_RC }}
WEBHOOK_MAIN: ${{ secrets.DISCORD_WEBHOOK_MAIN }}
PRERELEASE: ${{ github.event.release.prerelease }}
TAG: ${{ github.event.release.tag_name }}
RNAME: ${{ github.event.release.name }}
URL: ${{ github.event.release.html_url }}
BODY: ${{ github.event.release.body }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
if [ "$PRERELEASE" = "true" ]; then
WEBHOOK="$WEBHOOK_RC"; BOT="The Lab TV"; EMOJI="🧪"; COLOR=15105570; INTRO="Beta build, might break, have fun (・ω・)"
else
WEBHOOK="$WEBHOOK_MAIN"; BOT="Rocket TV"; EMOJI="🚀"; COLOR=5763719; INTRO="New release (。•̀ᴗ-)✧"
fi
[ -n "$WEBHOOK" ] || { echo "webhook secret not set"; exit 0; }
TITLE="${EMOJI} ${RNAME:-${REPO#*/} ${TAG}}"
jq -n \
--arg title "$TITLE" \
--arg url "$URL" \
--arg desc "$(printf '%s\n\n%s' "$INTRO" "${BODY:-}" | cut -c1-3900)" \
--argjson color "$COLOR" \
--arg bot "$BOT" \
'{username: $bot, embeds: [{title: $title, url: $url, description: $desc, color: $color}]}' \
> payload.json
curl -fsS -H "Content-Type: application/json" -d @payload.json "$WEBHOOK"
while read -r TAG; do
[ -n "$TAG" ] || continue
gh api "repos/$REPO/releases/tags/$TAG" > release.json
PRERELEASE=$(jq -r .prerelease release.json)
RNAME=$(jq -r '.name // ""' release.json)
URL=$(jq -r .html_url release.json)
BODY=$(jq -r '.body // ""' release.json)
if [ "$PRERELEASE" = "true" ]; then
WEBHOOK="$WEBHOOK_RC"; BOT="The Lab TV"; EMOJI="🧪"; COLOR=15105570; INTRO="Beta build, might break, have fun (・ω・)"
else
WEBHOOK="$WEBHOOK_MAIN"; BOT="Rocket TV"; EMOJI="🚀"; COLOR=5763719; INTRO="New release (。•̀ᴗ-)✧"
fi
[ -n "$WEBHOOK" ] || { echo "webhook secret not set"; exit 0; }
TITLE="${EMOJI} ${RNAME:-${REPO#*/} ${TAG}}"
jq -n \
--arg title "$TITLE" \
--arg url "$URL" \
--arg desc "$(printf '%s\n\n%s' "$INTRO" "${BODY:-}" | cut -c1-3900)" \
--argjson color "$COLOR" \
--arg bot "$BOT" \
'{username: $bot, embeds: [{title: $title, url: $url, description: $desc, color: $color}]}' \
> payload.json
curl -fsS -H "Content-Type: application/json" -d @payload.json "$WEBHOOK"
echo "posted $TAG"
done < tags.txt
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

// The release workflow reads this line: "x.y.z-beta.n" is published from the beta branch, "x.y.z" from main.
val appVersion = "0.9.0-beta.3"
val appVersion = "0.10.0-beta.1"

// The version code follows from the name, so each release installs over the one before, and a beta sits under the
// stable release that ends it: 0.3.0-beta.2 is 30002 and 0.3.0 is 30099.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PlayerControlDescriptionsTest {

private val video = Video(
"https://v.example/1", "A title", Channel("c", "Channel", "", "1M"),
durationSeconds = 120, views = "1 view", age = "today", genre = "", description = "",
durationSeconds = 120, genre = "", description = "",
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PlayerControlsOptionsTest {
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val video = Video(
"https://v.example/1", "A title", Channel("c", "Channel", "", "1M"),
durationSeconds = 120, views = "1 view", age = "today", genre = "", description = "",
durationSeconds = 120, genre = "", description = "",
)
private val actions = PlayerControlActions({}, {}, {}, {}, {}, {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PlayerPanelsTest {

private val video = Video(
"https://v.example/1", "A title", Channel("c", "Channel", "", "1M"),
durationSeconds = 600, views = "1 view", age = "today", genre = "",
durationSeconds = 600, genre = "",
description = "First paragraph.\n\nSecond paragraph.", chapters = chapters,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class QualityAndRepliesPanelsTest {
}

private fun comment(id: String, replies: Int = 0, page: String? = null) =
Comment(id, "author$id", null, "text of $id", "", "1 day ago", false, false, replies, page)
Comment(id, "author$id", null, "text of $id", "", 0L, "1 day ago", false, false, replies, page)

private val repository: ContentRepository = object : ContentRepository by MockContentRepository(0) {
override suspend fun comments(videoUrl: String, page: String?) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ScreenAccessibilityTest {

private val video = Video(
"https://v.example/1", "A title", Channel("c", "Channel", "", "1M"),
durationSeconds = 120, views = "1 view", age = "today", genre = "", description = "",
durationSeconds = 120, genre = "", description = "",
)

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UpNextCardTest {

private val next = Video(
"https://v.example/2", "The next video", Channel("c", "Some channel", "", "1M"),
durationSeconds = 200, views = "", age = "", genre = "", description = "",
durationSeconds = 200, genre = "", description = "",
)

@Before
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/video/typetype/tv/AppContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import video.typetype.tv.playback.CodecSupport
import video.typetype.tv.playback.DecoderFailures
import video.typetype.tv.playback.DeviceCodecSupport
import video.typetype.tv.playback.LearnedCodecSupport
import video.typetype.tv.playback.MeasuredSpeed
import video.typetype.tv.playback.MediaBandwidth
import video.typetype.tv.playback.mimeType
import video.typetype.tv.playback.PlaybackProvider
import video.typetype.tv.playback.RoutingPlaybackProvider
Expand Down Expand Up @@ -128,7 +130,11 @@ class AppContainer(context: Context) {
access,
decoderFailures,
preference = { codecSettings.current.value.mimeType() },
) { connectivity.online.value }
online = { connectivity.online.value },
speed = bandwidth,
)

private val bandwidth: MeasuredSpeed by lazy { MediaBandwidth(appContext) }

@OptIn(UnstableApi::class)
@androidx.annotation.OptIn(UnstableApi::class)
Expand Down
4 changes: 3 additions & 1 deletion core/data/src/main/java/video/typetype/tv/data/Comment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ data class Comment(
val avatarUrl: String?,
val text: String,
val likes: String,
val published: String,
val publishedAtMillis: Long = 0L,
// The server's own wording, kept for comments it gives no date for.
val publishedText: String = "",
val pinned: Boolean,
val hearted: Boolean,
val replies: Int,
Expand Down
4 changes: 2 additions & 2 deletions core/data/src/main/java/video/typetype/tv/data/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ data class Video(
val title: String,
val channel: Channel,
val durationSeconds: Int,
val views: String,
val age: String,
val views: ViewCount = ViewCount.Unknown,
val publishedAtMillis: Long = 0L,
val genre: String,
val description: String,
val resumeFraction: Float? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class PublicPlaylist(
val uploader: String,
val count: Long,
val thumbnailUrl: String?,
val audience: ViewCount? = null,
)

data class PublicPlaylistPage(
Expand Down
2 changes: 1 addition & 1 deletion core/data/src/main/java/video/typetype/tv/data/Twitch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class TwitchCategory(
val name: String,
val slug: String,
val boxArtUrl: String?,
val viewers: String,
val viewers: Long? = null,
)

data class TwitchPage<T>(val items: List<T>, val cursor: String?)
Expand Down
15 changes: 15 additions & 0 deletions core/data/src/main/java/video/typetype/tv/data/VideoTier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package video.typetype.tv.data

// The quality a picture is named after, as YouTube names it: a wide film in 3840x1608 is 2160p, 2048x858 is 1080p
// and a vertical 1080x1920 is 1080p. Raw heights would show a wide 4K film as 1608p and let a 1080p cap pick the
// 1440p picture.
object VideoTier {
private val TIERS = listOf(144, 240, 360, 480, 720, 1080, 1440, 2160, 4320)

fun of(width: Int, height: Int): Int {
if (width <= 0 || height <= 0) return height.coerceAtLeast(0)
val wide = width.toLong() * 9L > height.toLong() * 16L
val lines = if (wide) width * 9 / 16 else minOf(width, height)
return TIERS.minBy { kotlin.math.abs(it - lines) }
}
}
11 changes: 11 additions & 0 deletions core/data/src/main/java/video/typetype/tv/data/ViewCount.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package video.typetype.tv.data

// A view count kept as a number, so each screen words it in the viewer's language. On a live stream the server's
// count is the audience connected right now.
data class ViewCount(val count: Long, val watchingNow: Boolean = false) {
val known: Boolean get() = count >= 0L

companion object {
val Unknown = ViewCount(-1L)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package video.typetype.tv.data.remote

import video.typetype.tv.data.WatchedRule
import kotlin.math.roundToLong

object Formatters {
fun compactCount(count: Long): String {
Expand All @@ -13,32 +14,6 @@ object Formatters {
}
}

fun views(count: Long): String {
val compact = compactCount(count)
return if (compact.isEmpty()) "" else "$compact views"
}

// On a live stream the server's view count is the audience connected right now.
fun audience(count: Long, live: Boolean): String {
if (!live) return views(count)
val compact = compactCount(count)
return if (compact.isEmpty()) "" else "$compact watching"
}

fun age(nowMillis: Long, thenMillis: Long): String {
if (thenMillis <= 0L || thenMillis > nowMillis) return ""
val minutes = (nowMillis - thenMillis) / 60_000L
return when {
minutes < 1L -> "just now"
minutes < 60L -> unit(minutes, "minute")
minutes < 60L * 24L -> unit(minutes / 60L, "hour")
minutes < 60L * 24L * 7L -> unit(minutes / (60L * 24L), "day")
minutes < 60L * 24L * 30L -> unit(minutes / (60L * 24L * 7L), "week")
minutes < 60L * 24L * 365L -> unit(minutes / (60L * 24L * 30L), "month")
else -> unit(minutes / (60L * 24L * 365L), "year")
}
}

fun resumeFraction(progressSeconds: Long, durationSeconds: Long, watchedThresholdPercent: Int = 0): Float? {
if (durationSeconds <= 0L || progressSeconds <= 0L) return null
if (WatchedRule.isWatched(progressSeconds * 1_000L, durationSeconds, watchedThresholdPercent)) return null
Expand All @@ -47,12 +22,9 @@ object Formatters {

private fun scaled(count: Long, divisor: Double, suffix: String): String {
val value = count / divisor
val text = if (value >= 100.0) "%.0f".format(value) else "%.1f".format(value).removeSuffix(".0")
return text + suffix
val whole = value >= 100.0 || (value * 10.0).roundToLong() % 10L == 0L
return (if (whole) "%.0f" else "%.1f").format(value) + suffix
}

private fun unit(amount: Long, name: String): String =
if (amount == 1L) "1 $name ago" else "$amount ${name}s ago"

private const val MIN_RESUME = 0.02f
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal class HomeLaterShelves(
private val filter: ContentFilter,
private val branding: DeArrowBranding,
private val texts: TextProvider,
private val clock: () -> Long,
) {
// The rows for these services, in their place on the home; `shown` are already on the first screen.
fun ids(services: Set<ContentSource>, primary: ContentSource, hideShorts: Boolean, shown: Set<String>): List<String> {
Expand All @@ -32,25 +31,24 @@ internal class HomeLaterShelves(
}

suspend fun load(id: String, services: Set<ContentSource>): Shelf? {
val now = clock()
val blocked = filter.blocked()
val videos = when (id) {
WATCH_LATER -> api.watchLater().mapNotNull { it.toVideo(now, resume = false) }
FAVORITES -> api.favorites().mapNotNull { it.toVideo(now, resume = false) }
SHORTS -> api.shorts(SHELF_LIMIT).items.mapNotNull { it.toVideo(now, keepShorts = true) }
else -> remote(id, now) ?: return null
WATCH_LATER -> api.watchLater().mapNotNull { it.toVideo(resume = false) }
FAVORITES -> api.favorites().mapNotNull { it.toVideo(resume = false) }
SHORTS -> api.shorts(SHELF_LIMIT).items.mapNotNull { it.toVideo(keepShorts = true) }
else -> remote(id) ?: return null
}
val kept = blocked.filter(videos).filter { it.source in services }.take(SHELF_LIMIT)
if (kept.isEmpty()) return null
return Shelf(id, texts.text(titleRes(id) ?: return null), branding.apply(kept))
}

private suspend fun remote(id: String, now: Long): List<Video>? {
private suspend fun remote(id: String): List<Video>? {
ContentSource.extractors.firstOrNull { trendingId(it) == id }?.let { source ->
return api.trending(source).mapNotNull { it.toVideo(now) }
return api.trending(source).mapNotNull { it.toVideo() }
}
OTHER_SOURCES.firstOrNull { recommendedId(it) == id }?.let { source ->
return api.homeRecommendations(SHELF_LIMIT, source = source).items.mapNotNull { it.toVideo(now) }
return api.homeRecommendations(SHELF_LIMIT, source = source).items.mapNotNull { it.toVideo() }
}
return null
}
Expand Down
Loading