Repository navigation
perf: Bilibili images at shown size, adaptive NicoNico qualities, prewarm on focus, expired link refresh - #1
Merged
Conversation
…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
force-pushed
the
fix/bilibili-card-sized-images
branch
from
November 6, 2026 13:07
5729fc0 to
f2faea1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 fromwatch.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 reportsheight: 0,width: 0,bitrate: null,codec: null. Only the label ("720p") tells them apart.main, the realsm47010857response (4 qualities) collapses to 1 identity inallVideoSources, so one quality is kept, whichever the server lists first. The quality menu filtersheight > 0, so NicoNico had no quality choices; the quality chosen depended on the server's order.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.Changes (4 commits)
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/proxyreturns 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/proxylike web and Android. YouTube and other hosts are untouched.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. NoRESOLUTIONis invented without a width:ffprobeon the realsm9playlists shows a 4:3 480x360 stream, which a 16:9 guess would misdescribe.LivePlaybackPrewarmerruns.claimStreamRefreshfrom the web client).Verification
Done on a Linux host with Swift 6.0.3 (no Xcode available there):
sm9and a real 4-qualitysm47010857response are embedded as fixtures.LivePlaybackService+Selection.swiftran against a minimal stub of the service, soselectVideoandproviderHLSAlternatesran on the real data.maingave the "1 identity of 4" result above.sm9data parses inffprobeas two variants with an audio group, and both variants decode (h264 + aac, including the server's AES-128 keys).CI on
f2faea1(macOS runner): theiOSworkflow 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 adjustedseparateHLSpattern.Not verified, needs a device or the simulator:
Not in this PR
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.ytimg.com,ggpht.com) like web and Android; a separate decision (instance load, privacy).AI disclosure
Prepared with AI assistance (Claude). Real responses were fetched from the public instance; compiled by CI, not run on a device.