Skip to content

perf: Bilibili images at shown size, adaptive NicoNico qualities, prewarm on focus, expired link refresh - #1

Merged
Priveetee merged 9 commits into
mainfrom
fix/bilibili-card-sized-images
Nov 6, 2026
Merged

Priveetee merged 9 commits into
mainfrom
fix/bilibili-card-sized-images

Conversation

@Toastienergy

@Toastienergy Toastienergy commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Not a port of TypeType-Android#122. I read what the web client does for Bilibili and NicoNico (proxy.ts, nico-hls-manifest.ts, stream-refresh.ts, the card preflight) and compared it with the Apple TV code, using real responses from watch.typetype.video. That turned up problems the Android PR does not describe.

What was wrong (measured)

Real NicoNico responses (sm9, sm47010857, sm47009535, sm47010369, sm45174902, sm1715919): every quality reports height: 0, width: 0, bitrate: null, codec: null. Only the label ("720p") tells them apart.

  • Run against main, the real sm47010857 response (4 qualities) collapses to 1 identity in allVideoSources, so one quality is kept, whichever the server lists first. The quality menu filters height > 0, so NicoNico had no quality choices; the quality chosen depended on the server's order.
  • Nothing could switch quality while playing: the master playlist had one variant.
  • Bilibili avatars arrive as http://… (seen in /trending?service=5). The tvOS app only allows local networking in ATS, so those avatars could not load. //… covers resolved against the instance URL.
  • Apple TV never prepared a stream when a card got the focus (web does for Bilibili/NicoNico, iOS does on press).
  • A playback that failed on expired links went straight to a lower quality or an error.

Changes (4 commits)

  1. Images (LiveImageURLResolver): covers 672x378, or 1280x720 for the full-screen backdrop and player poster; avatars 240x240. Measured on a real cover: 223 KB → 33 KB / 68 KB; avatar 57 KB → 7.6 KB (the instance /proxy returns identical bytes). http/// → https, biliimg.com → i0.hdslb.com, addresses that already name a size stay as they are, Bilibili images go through the instance /proxy like web and Android. YouTube and other hosts are untouched.
  2. NicoNico qualities: quality from the label when the height is missing (effectiveHeight), used by the menu, HD badge, choice and recovery; every HLS playlist gets its own identity; the master playlist lists the lighter qualities after the chosen one with the web client's bandwidth estimates, so AVPlayer can switch down. A quality picked by hand still plays alone. No RESOLUTION is invented without a width: ffprobe on the real sm9 playlists shows a 4:3 480x360 stream, which a 16:9 guess would misdescribe.
  3. Prewarm on focus (tvOS): after 250 ms on a card (600 ms for YouTube, as on web) the existing LivePlaybackPrewarmer runs.
  4. Expired links: a provider playback failure on a stream loaded 10 minutes ago or more fetches it again once and resumes at the same position, before a lower quality is tried (claimStreamRefresh from the web client).

Verification

Done on a Linux host with Swift 6.0.3 (no Xcode available there):

  • The new and touched pure-Foundation sources compile and 31 XCTest cases pass (resolver, source models, HLS variants, refresh claim, video catalog) using the unchanged test files from this branch. A real sm9 and a real 4-quality sm47010857 response are embedded as fixtures. LivePlaybackService+Selection.swift ran against a minimal stub of the service, so selectVideo and providerHLSAlternates ran on the real data.
  • The same real response run against main gave the "1 identity of 4" result above.
  • A master playlist built from the real sm9 data parses in ffprobe as two variants with an audio group, and both variants decode (h264 + aac, including the server's AES-128 keys).

CI on f2faea1 (macOS runner): the iOS workflow passed, with the unit tests in the iOS simulator, the unsigned iOS build and the unsigned Apple TV (tvOS) build. That compiled everything the Linux run could not (LivePlaybackHTTPServer*, LivePlayerController*, TVVideoCard, TVShellView, the views) and ran the existing unit tests with the adjusted separateHLS pattern.

Not verified, needs a device or the simulator:

  • AVPlayer actually switching between the variants on a slow connection, the prewarm when the focus rests on a card, and the link refresh at a position were not exercised. No UI or playback test exists for them in this repo, and nobody ran the app on an Apple TV or in the tvOS simulator.

Not in this PR

  • Bilibili's "start light, then let the quality climb" and the seek behaviour (dash-bilibili-seek-buffer) are dash.js specific; on Apple the progressive Bilibili source is a single variant, so the same needs a master playlist for Bilibili too. Larger change, separate PR.
  • Proxying YouTube image hosts (ytimg.com, ggpht.com) like web and Android; a separate decision (instance load, privacy).
  • Android's Media3 MIME type fix does not apply to AVPlayer.

AI disclosure

Prepared with AI assistance (Claude). Real responses were fetched from the public instance; compiled by CI, not run on a device.

…e instance

Port of the image part of TypeType-Android#122 and of TypeType-Frontend cccc1e8, with the cases the web client covers:
- covers 672x378 (cards) or 1280x720 (full-screen backdrop and player poster), avatars 240x240; a real cover goes from 223 KB to 33/68 KB, an avatar from 57 KB to 7.6 KB
- http:// and // addresses become https:// (the server sends http avatars and ATS blocks them on tvOS)
- biliimg.com maps to i0.hdslb.com, addresses that already name a size stay as they are
- Bilibili images load through the instance /proxy like on web and Android
… them

Port of the NicoNico part of TypeType-Android#122 and of the web client's nico-hls-manifest, checked against real instance responses: NicoNico reports height 0, width 0, no bitrate and no codec for every quality, so only the label ("720p") says what a playlist is.
- the quality comes from the label when the height is missing (effectiveHeight); the menu, the HD badge, the choice and the fallback use it
- every HLS playlist gets its own identity: allVideoSources collapsed all four qualities of a real video into one
- the master playlist lists the lighter qualities next to the chosen one, with the web client's bandwidth estimates, so AVPlayer drops to one when the connection is slow; a quality picked by hand still plays alone
- no RESOLUTION is invented when the server sends no width (a real 4:3 playlist would be announced as 16:9)
The web client prepares a Bilibili or NicoNico stream while its card is hovered and iOS prewarms on press; Apple TV did neither, so every start paid the stream request. The focus has to rest 250 ms on a card (600 ms for YouTube, which opens a whole session, as on web) before the prewarm starts. The prewarmer already skips lives, the playing video and cards prewarmed in the last 50 s.
Port of TypeType-Frontend 5c4b78e: provider media links expire, so a playback that fails on a stream loaded ten minutes ago or more fetches it again once and resumes where it was, before a lower quality is tried or an error is shown.
@Toastienergy
Toastienergy force-pushed the fix/bilibili-card-sized-images branch from 5729fc0 to f2faea1 Compare November 6, 2026 13:07
@Toastienergy Toastienergy changed the title fix: request Bilibili covers and avatars at card size perf: Bilibili images at shown size, adaptive NicoNico qualities, prewarm on focus, expired link refresh Nov 6, 2026
@Priveetee
Priveetee merged commit d16b185 into main Nov 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants