~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/hydraulophone

An unofficial YouTube Music app for iPhone, iPad, and Mac.

0
0
main
184 lines · 11.1 KB Raw History
# ADR 0001: MVP boundary and InnerTube adapter

- Status: accepted for the merged MVP; broader device and service validation pending
- Date: 2026-09-22

## Context

The requested MVP is an accurate AuraMusic-informed Kotlin-to-Swift protocol
port with working search, playlists, and streaming, an Apple Music-style
iPhone experience, and mandatory Keychain-backed cookies. InnerTube is
undocumented, changes without notice, and does not have the same stability or
authorization guarantees as an official API. The project guide requires
transport DTOs and protocol-specific parsing to remain outside SwiftUI.

The implementation now has a native Search/Library shell, a purple theme, a
mini and full player with queue and seek state, an ordered Keychain session
boundary, and fixture-tested Core and app targets. The basic live run at
2026-09-22 13:59 local restored the Keychain session, returned 17 search
results, 11 playlists, and 100 tracks, then observed native `AVPlayer`
progress for at least two seconds. An extended run at 14:06–14:07 repeated
the browse path, sustained playback for 30 seconds, paused/resumed, sought to
65% of the track, and advanced to the next track with observed progress. This
validates the direct-AAC checkpoint, but not every track, physical-device
playback, or background audio. The complete evidence and the older diagnostic
result are recorded in [`docs/mvp-validation.md`](../mvp-validation.md).

The protocol review consulted the GPL-3.0 AuraMusic reference at commit
[`185a77d31733047de06cbec619d40731755a0ec1`](https://github.com/TeamAuraMusic/AuraMusic/tree/185a77d31733047de06cbec619d40731755a0ec1),
specifically:

- [`InnerTube.kt`](https://github.com/TeamAuraMusic/AuraMusic/blob/185a77d31733047de06cbec619d40731755a0ec1/innertube/src/main/kotlin/com/auramusic/innertube/InnerTube.kt)
  for request headers, web configuration, retry boundaries, and
  `SAPISIDHASH`;
- [`YouTubeClient.kt`](https://github.com/TeamAuraMusic/AuraMusic/blob/185a77d31733047de06cbec619d40731755a0ec1/innertube/src/main/kotlin/com/auramusic/innertube/models/YouTubeClient.kt)
  for client identities and login policy;
- [`YouTube.kt`](https://github.com/TeamAuraMusic/AuraMusic/blob/185a77d31733047de06cbec619d40731755a0ec1/innertube/src/main/kotlin/com/auramusic/innertube/YouTube.kt)
  for search and browse renderer shapes; and
- the corresponding `YTPlayerUtils.kt` implementation for the bounded player
  profile order.

## Decision

The MVP uses:

1. `InnerTubeClient` as an actor that obtains the current Music web
   configuration and centralizes request headers.
2. `InnerTubeRequestBuilder` as a pure, fixture-testable request/signature
   boundary.
3. A defensive JSON parser that maps responsive list rows and two-row
   playlist cards into stable `Song` and `Playlist` models. The Swift request
   and model shapes are not a mechanical copy of Kotlin source.
4. A first-page-only query API. Continuation tokens are opaque and are not
   exposed until their response envelopes have dedicated fixtures.
5. Search through anonymous `WEB_REMIX`; authenticated library playlists through
   `browseId = FEmusic_liked_playlists`; and individual playlist pages through
   `VL<playlist-id>`. `DATASYNC_ID` remains opaque, including any `||`
   components, and is not emitted as `onBehalfOfUser`. Captured session
   `VISITOR_DATA` is optional. A separate optional delegated session ID is
   populated only from authoritative `DELEGATED_SESSION_ID` and is emitted
   only when present.
6. A bounded AuraMusic-derived playback profile sequence. Each candidate is
   attempted at most once, credentials are supplied only to profiles that
   explicitly support login, and `IOS` is not treated as the sole fallback.
   Direct audio is preferred at play time; media URLs are never persisted.
7. No invented signature decipherer or PO-token provider. Cipher-only and
   provider-dependent responses are explicit unavailable states. Native AAC
   restriction and strict HTTPS host/redirect validation are merged and covered
   by the direct-AAC simulator checkpoint. Playback uses a native
   `AVAssetResourceLoader`/`URLSession` bridge with full Aura request headers;
   this resolved the observed AVPlayer 403 in the checkpoint, but does not
   establish every-track or device-wide playback.
8. `AVAudioSession`, `AVPlayer`, `MPNowPlayingInfoCenter`, queue/seek state, and
   remote commands inside `PlaybackController`, not in SwiftUI views.
9. A SwiftUI Search/Library shell with a mini player and full Now Playing
   surface, plus a reproducible XcodeGen project with one iPhone application.
   iOS 17 is the deployment floor.

The detailed endpoint contract and protocol provenance are maintained in
[`docs/protocol/innertube-aura-port.md`](../protocol/innertube-aura-port.md).
That note is the source of truth for protocol-sensitive behavior.

## Authentication decision

The owner explicitly approved an experimental InnerTube-compatible web-session
flow for this unofficial client. The login surface uses a non-persistent
`WKWebView` pointed at YouTube Music. When a Keychain session exists, allowed
cookies seed the ephemeral store before navigation. After a successful
YouTube-domain navigation, the app captures the allowed cookie header,
`DATASYNC_ID`, and optional `VISITOR_DATA`; `SAPISID` is required. The
immutable session snapshot is stored as device-only Keychain data, and
`SAPISIDHASH` is derived only inside the transport boundary.

On 2026-09-23, a fresh physical-iPhone login displayed Google's “This browser
or app may not be secure” error. The owner confirmed that a fresh simulator
login had previously succeeded with an empty Keychain. The login WebView now
uses a mobile Safari-format user agent, independent of the InnerTube request
profiles. After the updated device build was installed, the owner completed
sign-in on the iPhone and reported that the app worked well there. This is one
device observation; session restoration and repeat sign-in on that device
remain to be checked. The format follows
[WebKit's Safari 26 user-agent note](https://webkit.org/blog/17333/webkit-features-in-safari-26-0/).
Google [documents embedded-browser OAuth failures](https://developers.google.com/identity/protocols/oauth2/native-app)
and [restricts embedded user agents](https://developers.google.com/identity/protocols/oauth2/policies),
so this result does not establish a supported or durable authentication flow.

Restore and login install the service session before publishing it to the
SwiftUI state. The persistent WebKit store is read only to migrate sessions
from earlier builds, then cleared; it is not a second credential database.
Sign-out clears playback, in-memory state, Keychain data, and owned YouTube or
Google WebKit data, and surfaces a checked Keychain failure rather than
claiming success.

Authenticated request bodies include a delegated session identity only for
operations and profiles that explicitly opt in, and only when the
authoritative `DELEGATED_SESSION_ID` value is present. Raw `DATASYNC_ID` is
retained but is not sent as `context.user.onBehalfOfUser`. Search remains
anonymous.
`IOS` has `loginSupported = false`; the bounded playback sequence does not
silently attach the account session to that or other guest profiles.
Cookie headers, signatures, `DATASYNC_ID`, visitor data, account responses, and
stream URLs are not logged.

`DATASYNC_ID` is intentionally not normalized at the session boundary. The
adapter retains the captured value unchanged, including `||` components, and
does not manufacture or strip a prefix during Keychain decoding. It does not
use that raw value as `onBehalfOfUser`. Authenticated `WEB_REMIX` requests use
session visitor data when available; anonymous and non-login profiles use the
anonymous web configuration visitor data. A separate delegated session value
is read only from authoritative `DELEGATED_SESSION_ID` and omitted when absent.
The previous ADR text claiming that prefix normalization caused the HTTP 500
was not supported as a durable protocol rule and has been removed.

The runtime uses a pinned `AuraWEB_REMIX` configuration path. A homepage GET
is not mandatory when the API key is absent, avoiding a 302 consent bootstrap
response being treated as the configuration source.

The simulator build is ad-hoc signed with
`Resources/Hydraulophone.Simulator.entitlements`. iOS 27 rejects Keychain
operations from an unsigned simulator app with `errSecMissingEntitlement`
(`-34018`), even when the app only uses its private generic-password item.
The simulator entitlement is selected only for the simulator SDK. Device
builds use the normal `$(AppIdentifierPrefix)$(CFBundleIdentifier)` Keychain
access group and the developer's real signing configuration.

This is not an official Google sign-in implementation. Embedded Google login,
high-privilege web cookies, InnerTube impersonation, and private account access
carry Google policy, App Store, and account-security risks. The app must not
describe this flow as endorsed or official.

## Consequences and risks

- The anonymous search, authenticated library, and playback paths can break
  when YouTube changes the web configuration, client profile, renderer layout,
  account identity, or stream policy. The latest basic and extended runs
  validate one direct-AAC checkpoint, but not every track or service response.
- Direct media URLs expire and can return 403/410. Playback must refresh
  through `player` rather than retrying the same URL; the current slice has a
  bounded refresh attempt but still needs broader live validation.
- The parser intentionally returns only supported rows and never treats a
  missing renderer as a crash. A future continuation implementation must
  normalize known continuation envelopes without parsing opaque tokens.
- Background audio, remote commands, route changes, interruptions, lock-screen
  controls, codec restrictions, and stream behavior require physical-iPhone
  validation. Simulator build/test is not evidence for those behaviors, and
  no physical iPhone was available for this MVP snapshot.
- The historical diagnostic run should not be confused with the normal app
  result. The temporary DATASYNC-omission diagnostic was removed after A/B
  verification; no active omission command is part of the MVP validation
  path.
- The new extended simulator command provides a bounded observed-progress
  check, but final range and URL-userinfo review fixes still require a new
  hosted test run. The current evidence is not a physical-device or
  background-audio result.
- InnerTube client impersonation, private account access, and bypassing stream
  restrictions can raise YouTube terms, App Store, and distribution issues.
  This project does not claim official API access or endorsement.
- Some protocol-sensitive implementation behavior, including the bounded
  playback profile sequence, is adapted from AuraMusic. The applicable
  GPL-3.0 provenance and distinction between adapted behavior and new Swift
  code are recorded in [`NOTICE`](../../NOTICE), source comments, and the
  protocol note.
- The approved YouTubeKit signature and `n` deciphering adapter is follow-up
  work and has not landed. It is not a prerequisite for the working direct-AAC
  checkpoint, but cipher-only responses remain unavailable until it does.