Last active
January 28, 2024 03:54
-
-
Save minibox24/5041eda366ce69e784971ccd34093c6f to your computer and use it in GitHub Desktop.
플리 딸깍
This file contains 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 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(); | |
})(); |
Author
minibox24
commented
Jan 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment