Conversation
…snapshot setCookie writes the three values in one DataStore edit, but they were pushed to the scraper by three independent collectors and stored as three plain vars read one by one while building request headers. After an account switch a request could still carry the new pageId with the previous authuser or cookie, for a short window. DataStoreManager now exposes youTubeSession, a single flow over one Preferences snapshot; CommonRepositoryImpl collects it and calls YouTube.setSession. Ytmusic keeps a @volatile immutable Session that ytClient and getAuthorizationHeader read once per request; the per-field setters and the cached cookieMap are gone, the SAPISID hash is computed from the cookie actually sent. visitorData is still refreshed only when the cookie changes, and the netscape cookie file is written once per session change instead of twice. AccountRepositoryImpl no longer writes youTube.cookie directly: both callers already wrote DataStore. Refs maxrave-dev/SimpMusic#2505
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.
What & why
Follow-up to #36 / maxrave-dev/SimpMusic#2505. That fix added
authUsernext topageId,but the three session values still reached the scraper through three independent DataStore
collectors, and
Ytmusicstored them as three plain vars read one by one inytClient().A request built right after an account switch could carry a new pageId with the previous
authuser or cookie, for a short window.
DataStoreManager.youTubeSession: one flow over one Preferences snapshot(
distinctUntilChanged, sincedatare-emits on every unrelated preference).CommonRepositoryImpl: one collector callingYouTube.setSession(...)first, synchronously.visitorData is refreshed only when the cookie changes (same trigger as before, tracked
with
lastCookie, committed only on a successful fetch); the netscape cookie file iswritten once per session change (was twice).
Ytmusic:@Volatile private var session: Sessionswapped as one immutable object;ytClient()andgetAuthorizationHeader()read it once.cookie/pageId/authUserare read-only now,
setSessionis the only writer. The cachedcookieMapis gone: theSAPISID map is parsed from the cookie actually sent (
customCookie ?: session cookie).AccountRepositoryImpl.getAccountInfono longer writesyouTube.cookiedirectly: bothcallers already wrote DataStore and the request passes the cookie explicitly.
getAuthorizationHeader()hadif (...) nullwithoutreturn(no callers).Not changed, worth knowing:
parseCookieStringthrows on a;-segment without=; itnow runs per request instead of inside the collector, so a bad pasted cookie no longer
kills the sibling jobs. A guard there is a separate follow-up.
Two pre-existing issues seen while testing, not touched here: every DataStore write
re-emits the proxy flows,
removeProxy()setsproxy = nullunconditionally and thesetter closes and recreates the HttpClient, so in-flight requests fail with
executor rejected(hit thevisitorData()request on every account switch); andvisitorData()currently fails parsingsw.js_datawithNoSuchElementException.I can open issues for both.
Linked issue
Refs maxrave-dev/SimpMusic#2505
Checklist
channels of the same Google account, watching the request log: startup (one session,
X-Goog-Authuser: 0+X-Goog-Pageidof the brand channel), switch to the main channel(one session, cookie file written once, next
browsehas no Pageid), switch back (Pageidback, never a mixed pair), logout (one session, next requests without Cookie or Pageid).
Compiled scraper/domain/data for JVM and Android,
:desktopApp:jvmMainClassesand:composeApp:compileAndroidMain. Not tested: re-login with the same cookie.