Repository navigation
Decrypt KissKH's encrypted subtitle cues on Android TV and Apple TV - #40
Merged
professorDeveloper merged 2 commits intoNov 3, 2026
Merged
Conversation
KissKH's .txt1 subtitles are SRT files whose cue text lines are each AES-128-CBC ciphertext, so viewers saw base64 instead of captions. The backend now tags those tracks with a cipher; both players carry it from the media payload and open each cue text line after download, before parsing. A key that opens no line or an unknown algorithm fails the track instead of showing ciphertext.
…hat open few cues translateMedia rebuilt each subtitle from a fixed set of keys and dropped cipher, so on Android TV KissKH tracks still reached the player as base64. A wrong AES key still unpads cleanly on about one line in 256, so a cue now only counts as opened when it is strict UTF-8, and a track fails unless at least half its cues open. Decrypted lines keep their trailing \r.
professorDeveloper
added a commit
that referenced
this pull request
Nov 10, 2026
* Integrating Apple TV (tvOS); Android TV improvements Apple TV: new native SwiftUI app under apple-tv/ (XcodeGen project, 53 Swift files, PrivacyInfo, CI + Release workflows). Android TV: profiles (ProfileDatabaseProvider), continue-watching (EpisodeProgress), remote seek steps, search result diffing; torrentserver rebuilt 16 KB page-aligned for Android 15. * i18n: English base for profile strings, add uz/ru translations The new profile_* strings landed in values/ as Uzbek; move them to English in the base and add full uz and ru translations so the required locales pass check_strings.py. * Android TV: dub and other audio languages are offered as servers Every server-source episode was asked for "sub", so a dub was never reachable on TV. Each language an episode lists is now resolved and offered as its own server (Sub, Dub, a voice name), and the picked one is kept for the next episode. Movies in more than one language are resolved the same way. Quality lists that a provider files as languages are left alone. * Apple TV: focused shelf card scrolls into view; Profiles reachable by Up Moving between shelves focuses the remembered card from code, which does not scroll: the card could be focused off screen. The Profiles button sits at the far right with nothing under it, and Up from the first row went past it. Both failed the UI tests. * Apple TV: scroll a shelf's own row to its focused card The outer reader's scrollTo only moves the vertical scroll view, so a remembered card off the right edge stayed off screen. Each shelf now scrolls itself when one of its cards takes focus. The UI tests' focus walker logs where focus is at each step, so a walk that cannot reach its target says why. * Apple TV: Profiles button built like the other header buttons Focus reaches the button from the first row, but nothing reported it as focused, unlike the header buttons built from SozoActionLabel. The Up override added earlier had no effect and is gone. The UI tests now dump the screen when no element reports focus or a focused card is off screen. * Apple TV UI tests: wait out a focus move; check against the window The focus walker pressed Down whenever no element reported focus, which is also the state for a moment after every move while the scroll view follows. Up from Account reached My library and Down took it straight back, so Profiles was never reached. It now waits for focus to settle first. The shelf test checked the focused card against app.frame, which is empty on tvOS, so it failed with the card on screen. It uses the window now. The Profiles button goes back to how it was: it was never the cause. * Apple TV UI tests: find a focused button the any-element query misses With My library focused, the query over all elements found nothing even after waiting, and the walker pressed Down, back to Account. It now also asks the buttons query, and when neither answers it repeats its last move instead of always pressing Down. * Android TV: the player plays on past episode 100 The player holds one 100-episode part of a series. At its last episode it showed the end card, Next said "this is the last episode", and the episode list stopped at 100, so One Piece and any long series looked like it ended there. Past either end of a part the player now loads the next or the previous part and plays on, the up-next card announces the first episode of the next part, and history records the part actually playing. * Reviewing adapter * API address: encoded the way the phone app does it * CI: run the 218 tests that were already written, and stop paying twice for tvOS app/src/test holds 218 test methods across 36 Kotlin files — the watch-party wire format, CloudStream extension parsing, AniList matching, history sync, the player's source selection and auto-advance — and CI ran none of them. It ran check_strings.py and assembleDebug, so a green check meant the resources merged and the app compiled, which reads like a much larger claim than it is. The suite takes eight seconds warm. tvos-ci.yml carried a paths filter on push but no branch filter, next to a pull_request trigger with the same paths, so every push to a branch with a PR open booted a tvOS simulator and ran the whole UI suite twice. On 2 November that was 21m01s and 18m21s on the same commit, on a macos runner billed at ten times the Linux rate. Also: a concurrency group, so pushing three times in ten minutes no longer queues three full Gradle builds and waits for all of them, and per-job timeouts. * Apple TV CI: stop asking the hierarchy for a viewport it no longer reports "Apple TV CI" has been red since 30 October on one test, testLongShelvesMoveVerticallyAndReturnToHorizontalPosition, and not because anything in the app broke. The assertion asked whether the focused title's frame intersects app.windows.firstMatch.frame. The old comment here already knew that app.frame is empty on tvOS; on the macos-26 runner the window element's frame became empty as well, and an empty rect intersects nothing — so the check failed on a title that was plainly on screen. Run 41400672636 says so in its own failure message: /title/709 at (1488.05, 881.5, 293.89, 492.0), comfortably inside tvOS's 1920x1080 points. The claim is worth keeping — a shelf that does not scroll leaves focus on something nobody can see — so it is still asserted, against the window's frame while the window still reports one and against the fixed point size tvOS renders at otherwise. A frame of zero on the focused element itself is now its own failure with its own message, rather than being folded into an intersection that silently cannot succeed. Not run here: there is no tvOS runtime on this machine (xcrun simctl list runtimes shows none), so this is reasoned from the run log and parse-checked only. CI is the proof. * Android TV: small fixes for watch party, Live TV, Home View All, CAs and History (#35) * Android TV: a watch party survives an HDR or HDMI mode switch WatchPartyActivity declared no configChanges, so a uiMode, density or screen change recreated it, and onDestroy leaves the room, releases the player and stops the proxy. It now declares the same set as the other players, and the players comment sits above it again. * Live TV: drop the Adlt tab, and do not crash on a bookmarked channel with no stream The tab played two hard-coded streams whose tokens expired in 2025, and one token carried a third party's peers.tv session. The Bookmarks grid indexed iptvUrls[0] without a check; it now shows the same no-stream toast the Live TV grid does. * Home: no View All card on a section that has nowhere to go A section without viewAll was given the slug "::", so its View All card paged GET /contents/ or getCategory("") and landed on an empty grid. Such sections now carry no slug, and the card is only added when there is one. * Trust user-installed CAs in debug builds only Release builds trusted any user-added CA, so one could intercept the app's own backend traffic, device-auth tokens included. Cleartext stays allowed for http sources. * History: tie the sync and clear jobs to the view, not the fragment They ran on the fragment's lifecycleScope and wrote to the binding, so after onDestroyView they could touch a dead view, and a back-stack return started a second job alongside. * History: finish a clear and its sync even if the page goes away mid-clear The clear now runs on the page's view scope, so a view torn down between the tombstone and the delete could leave the tombstone without the follow-up sync. Running it on viewModelScope and joining keeps it whole. * Stop tracking the release APK, IDE state and a stray subtitle file (#34) The 45 MB app-release.apk grew history with every rebuild while the README said APKs are not hosted here; release.yml builds and ships it instead. .idea and .idea_backup were per-machine state. .gitignore now keeps them out, except .idea/codeStyles, which carries the shared Kotlin/XML style. APKs under src/test/resources stay addable as test fixtures. History is left as it is. The README still described an AniList-only anime client. It now covers the Android TV and Apple TV apps, how to build them and the four workflows. The vendored AARs get a note with their origin and SHA-256. * Android TV release: test, build once, tag, publish to the CDN and updater (#33) * CI: callable from the release, and quiet for Apple TV-only changes The Android TV release now runs the same string check and unit tests before it builds, so ci.yml accepts workflow_call with an input to skip the debug assemble. The concurrency group includes the workflow name, so a push to master can no longer cancel the tests a release is waiting on. Apple TV-only changes have their own CI and no longer trigger this one. * Android TV release: test, build, then tag and publish to the CDN The release ran on dispatch and on v* tags, cancelled itself mid-way, pushed the version bump before knowing the APK would build, and left the CDN, the in-app updater and the GitHub Release to be done by hand. It now runs only on dispatch from the default branch, queues instead of cancelling, refuses a versionCode that is not higher than the one published at /api/app-version, runs the unit tests and string check first, and pushes the bump commit and tag only after the APK built and verified. A publish job uploads the APK to R2 through the backend with SOZO_RELEASE_TOKEN, creates the download row, and optionally updates the androidtv updater row; without the token it warns and skips. The GitHub Release (draft by default) carries the APK and SHA256SUMS. Only the tagging job gets contents: write, and the actions in the signing job are pinned to commit SHAs. * Android TV release: match the backend token rules, and tag code-only builds The backend refuses a storeUrl sent with the release token, so the updater always sends storeUrl null instead of copying the row's value; otherwise a storeUrl set in the admin panel would fail every publish after the APK and tag had already shipped. A code-only bump (or none) on an already released name now tags v<name>-<code> instead of failing on the existing tag. Explicit versions must be numbers separated by dots, the version guard honours skip_version_guard when the API base cannot be decoded, and the deliver job gets a timeout. * Apple TV: release to TestFlight from Actions (#32) * Apple TV: add the wide Top Shelf image App Store Connect expects a Top Shelf Image Wide (2320x720, 4640x1440 @2x) next to the standard one. It is the existing shelf art padded with its own flat #141414 background, so the wordmark stays centred and nothing is stretched. * Apple TV release: ready for the first TestFlight upload Apple credentials are not in place yet, so the release has to fail readably and then need nothing but secrets and a dispatch. A Linux preflight lists every missing secret by name before any macOS minutes are spent. The build number defaults to the latest App Store Connect build + 1 (run number if the API query fails), a successful upload is tagged tvos-<version>-<build>, and waiting for processing and adding to an internal group run on Linux. Telegram reports the outcome. Xcode is pinned by input, Homebrew downloads are cached, and CI fails if xcodegen changes committed files. * Apple TV release: catch build number mistakes before archiving A wrong build number is only rejected by App Store Connect after about 40 macOS minutes. An upload now stops when the latest build cannot be read instead of guessing the run number, the automatic number also counts tvos-* tags so a build that is not listed yet is not reused, and preflight rejects a manual number that is not above the latest build of that version and a malformed team ID. Also: shorter JWT lifetime for clock skew, Xcode version passed through env, tests for the App Store Connect client with the API mocked, and a clearer xcodegen drift error since CI's xcodegen is unpinned. * Android TV: strip kkphim's ads and sign asilmedia's fayllar1 files (#37) * Android TV: take kkphim's ads out and sign asilmedia's fayllar1 files The backend sends a dropSegments rule for kkphim and a signer for asilmedia's fayllar1 files, and the TV dropped both on the way to the player: kkphim played its spliced ads, and fayllar1 was asked for the bare file, which it refuses. Both now reach the player as they do on the phone. A source with a rule goes through the local proxy, which strips the matching segments from each media playlist; a signed file is signed on the device, with the player's own User-Agent, before it plays. Ported from hls_segment_filter.dart and url_signer.dart. * Android TV: sign fayllar1 files each time they start, and let kkphim open externally again The file was signed once, when the source was built, and the signed URL was kept. A retry after the token expired sent the same dead token, so a long film that failed after a pause could not be resumed without picking the source again. The source now keeps the unsigned file and the player signs it on every start, as the phone does; the external player and downloads sign it when they are opened. History no longer stores a token bound to this device's IP and User-Agent. The ad rule no longer marks kkphim as needing the proxy, which had stopped those streams from opening in an external player. The player still routes them through the proxy to strip the ads. * Apple TV: relay image-wrapped HLS segments through the backend (#36) * Apple TV: relay image-wrapped HLS segments through the backend Streams on the /stream/*.m3u8 route serve their TS segments as tiktokcdn .image files with a PNG prefix, which AVPlayer cannot play. Mobile and Android TV rewrite those segment URLs to /api/contents/media-segment; tvOS had no rewrite at all. The playlists now load through an AVAssetResourceLoaderDelegate on a custom scheme, which fetches them on the device with the source headers (their tokens are bound to its address) and rewrites allowlisted segments to the relay. Other sources keep the existing direct path. * Apple TV: keep source headers on direct segments of relayed streams Segments outside the relay allowlist, EXT-X-KEY URIs and init segments are fetched by AVPlayer itself, so without the asset header option they lost Referer/Origin and any header-checked CDN that played before would now fail. Mobile and Android TV proxy them with the source headers. The loader also finishes its requests on the queue it was registered on rather than the URLSession delegate queue. * Apple TV: explain failed streams with a working Retry, focus Play, remove favourites (#39) * Apple TV player: explain a failed stream and offer Retry The player only saw item.status and a startup timeout, so a long stall went unnoticed and a failure showed AVFoundation's raw message with a single button. It now also watches FailedToPlayToEndTime, stalls that last 30 seconds and the error log, maps them to a reason the viewer can act on (offline, refused or expired link, gone, unsupported format), and offers Retry, Choose another source and Close. Retry is handed back to the caller so the stream is rebuilt through the normal loading path. * Apple TV detail: focus Play or the episodes, and let favourites be removed Focus landed on "Add to favorites" because the save row sits above the playback controls. The screen now focuses Play film, or the resumed or first episode, once loading finishes. The favourites button reads the profile's saved state, shows Remove when the title is already saved and calls DELETE /auth/favorites. The detail screen also wires the player's Retry to present the same stream again from the last position. * Apple TV: survive slow sources, throttling and a deleted profile The backend gives /contents/media 60 s to resolve a slow provider, but every request here gave up after 30 s of silence. Media now waits 75 s; everything else keeps 30 s. Backend messages are Uzbek and mostly carry no code, so they no longer reach the screen: the error code, then the HTTP status, picks an English message, and a body that does not decode says so instead of Foundation's text. A 429 or 503 GET with a short Retry-After is retried once after that wait; a longer one is shown as "try again in N seconds". Device-link polling stopped for good on the first failed poll. It now backs off exponentially on network errors, 429, 503 and 5xx, honours Retry-After, and gives up only on permanent errors or code expiry. The "denied" branch is gone: pollToken only returns pending, expired or approved. A PROFILE_NOT_FOUND reply drops the active profile, which brings back the picker, and reloads the list. "Choose another source" and playing a film no longer reuse the first, possibly expired, signed URLs: episodes call contents/media again and inline film sources are fetched again from contents/episodes, since they have no media ref. Continue watching skips a malformed row instead of losing the whole rail. * Apple TV: keep the active profile when only a managed profile is gone The backend returns PROFILE_NOT_FOUND both for a missing active profile and for a missing target of a profile edit, delete or PIN check. Reload the listing instead of assuming the active one was deleted, as the phone app does. Switching sources falls back to the earlier candidates when the fresh resolution fails, and films refetch their inline sources only on a switch. A string episodeIndex in history is read like a string episodeNumber. * Apple TV player: retry fetches a fresh link instead of replaying the old one Retry replayed the same URL and headers, so a stream refused because its signed link expired just failed again. Retry now resolves the title again (a film refetches its sources) and plays the same source at the kept position. A mapped error now outranks the error log, and only a log entry from the last few seconds is used, so a segment AVPlayer already recovered from no longer explains a later network loss. "Cannot Open" (-11828) is reported as a blocked source, as on mobile. A stall alert no longer fires after playback recovered. * Apple TV: survive slow sources, throttling and removed profiles (#38) * Apple TV: survive slow sources, throttling and a deleted profile The backend gives /contents/media 60 s to resolve a slow provider, but every request here gave up after 30 s of silence. Media now waits 75 s; everything else keeps 30 s. Backend messages are Uzbek and mostly carry no code, so they no longer reach the screen: the error code, then the HTTP status, picks an English message, and a body that does not decode says so instead of Foundation's text. A 429 or 503 GET with a short Retry-After is retried once after that wait; a longer one is shown as "try again in N seconds". Device-link polling stopped for good on the first failed poll. It now backs off exponentially on network errors, 429, 503 and 5xx, honours Retry-After, and gives up only on permanent errors or code expiry. The "denied" branch is gone: pollToken only returns pending, expired or approved. A PROFILE_NOT_FOUND reply drops the active profile, which brings back the picker, and reloads the list. "Choose another source" and playing a film no longer reuse the first, possibly expired, signed URLs: episodes call contents/media again and inline film sources are fetched again from contents/episodes, since they have no media ref. Continue watching skips a malformed row instead of losing the whole rail. * Apple TV: keep the active profile when only a managed profile is gone The backend returns PROFILE_NOT_FOUND both for a missing active profile and for a missing target of a profile edit, delete or PIN check. Reload the listing instead of assuming the active one was deleted, as the phone app does. Switching sources falls back to the earlier candidates when the fresh resolution fails, and films refetch their inline sources only on a switch. A string episodeIndex in history is read like a string episodeNumber. * Apple TV: name source outages, and test the messages the app now shows Since the error text comes from the code and status rather than the server's Uzbek message, the UI tests waited for fixture strings that never appear. Source and upstream codes now read as an unavailable source; the retry tests expect the 503 wording. * Apple TV UI tests: the notifications retry message, and a settled shelf frame The notifications retry waited for the fixture's text, which the app no longer shows. The long-shelf check read the focused title's frame mid-scroll and reported a later, on-screen reading; it now waits for the frame to settle and asserts on that one value. * Decrypt KissKH's encrypted subtitle cues on Android TV and Apple TV (#40) * Decrypt KissKH's encrypted subtitle cues on Android TV and Apple TV KissKH's .txt1 subtitles are SRT files whose cue text lines are each AES-128-CBC ciphertext, so viewers saw base64 instead of captions. The backend now tags those tracks with a cipher; both players carry it from the media payload and open each cue text line after download, before parsing. A key that opens no line or an unknown algorithm fails the track instead of showing ciphertext. * Carry the KissKH subtitle cipher through ServerHost and refuse keys that open few cues translateMedia rebuilt each subtitle from a fixed set of keys and dropped cipher, so on Android TV KissKH tracks still reached the player as base64. A wrong AES key still unpads cleanly on about one line in 256, so a cue now only counts as opened when it is strict UTF-8, and a track fails unless at least half its cues open. Decrypted lines keep their trailing \r. * Add an LG webOS TV app (#41) * Add an LG webOS TV app A plain ES5 web app for webOS TV 4.x and newer, with no build step. It browses, searches and plays the nine allowlisted server sources with the remote or the Magic Remote pointer. Not yet run on a real TV. webos.yml runs the unit and ES5 checks and keeps the ipk as an artifact. * Give the webOS app a release workflow and skip Android CI for it Android jobs took about ten minutes on changes that only touch webos/. CI artifacts expire after 14 days, so a manual workflow now publishes the ipk as a pre-release in this repository. * Let vidapi fall back to hls.js on webOS (#42) * Start hls.js from a 5 Mbps bandwidth estimate (#43) * webOS: subtitle timing offset in half-second steps (#44) * Add half-second subtitle timing offset to the webOS player * Move subtitle timing to compact chips beside the offset * webOS: play vidapi natively through a loopback relay (#45) * Let vidapi fall back to hls.js on webOS * Play vidapi natively on webOS through a loopback relay that fixes segment content types * Restrict the relay to Sozo and public hosts, pipe segments, abort redirected requests * Make the relay service private * Answer 502 when a relay request cannot be made, such as a redirect to a non-http scheme * Percent-encode non-ASCII relay paths and normalise IPv6 before the public-address check * Answer 502 for unparsable relay targets and redirects, drop unparsable playlist lines * Record sportstv playing natively on webOS 10.3 in the README * Relay API-declared headers on webOS and allow seven more sources, with mkv audio and subtitle choice (#46) --------- Co-authored-by: professorDeveloper <108933534+professorDeveloper@users.noreply.github.com> Co-authored-by: Arnold de Ruiter <187004+ArnoldDeRuiter@users.noreply.github.com>
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.
Stacked on #31 (
integrating-apple-tv). This is the TV half of PR 14 in the backend source audit ("Backend manbalari chuqur tekshiruvi", section "Tuzatishlarni PR larga bo'lish"). The backend half is professorDeveloper/sozo-backend#55.What and why
KissKH serves
.txt1subtitles as ordinary SRT files, but each cue text line is AES-128-CBC encrypted and base64 encoded. Viewers saw ciphertext. Backend #55 tags these tracks withcipher {alg, key, iv, scope, encoding}. The owner approved sending the key in the API response. This PR decrypts the cue lines on the client.SubtitleCipher(new) is parsed fromsubtitles[].cipherintoExtSubtitle,MegaTrackandSubTitle.SubtitleSideloaderdecrypts afterSubtitleBody.decodeand beforeSubtitleNormalizer.ServerHost.translateMedianow passescipherthrough. Before this change it rebuilt each subtitle and dropped the field, and that is the path KissKH takes on Android TV.SubtitleTrack.cipheris decoded leniently, so a malformed cipher keeps the track.SidecarSubtitles.decryptCueTextuses CommonCrypto, andTVPlayerViewdecrypts before it parses.Outcome.Failedon Android and the "Subtitles unavailable" alert on tvOS; it never shows ciphertext.alg,scopeorencodingvalues are refused. Tracks withoutcipherbehave exactly as before, so old backends and other sources are not affected.Validation
./gradlew :app:testDebugUnitTest --offline: 238 tests, 0 failures.SubtitleCipherTesthas 6 tests. They cover the live vector (Sq/yslS8glo0CoTCWZBT0GepZqSNY4KqATqtSAO1798=decrypts to<i>♫ Set off ♫</i>, also checked with openssl), a wrong key, minority opens, an unknown algorithm, the ExtParser payload, and an extractor-shaped payload (src+cipher, asextractors/kisskh.jsv7 emits) sent throughServerHost.translateMedia.apple-tv/scripts/check-profiles.sh: every check passed, including the cipher decrypt and decoding checks.xcodebuild build-for-testingfor the tvOS Simulator. It was not run again for the one-line threshold change inSidecarSubtitles.swift, which check-profiles compiles.Device version bumps
None. Only native app code changes here. The kisskh extractor bump (v6 to v7) is in backend #55.
Not tested / limits
client-mode source, andProvider.supportsServerBrowsinghides it on tvOS. The tvOS decrypt path is ready, but it cannot be reached for KissKH today. This PR does not make KissKH subtitles work on Apple TV..txtsubtitles, its own interceptor, see theCsStreamProxycomment) is separate and was not changed.Owner questions
ITSAppUsesNonExemptEncryption=false, and the app now calls CommonCryptoCCCrypt, only to decrypt content. That use is normally exempt. Please confirm before the next App Store submission.