Last active
May 10, 2025 21:25
-
-
Save Jiiks/6c3e6391ed236568c3d047bea1e6953c to your computer and use it in GitHub Desktop.
Youtube sapisid hash gen
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
async function generateSapisidHash(datasyncId, full = true, origin = 'https://www.youtube.com') { | |
const sapisid = document.cookie.split('; ').find(cookie => cookie.startsWith('SAPISID')).split('=')[1]; | |
const dsid = datasyncId.split('||')[1]; | |
const ts = Math.floor(new Date().getTime() / 1E3); | |
const input = [dsid, ts, sapisid, origin].join(' '); | |
const digest = await window.crypto.subtle.digest('SHA-1', new TextEncoder('utf-8').encode(input)).then(buf => { | |
return Array.prototype.map.call(new Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join(''); | |
}); | |
const hash = `${ts}_${digest}_u`; | |
if(full) return `SAPISIDHASH ${hash} SAPISID1PHASH ${hash} SAPISID3PHASH ${hash}`; | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment