Enter Passkey

Text

(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([[505], { 6800: function(e, t, r) { (window.__NEXT_P = window.__NEXT_P || []).push(["/playlist-generator", function() { return r(3570) }]) }, 3056: function(e, t, r) { "use strict"; r.d(t, { H: function() { return s } }); var a = r(5893); function s() { return (0, a.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink", style: { margin: "auto", display: "block", shapeRendering: "auto" }, width: "100px", height: "100px", viewBox: "0 0 100 100", preserveAspectRatio: "xMidYMid", children: (0, a.jsx)("path", { d: "M29 50A21 21 0 0 0 71 50A21 22.7 0 0 1 29 50", fill: "#74007a", stroke: "none", children: (0, a.jsx)("animateTransform", { attributeName: "transform", type: "rotate", dur: "1s", repeatCount: "indefinite", keyTimes: "0;1", values: "0 50 50.85;360 50 50.85" }) }) }) } }, 3570: function(e, t, r) { "use strict"; r.r(t), r.d(t, { default: function() { return x } }); var a = r(5893), s = r(4763), n = r(6154), l = r(7294), i = r(6501), c = r(3967), o = r(623), d = r(3056), u = r(7708); let p = "31vbyjigdveqsnpc54fyfsxzjuge"; function m() { let e, t, r; let [s, m] = (0, l.useState)(""), [x, f] = (0, l.useState)([]), [g, y] = (0, l.useState)([]), [v, w] = (0, l.useState)({ tracks: [], duration: 0 }), [b, j] = (0, l.useState)(""), k = (0, l.useRef)(null), [N, A] = (0, l.useState)(!1), [P, O] = (0, l.useState)(!1); (0, l.useEffect)(() => { (0, n.Z)({ url: "/api/token", method: "get" }).then(e => m(e.data.access_token)) }, []), (0, l.useEffect)(() => { (async function() { try { let e = (await n.Z.get("/api/token")).data.access_token; await (0, n.Z)({ url: "https://api.spotify.com/v1/search?q=test&type=track&limit=5", method: "GET", headers: { Authorization: "Bearer ".concat(e) } }) } catch (e) { O(!0) } })() }, []); let Z = async e => { if (j(""), !P) { if ("" === e.target.value) f([]); else try { let t = await (0, n.Z)({ url: "https://api.spotify.com/v1/search?q=".concat(e.target.value, "&type=track,album&limit=5"), method: "GET", headers: { Authorization: "Bearer ".concat(s) } }); f([...t.data.tracks.items, ...t.data.albums.items]) } catch (e) { i.ZP.error(e.response.data), i.ZP.error("Please try again later"), O(!0) } } }, _ = async e => { if (P) { k.current && (k.current.value = ""); return } if (g.length > 40) { i.ZP.error("Maximum selected song is 20."); return } if ("track" === e.type) { let t = { uri: e.uri, name: e.name, img: e.album.images[0].url, noOfApperances: 1, duration: e.duration_ms, explicit: e.explicit }; if (g.map(e => e.uri).includes(e.uri)) { i.ZP.error("Song is already selected."); return } g.push(t), y(g) } else { let t = await (0, n.Z)({ url: "https://api.spotify.com/v1/albums/".concat(e.id, "/tracks?limit=40"), method: "GET", headers: { Authorization: "Bearer ".concat(s) } }), r = t.data.items.map(t => { if (!g.map(e => e.uri).includes(t.uri)) return { uri: t.uri, name: t.name, img: e.images[0].url, noOfApperances: 1, duration: t.duration_ms, explicit: t.explicit } }).filter(e => e); y([...g, ...r]) } f([]), k.current && (k.current.value = "") }, S = () => { if (P) return; if (g.length < 5) { i.ZP.error("Please select more than 5 songs to avoid looping"); return } j(""), A(!0); let e = []; for (let t of g) { if (t.noOfApperances > 40 || t.noOfApperances < 1) { w({ tracks: [], duration: 0 }), i.ZP.error("Please reduce the number of appearances to less than 40"), A(!1); return } for (let r = 0; r < t.noOfApperances; r++) e.push(t) } if (e.length > 200) { i.ZP.error("Total appearances should be less than 150 to avoid long playlist creation. Please reduce the number of appearances or selected tracks"); return } let t = []; e = e.sort((e, t) => t.noOfApperances - e.noOfApperances); for (let a = 0; a < e.length; a++) { let s = e[a - 1]; if (s && s.uri === e[a].uri) { var r; let n = g.filter(e => e.uri !== s.uri).sort((e, t) => t.noOfApperances - e.noOfApperances), l = n[Math.floor(5 * Math.random())], i = n.filter(e => ![l.uri, s.uri].includes(e.uri)); t.push(l), t.push(null !== (r = i.find(e => !t.includes(e))) && void 0 !== r ? r : i[Math.floor(Math.random() * i.length)]), t.push(e[a]) } else t.push(e[a]) } let a = 0; t.map(e => a += e.duration), w({ tracks: t.splice(0, e.length < t.length - 40 ? e.length + 40 : t.length), duration: a }), A(!1) }, C = async () => { let e; if (P) return; let t = "Playlist includes minimum: "; for (let e of (A(!0), g.sort((e, t) => t.noOfApperances - e.noOfApperances))) t += "".concat(e.noOfApperances, "x ").concat(e.name, ", "); let r = g.sort((e, t) => t.noOfApperances - e.noOfApperances); try { let a = await (0, n.Z)({ url: "https://api.spotify.com/v1/users/".concat(p, "/playlists"), method: "POST", data: { name: "".concat(r[0].name, ", ").concat(r.length > 1 ? "".concat(r[1].name, " + more") : ""), description: t, public: !0 }, headers: { Authorization: "Bearer ".concat(s) } }); e = a.data.id, j(a.data.external_urls.spotify) } catch (e) { i.ZP.error(e.response.data), i.ZP.error("Please try again later."), A(!1), j("") } if (e) try { await Promise.all((function(e, t) { let r = []; for (e = [].concat(...e); e.length;) r.push(e.splice(0, 90)); return r })(v.tracks, 0).map(t => { (0, n.Z)({ url: "https://api.spotify.com/v1/playlists/".concat(e, "/tracks"), method: "POST", data: { uris: t.map(e => e.uri) }, headers: { Authorization: "Bearer ".concat(s) } }) })), y([]), w({ tracks: [], duration: 0 }), A(!1) } catch (e) { i.ZP.error(e.response.data), i.ZP.error("Please try again later."), A(!1), j("") } }; return (0, a.jsxs)("section", { className: "bg-gray-900", children: [(0, a.jsxs)("div", { className: "flex flex-col items-center w-screen py-5", children: [(0, a.jsx)("div", { className: "text-xl font-bold text-white lg:text-3xl", children: "Streaming playlist generator" }), (0, a.jsxs)("div", { className: "w-[20rem] relative py-3 lg:w-[30rem]", children: [(0, a.jsx)("div", { className: "absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none", children: (0, a.jsx)("svg", { "aria-hidden": "true", className: "w-5 h-5 text-gray-500 dark:text-gray-400", fill: "currentColor", viewBox: "0 0 20 20", xmlns: "http://www.w3.org/2000/svg", children: (0, a.jsx)("path", { fillRule: "evenodd", d: "M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z", clipRule: "evenodd" }) }) }), (0, a.jsx)("input", { type: "text", id: "simple-search", onChange: Z, ref: k, className: "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500", placeholder: "Type in track name...", required: !0 }), x.length > 0 && (0, a.jsx)("div", { className: "bg-white flex flex-col gap-2 absolute w-full p-2 mt-3 rounded-md", children: x.map((e, t) => (0, a.jsxs)("div", { className: "p-2 flex items-center gap-2 cursor-pointer hover:bg-gray-400", onClick: () => _(e), children: [(0, a.jsx)("img", { src: "album" === e.type ? e.images[0].url : e.album.images[0].url, alt: "", className: "h-12" }), (0, a.jsxs)("div", { className: "truncate max-w-[15rem]", children: [(0, a.jsxs)("div", { className: "flex items-center gap-1", children: [(0, a.jsx)("div", { children: e.name }), e.explicit && (0, a.jsx)("div", { className: "px-1 py-[0.5px] bg-red-500 text-white text-[10px] font-bold rounded-sm", children: "E" })] }), (0, a.jsx)("div", { className: "text-xs text-green-500", children: e.type.toUpperCase() })] })] }, t)) })] }), (0, a.jsxs)("div", { className: "flex flex-col items-center", children: [(0, a.jsx)("div", { className: "text-white text-center max-w-lg text-xs", children: "*Tips: If you wanna have a focused track(s), please add it(them) as the sole song with highest minimum appearances. Ex: 25 track A, 20 track B, 15 track C, + fillers to focus on track A the most." }), g.length > 0 && (0, a.jsxs)(a.Fragment, { children: [(0, a.jsx)("div", { className: "text-white py-5", children: "System experiencing too many request rate limit (~ 10 hours). Feel free to save the link and check back in later. \uD83D\uDE03" }), (0, a.jsxs)("a", { href: "https://open.spotify.com/user/".concat(p), className: "flex items-center gap-1 text-purple-500 my-5 py-1 px-2 border border-purple-500 rounded-full hover:text-white hover:bg-purple-500", children: [(0, a.jsx)("p", { children: "View the playlists created by other users" }), (0, a.jsx)(o, { className: "h-4" })] })] })] }), b && (0, a.jsxs)("div", { className: "py-3 gap-2 flex flex-col items-center", children: [(0, a.jsx)("a", { href: b, className: "bg-green-500 py-3 px-5 text-white rounded-full font-bold hover:bg-green-700", children: "Click to view playlist" }), (0, a.jsx)(u.Z, { force: .7, duration: 2e3, particleCount: 250, width: 1e3 })] }), N && (0, a.jsx)(d.H, {})] }) } function h(e) { return e.toString().padStart(2, "0") } function x() { return (0, a.jsx)(s.Z, { preview: "https://bcd-chart.s3.eu-north-1.amazonaws.com/img/spotify+thumbnail+4.png", description: "Generate your Spotify streaming playlist", title: "Playlist generator", children: (0, a.jsx)(m, {}) }) } } }, function(e) { e.O(0, [948, 870, 894, 154, 78, 763, 774, 888, 179], function() { return e(e.s = 6800) }), _N_E = e.O() }]);