feat: add bulubulu Android TV client v0.1.0-alpha

Implement official QR login with encrypted sessions, recommendation/movie/bangumi tabs, TV focus navigation and Media3 playback controls. Include Gradle wrapper, preview tooling, privacy protections, tests and documented alpha validation limits.
This commit is contained in:
loveuer committed 2026-11-03 22:57:04 +08:00
commit 52c840661b
52 files changed
+3766

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
# Architecture
The application has one Android app module and no backend service.
- `MainActivity` renders Compose, collects lifecycle-aware state and coordinates overlay focus restoration.
- `AppViewModel` owns feed pagination/cache, cancellable detail/playback requests, visible-screen QR polling and serialized account transitions.
- `AuthRepository` uses the official web QR flow with an isolated in-memory attempt. Only a verified active attempt can atomically replace the durable account session.
- `BiliHttpClient` validates official HTTPS API destinations, scopes cookies per network hop, bounds response sizes and propagates coroutine cancellation to OkHttp calls.
- `SessionStore` encrypts cookies with an Android Keystore AES-GCM key and writes an atomic file in `noBackupFilesDir`.
- `ContentRepository` retrieves official catalogue/details/playback responses; `WbiSigner` caches official signing material; pure `ContentJson` parsing separates format and entitlement checks from transport.
- `BulubuluHome`, dialogs and `TvAction` own TV layout/focus. Home stays composed beneath overlays, with focus/clicks disabled while inactive.
- `PlayerScreen` creates and releases Media3 with the composable lifecycle, merges separate AVC/AAC tracks and handles D-pad/media keys. CDN requests never receive account cookies.
There is no analytics, self-update service, local media scanning or private server. Login credentials and signed playback URLs must never appear in application logs or raw error messages. Account entitlements and region/DRM restrictions remain server-controlled. Tests use fake sessions in isolated storage and do not require a real account.
+12
View File
@@ -0,0 +1,12 @@
# 登录与会话实现说明
- 二维码由官方 `passport.bilibili.com/x/passport-login/web/qrcode/generate` 获取,在电视本地用 ZXing 绘制;不通过第三方生成图片。
- 手机哔哩哔哩扫码后由官方接口轮询确认:86101 等待扫码、86090 等待手机确认、86038 过期、0 成功。
- 成功响应中的官方 `Set-Cookie` 只进入该次扫码独立的内存会话,通过官方 `/x/web-interface/nav` 验证用户后,仅在扫码仍有效且前台协程未取消时原子提交到持久会话。关闭/暂停二维码会丢弃待确认的会话,避免迟到响应在后台悄悄登录。不会访问 poll JSON 返回的跨站同步 URL,不收集密码,也不向第三方传递 Cookie。
- 会话 Cookie 经 Android Keystore 内 AES-GCM 密钥加密,写入 `noBackupFilesDir/session.enc`,原子替换;密钥不可导出。损坏的存储或丢失的 Keystore 密钥导致退出登录,不降级为明文。
- HTTP 层每一跳重新计算 Cookie,严格遵守域名、路径、有效期,并且仅向 HTTPS 的 `bilibili.com` 及其子域发送。图片/CDN、第三方和 HTTP 不会收到会话 Cookie。
- 退出登录先立即删除本地会话,再用隔离的旧会话尽力调用官方注销接口。该请求迟到也不会删除之后的新登录。Cookie 代次保护还可避免旧网络响应覆盖已验证的新账号。
- 只有官方明确返回未登录时清理失效凭据。网络失败、HTTP 412 风控和服务器错误不会触发删除登录状态。
- 没有统计 SDK、崩溃上传、口令输入、刷新令牌上传或自动升级器。没有实现 Cookie 自动续期;失效后重新扫码。
验证范围:官方匿名 nav 和 QR 生成接口已成功做只读探测。未使用用户账号完成扫码,也未在电视上安装。单元测试覆盖 Cookie 域名/路径/HTTPS/过期/替换、退出登录竞态,以及 JSON API URL 限制。Keystore 加密需要真机或 Android 模拟器验证,普通 JVM 单元测试不能代替。
+33
View File
@@ -0,0 +1,33 @@
# 内容接口与播放范围
本客户端的内容请求仅使用 B 站官方 HTTPS Web API,沿用扫码登录获得的 Cookie,不访问作者自建解析服务,不添加统计或自动更新服务。
## 当前路径
- 推荐:`/x/web-interface/wbi/index/top/feed/rcmd`。WBI 公共签名信息来自 `/x/web-interface/nav`,缓存最多六小时,签名失效时刷新一次。登录后由服务端决定推荐内容;未登录时仍可浏览。推荐接口返回特定风控错误时,降级到官方 `/x/web-interface/popular`,并不改变内容权限。
- 电影和番剧:`/pgc/season/index/result`,分别使用 `season_type=2` 和 `season_type=1`,按播放量排序并支持分页。卡片保留会员等权益标签。
- 投稿详情/分 P:`/x/web-interface/view`。
- 电影/番剧详情与选集:`/pgc/view/web/season`,只展示正片集数,不把额外花絮自动加入播放列表。
- 投稿播放:`/x/player/wbi/playurl`。
- 电影/番剧播放:`/pgc/player/web/playurl`。
播放请求按普通 Web 客户端获取服务端允许的视频流,优先选择不高于常规 1080P 的 H.264 与 AAC,适合已知的 32 位 ARM Android 11 电视。清晰度由实际返回的轨道决定,登录和会员权益仍以 B 站接口结果为准。HTTP 图片/CDN链接升级到 HTTPS。
## 明确处理的限制
- 不绕过登录、会员、购买、区域、付费或 DRM 检查。
- `is_preview=1` 的会员试看不会被当作完整电影播放,会提示确认登录和账号权限。
- DRM 流暂不支持,并返回明确说明。
- 支持 DASH 的分离视频/音轨,以及单个 progressive 文件;老式多段 progressive 流会明确提示不支持,不会只播第一段。
- 当前没有弹幕、离线下载、评论、投币或自建视频代理。
- 没有可复用的用户登录会话,因此“登录后推荐”和付费内容完整播放尚需用户以后在设备上验证。代码和公开接口正常响应不能替代电视遥控器及解码实测。
## 2026-11-03 电脑侧只读探测
使用浏览器 User-Agent 和 `Referer: https://www.bilibili.com/`,实际获得了匿名推荐、电影、番剧、投稿分 P、剧集选集的正常响应,UGC 播放接口返回 H.264 + AAC DASH;会员电影接口返回带 `is_preview=1` 的试看,因此客户端正确拒绝把它作为完整片源。
公开接口随 B 站更新可能变化。风控、账号权限、地域或网络错误会向界面返回,不能承诺所有内容都能播放。
## 单元测试
WBI 测试覆盖固定签名向量、Unicode/空格/保留字符编码、输入不变性和旧签名替换。解析测试覆盖大整数 ID、广告/非视频卡片过滤、分 P、剧集、H.264/AAC 选择、实际清晰度、会员试看/DRM拒绝、旧多段流拒绝和 PGC 的权限错误。
+19
View File
@@ -0,0 +1,19 @@
# TV interface and controls
The first build uses an ink / warm-white / soft-pink palette: background `#0C1017`, panel `#181F29`, text `#F5F1ED`, secondary text `#9DAAB9`, accent `#FFA5B9`. Pink marks selection and focus; normal cards use dark surfaces. All shapes are authored in Compose and no marketing artwork is bundled.
At a typical 960 × 540 dp TV viewport, the home screen has 38 dp horizontal and 24 dp vertical safe insets, a 44 dp tab/action row, a 21 sp section heading, and a four-column recommendation grid and five-column portrait grid with 18 dp gaps. Recommendation thumbnails are 16:9; movie/bangumi covers use a 0.72 portrait ratio. Focused cards gain a 3 dp border and a 1.025 scale. Buttons and episode items have at least 44 dp height. Account status stays in a top-right capsule. Loading, empty, error and pagination states use the same layout and do not insert a fake catalogue.
## Remote
- Home: direction keys move among tabs, cards, refresh, account and load more. Confirm selects a tab or opens video details. Back from the grid returns focus to the selected tab. Android's normal back handling applies from the header.
- Details: first episode receives focus after loading. Confirm starts playback. Multi-part videos and series have an episode grid. Back closes the dialog.
- Login: QR code is generated locally with ZXing, not uploaded to a QR service. Refresh and close are D-pad targets. Closing cancels the parent-owned poll task. No password input is present.
- Player: confirm or play/pause toggles playback; left/right seek ten seconds, with long press throttled to one step per 250 ms. Up/down display controls. Back exits playback directly. Both key-down and key-up are consumed so Android PlayerView cannot apply the same event twice. Controls remain visible when paused/end/error and hide after four seconds during playback.
- App backgrounding pauses the player; foregrounding resumes only if it was previously playing. Leaving the player releases Media3 and screen-on state.
The player requests signed CDN URLs with a Bilibili Referer and browser User-Agent, without account cookies. It merges separate AVC/AAC fMP4 tracks through Media3, can use official backup CDN URLs after connection failure, and hides raw decoder/network exceptions that might include signed URLs. Actual decoder/remote behavior still needs testing on the target TV.
## Visual review
Prefer an emulator screenshot of the real Compose UI. If an HTML preview is used before an emulator is available, label it as a layout preview, use the dimensions/palette above and real fetched API data, and do not treat it as runtime verification. Community screenshots from unrelated clients are not assets for this app.
+32
View File
@@ -0,0 +1,32 @@
# v0.1.0-alpha 验证记录
日期:2026-11-03。
## 已验证
- 使用 Gradle 8.9、JDK 17、Android SDK 35 构建开发版 APK。
- JVM 单元测试:30 项通过,0 失败。覆盖 Cookie 域名/路径/HTTPS/有效期隔离、账号切换与退出后的迟到响应、WBI 签名、内容解析、播放格式与权限判断、遥控器跳转边界、错误提示不泄露原始网络地址。
- Android 11 ARM64 模拟器:5 项设备测试通过,0 失败。其中 2 项测试验证实际 Android Keystore 加密存储的重建读取与密文篡改后拒绝恢复;3 项测试验证方向键切换页签、选集和覆盖层焦点隔离。
- Android Lint:无错误;保留依赖升级建议、固定横屏、targetSdk 等警告。依赖版本已固定,未宣称完成所有第三方依赖的漏洞审计。
- 匿名官方接口:推荐、电影目录、番剧目录、投稿详情、剧集选集、H.264/AAC DASH 地址、二维码生成和等待扫码状态均曾返回有效数据。
- 真实 Compose 应用已在电脑模拟器运行,已显示远程获取的推荐、电影封面和文本。`screenshots/recommendation.png` 是运行截图,不是网页效果图或预置目录。
- 用户已在电脑上查看模拟器界面并认可作为首个 alpha 版本。
## 仍待验证
- 用户手机扫码确认后,真实账号登录、重启恢复、失效与退出的端到端行为。
- 登录后的个性化推荐与账号实际有权观看的电影/番剧。
- 持续播放、音画同步、暂停/跳转、后台恢复等完整端到端播放表现。已验证解析和控制逻辑,不等于已验证完整播放。
- ARM32 雷鸟/TCL 电视的真实解码器、遥控器、焦点和分辨率适配。
- 网络变化、官方接口或风控策略变化下的长期稳定性。
本次没有连接或安装到用户电视;设备测试固定使用 `emulator-5580`。
## 复现
```sh
./gradlew assembleDebug testDebugUnitTest lintDebug
ANDROID_SERIAL=emulator-5580 ./gradlew connectedDebugAndroidTest
```
设备测试需要已启动的模拟器。测试使用独立存储目录和假测试会话,不需要用户账号;Gradle 的 connected 测试任务可能在结束后移除测试安装的 APK。如需继续查看,运行 `./scripts/preview.sh` 重新部署到预览模拟器。
Binary file not shown.

After

Width:  |  Height:  |  Size: 1015 KiB