Open dnicolson opened 3 weeks ago
To obtain the account index in the browser, the /getAccountSwitcherEndpoint
endpoint can be used:
const activeHandle = window.ytInitialData.header.playlistHeaderRenderer.ownerText.runs[0].navigationEndpoint.commandMetadata.webCommandMetadata.url.slice(1)
const youtube = await Innertube.create({
cookie: document.cookie,
fetch: (...arguments_) => fetch(...arguments_),
})
const response = await youtube.session.http.fetch(`/getAccountSwitcherEndpoint`, {
baseURL: 'https://www.youtube.com',
})
const text = await response.text()
const accountSwitcher = JSON.parse(text.slice(5))
const accounts = accountSwitcher.data.actions[0].getMultiPageMenuAction.menu.multiPageMenuRenderer.sections[0].accountSectionListRenderer.contents[0].accountItemSectionRenderer.contents
return accounts.findIndex(item => item.accountItem && item.accountItem.channelHandle.simpleText === activeHandle)
Steps to reproduce
In most cases, it is required to remove these lines: https://github.com/LuanRT/YouTube.js/blob/4b60b97132b0ee42b41838f3336c582a7f7f7aec/src/utils/HTTPClient.ts#L75-L76
To prevent this response from
/playlist
requests:Failure Logs
Expected behavior
The playlist contents will be retrieved from the secondary account.
Current behavior
The
X-Goog-AuthUser
header doesn't appear to indicate the active account as described in #229 and https://github.com/yt-dlp/yt-dlp/commit/34917076ad9844eddfa4ea97656d81a7fefe5d59.Looking at the source of desktop_polymer.js, the
X-Goog-AuthUser
header comes from theSESSION_INDEX
value:Switching between accounts does not change the
ytcfg.data_.SESSION_INDEX
value, it is always0
. A search on GitHub only found code using theSESSION_INDEX
value or hard coding0
or1
.Version
Default
Anything else?
This code successfully gets the contents of the Watch Later playlist of the active account:
Checklist