Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decipher format URLs with the local API #3053

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,42 @@ export async function getLocalSearchContinuation(continuationData) {
}

export async function getLocalVideoInfo(id, attemptBypass = false) {
let info
let player

if (attemptBypass) {
const innertube = await createInnertube({ withPlayer: true, clientType: ClientType.TV_EMBEDDED })
player = innertube.actions.session.player

// the second request that getInfo makes 404s with the bypass, so we use getBasicInfo instead
// that's fine as we have most of the information from the original getInfo request
return await innertube.getBasicInfo(id, 'TV_EMBEDDED')
info = await innertube.getBasicInfo(id, 'TV_EMBEDDED')
} else {
const innertube = await createInnertube({ withPlayer: true })
return await innertube.getInfo(id)
player = innertube.actions.session.player

info = await innertube.getInfo(id)
}

if (info.streaming_data) {
decipherFormats(info.streaming_data.adaptive_formats, player)
decipherFormats(info.streaming_data.formats, player)
}

return info
}

/**
* @param {import('youtubei.js/dist/src/parser/classes/misc/Format').default[]} formats
* @param {import('youtubei.js/dist/index').Player} player
*/
function decipherFormats(formats, player) {
for (const format of formats) {
format.url = format.decipher(player)

// set these to undefined so that toDash doesn't try to decipher them again, throwing an error
format.cipher = undefined
format.signature_cipher = undefined
}
}

Expand Down