Skip to content

Instantly share code, notes, and snippets.

@minibox24
Last active January 28, 2024 03:54
Show Gist options
  • Save minibox24/5041eda366ce69e784971ccd34093c6f to your computer and use it in GitHub Desktop.
Save minibox24/5041eda366ce69e784971ccd34093c6f to your computer and use it in GitHub Desktop.
플리 딸깍
(() => {
async function sha1(content) {
const buf = await window.crypto.subtle.digest(
"SHA-1",
new TextEncoder("utf-8").encode(content)
);
return Array.prototype.map
.call(new Uint8Array(buf), (x) => ("00" + x.toString(16)).slice(-2))
.join("");
}
async function makeHash() {
const now = new Date();
const origin = "https://www.youtube.com";
const timems = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
const timesec = Math.round(timems / 1000);
const SAPISID = document.cookie.split("SAPISID=")[1].split("; ")[0];
const shaed = await sha1(
timesec + " " + SAPISID + " " + origin,
"utf8",
"hex"
);
return timesec + "_" + shaed;
}
async function createPlaylist(title, videoIds) {
console.log(title, videoIds);
const res = await fetch(
"https://www.youtube.com/youtubei/v1/playlist/create?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&prettyPrint=false",
{
method: "POST",
headers: {
authorization: "SAPISIDHASH " + (await makeHash()),
"x-goog-authuser": ytcfg.data_.SESSION_INDEX,
"x-goog-pageid": ytcfg.data_.DELEGATED_SESSION_ID,
},
body: JSON.stringify({
context: {
client: {
clientName: "WEB",
clientVersion: "2.20200720.00.02",
},
},
title,
videoIds,
}),
}
);
const data = await res.json();
return data.playlistId;
}
async function main() {
const rawVideos = prompt("시트에서 노래 목록을 복사해오세요.");
const videos = rawVideos.replace(/\r/g, "").split("\n");
const videoIds = videos.map((video) => video.split("/")[3]);
let name = prompt(
`${videoIds.length}곡이 담길 유튜브 플레이리스트 이름을 입력하세요.`
);
if (name === null) {
alert("취소되었습니다.");
}
const ytPlaylistId = await createPlaylist(name, videoIds);
location.href = `https://www.youtube.com/playlist?list=${ytPlaylistId}`;
}
main();
})();
@minibox24
Copy link
Author

javascript:%28%28%29%3D%3E%7Basync%20function%20a%28t%29%7Bconst%20e%3Dawait%20window.crypto.subtle.digest%28%22SHA-1%22%2Cnew%20TextEncoder%28%22utf-8%22%29.encode%28t%29%29%3Breturn%20Array.prototype.map.call%28new%20Uint8Array%28e%29%2Ct%3D%3E%28%2200%22%2Bt.toString%2816%29%29.slice%28-2%29%29.join%28%22%22%29%7Dasync%20function%20c%28%29%7Bconst%20t%3Dnew%20Date%3Bconst%20e%3D%22https%3A%2F%2Fwww.youtube.com%22%3Bconst%20o%3Dt.getTime%28%29%2Bt.getTimezoneOffset%28%29%2A60%2A1e3%3Bconst%20n%3DMath.round%28o%2F1e3%29%3Bconst%20c%3Ddocument.cookie.split%28%22SAPISID%3D%22%29%5B1%5D.split%28%22%3B%20%22%29%5B0%5D%3Bconst%20i%3Dawait%20a%28n%2B%22%20%22%2Bc%2B%22%20%22%2Be%2C%22utf8%22%2C%22hex%22%29%3Breturn%20n%2B%22_%22%2Bi%7Dasync%20function%20i%28t%2Ce%29%7Bconsole.log%28t%2Ce%29%3Bconst%20o%3Dawait%20fetch%28%22https%3A%2F%2Fwww.youtube.com%2Fyoutubei%2Fv1%2Fplaylist%2Fcreate%3Fkey%3DAIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8%26prettyPrint%3Dfalse%22%2C%7Bmethod%3A%22POST%22%2Cheaders%3A%7Bauthorization%3A%22SAPISIDHASH%20%22%2Bawait%20c%28%29%2C%22x-goog-authuser%22%3Aytcfg.data_.SESSION_INDEX%2C%22x-goog-pageid%22%3Aytcfg.data_.DELEGATED_SESSION_ID%7D%2Cbody%3AJSON.stringify%28%7Bcontext%3A%7Bclient%3A%7BclientName%3A%22WEB%22%2CclientVersion%3A%222.20200720.00.02%22%7D%7D%2Ctitle%3At%2CvideoIds%3Ae%7D%29%7D%29%3Bconst%20n%3Dawait%20o.json%28%29%3Breturn%20n.playlistId%7Dasync%20function%20t%28%29%7Bconst%20t%3Dprompt%28%22%EC%8B%9C%ED%8A%B8%EC%97%90%EC%84%9C%20%EB%85%B8%EB%9E%98%20%EB%AA%A9%EB%A1%9D%EC%9D%84%20%EB%B3%B5%EC%82%AC%ED%95%B4%EC%98%A4%EC%84%B8%EC%9A%94.%22%29%3Bconst%20e%3Dt.replace%28%2F%5Cr%2Fg%2C%22%22%29.split%28%22%5Cn%22%29%3Bconst%20o%3De.map%28t%3D%3Et.split%28%22%2F%22%29%5B3%5D%29%3Blet%20n%3Dprompt%28%60%24%7Bo.length%7D%EA%B3%A1%EC%9D%B4%20%EB%8B%B4%EA%B8%B8%20%EC%9C%A0%ED%8A%9C%EB%B8%8C%20%ED%94%8C%EB%A0%88%EC%9D%B4%EB%A6%AC%EC%8A%A4%ED%8A%B8%20%EC%9D%B4%EB%A6%84%EC%9D%84%20%EC%9E%85%EB%A0%A5%ED%95%98%EC%84%B8%EC%9A%94.%60%29%3Bif%28n%3D%3D%3Dnull%29%7Balert%28%22%EC%B7%A8%EC%86%8C%EB%90%98%EC%97%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%22%29%7Dconst%20c%3Dawait%20i%28n%2Co%29%3Blocation.href%3D%60https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3D%24%7Bc%7D%60%7Dt%28%29%7D%29%28%29%3B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment