update to use new spotify-dl

main
hazycora 2 months ago
parent a1edff3f15
commit 7dfc7d77a2
Signed by: h
GPG Key ID: 215AF1F81F86940E

@ -10,14 +10,8 @@ dotenv.config()
const FILES_GAY_USER = process.env.FILES_GAY_USER??null
const FILES_GAY_PASS = process.env.FILES_GAY_PASS??null
const DISCORD_TOKEN = process.env.DISCORD_TOKEN
const CLSPOTIFY_PATH = process.env.CLSPOTIFY_PATH
let FILES_GAY_SESSION
if (!CLSPOTIFY_PATH) {
console.log('Please set the CLSPOTIFY_PATH environment variable.')
process.exit()
}
async function getFilesGaySession() {
if (!FILES_GAY_USER || !FILES_GAY_PASS) {
console.log('Not logged into files.gay. Uploading anonymously.')
@ -62,6 +56,7 @@ const bot = new Client({
})
bot.on("ready", async () => { // When the bot is ready
await spDl.login(process.env.SPOTIFY_USERNAME, process.env.SPOTIFY_PASSWORD)
await getFilesGaySession() // Get the files.gay session
await bot.application.bulkEditGlobalCommands([
{
@ -100,32 +95,20 @@ async function getSpotifyMetadata(url) {
}
async function downloadAndUpdateMessage(url, editMsg) {
let metadata
try {
metadata = await getSpotifyMetadata(url)
} catch (error) {
metadata = {
unknown: true,
title: 'Unknown',
author: 'Unknown',
type: 'Unknown'
}
}
let messageStartText = ''
let itemName = 'the resource'
if (!metadata.unknown) {
itemName = `*${metadata.title}* by *${metadata.author}*`
messageStartText = `Downloading ${itemName} `
let metadataRaw = await spDl.getMetadata(url)
let metadata = {
title: metadataRaw.name??metadataRaw.albumName??metadataRaw.playlistName??metadataRaw.showName,
author: metadataRaw.artist??metadataRaw.albumArtist??metadataRaw.playlistOwner??metadataRaw.publisher,
}
let itemName = `*${metadata.title}* by *${metadata.author}*`
let messageStartText = `Downloading ${itemName} `
let randomId = generateRandomId()
const albumFolderPath = `${ripsPath}/${randomId}`
await fs.promises.mkdir(albumFolderPath)
try {
await spDl(url, albumFolderPath, {
clspotifyPath: CLSPOTIFY_PATH,
await spDl.download(url, albumFolderPath, {
onProgress: (dat) => {
if (dat.percent===100) return
let text = `${messageStartText}${dat.percent}%`
@ -158,10 +141,7 @@ async function downloadAndUpdateMessage(url, editMsg) {
fs.promises.rm(albumFolderPath, {recursive: true})
await editMsg(`Finished downloading ${itemName}.\nCompressed. The zip file is ${new Intl.NumberFormat().format(Math.round(archive.pointer() / 1000000))} Megabytes.\nUploading to files.gay`)
const form = new FormData()
let filename = 'album.zip'
if (!metadata.unknown) {
filename = metadata.title.replace(/[^a-zA-z0-9 \-_]/gm, '-')+'.zip'
}
let filename = metadata.title.replace(/[^a-zA-z0-9 \-_]/gm, '-')+'.zip'
const file = new File([await fs.promises.readFile(zipFilePath)], filename)
form.set('file', file)
@ -178,11 +158,7 @@ async function downloadAndUpdateMessage(url, editMsg) {
await editMsg('Something went wrong uploading the file. :(')
return
}
if (!metadata.unknown) {
await editMsg(`Finished! Download ${itemName} at: https://files.gay/f/${respJson.data.id}/dl`)
} else {
await editMsg(`Finished! Download at: https://files.gay/f/${respJson.data.id}`)
}
await editMsg(`Finished! Download ${itemName} at: https://files.gay/f/${respJson.data.id}/dl`)
await fs.promises.rm(zipFilePath)
})
archive.directory(albumFolderPath, false)

182
package-lock.json generated

@ -48,6 +48,20 @@
"@types/node": "*"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/archiver": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/archiver/-/archiver-5.3.1.tgz",
@ -202,6 +216,42 @@
"node": ">=10.16.0"
}
},
"node_modules/caller": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/caller/-/caller-1.1.0.tgz",
"integrity": "sha512-n+21IZC3j06YpCWaxmUy5AnVqhmCIM2bQtqQyy00HJlmStRt6kwDX5F9Z97pqwAB+G/tgSz6q/kUBbNyQzIubw=="
},
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/compress-commons": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-4.1.1.tgz",
@ -366,6 +416,14 @@
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
@ -650,9 +708,45 @@
]
},
"node_modules/spotify-dl": {
"version": "2.0.0",
"resolved": "git+https://git.gay/h/spotify-dl.git#307390148f1006c68b9bd473dcf60b9f5f44cfd7",
"license": "ISC",
"dependencies": {
"pythonia": "^1.0.0"
}
},
"node_modules/spotify-dl/node_modules/pythonia": {
"version": "1.0.0",
"resolved": "git+https://git.gay/h/spotify-dl.git#5cae087693ee7cf24571929da01304958ebe15d0",
"license": "ISC"
"resolved": "https://registry.npmjs.org/pythonia/-/pythonia-1.0.0.tgz",
"integrity": "sha512-DMpVciipMnHSpSVSGTjdTla3JEKCXIqLMdgV9H+a5XUMrMv5pD8L3xBHiZI65a/K4pc7DFZ92ezkLGeW+Rfm1g==",
"dependencies": {
"caller": "^1.0.1",
"chalk": "^4.1.2"
},
"peerDependencies": {
"ws": "^7.5.1"
}
},
"node_modules/spotify-dl/node_modules/ws": {
"version": "7.5.9",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz",
"integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==",
"peer": true,
"engines": {
"node": ">=8.3.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/streamsearch": {
"version": "1.1.0",
@ -670,6 +764,17 @@
"safe-buffer": "~5.2.0"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/tar-stream": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",
@ -783,6 +888,14 @@
"@types/node": "*"
}
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"requires": {
"color-convert": "^2.0.1"
}
},
"archiver": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/archiver/-/archiver-5.3.1.tgz",
@ -899,6 +1012,33 @@
"streamsearch": "^1.1.0"
}
},
"caller": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/caller/-/caller-1.1.0.tgz",
"integrity": "sha512-n+21IZC3j06YpCWaxmUy5AnVqhmCIM2bQtqQyy00HJlmStRt6kwDX5F9Z97pqwAB+G/tgSz6q/kUBbNyQzIubw=="
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"compress-commons": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-4.1.1.tgz",
@ -1019,6 +1159,11 @@
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
},
"ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
@ -1217,8 +1362,29 @@
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"spotify-dl": {
"version": "git+https://git.gay/h/spotify-dl.git#5cae087693ee7cf24571929da01304958ebe15d0",
"from": "spotify-dl@git+https://git.gay/h/spotify-dl.git"
"version": "git+https://git.gay/h/spotify-dl.git#307390148f1006c68b9bd473dcf60b9f5f44cfd7",
"from": "spotify-dl@git+https://git.gay/h/spotify-dl.git",
"requires": {
"pythonia": "^1.0.0"
},
"dependencies": {
"pythonia": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/pythonia/-/pythonia-1.0.0.tgz",
"integrity": "sha512-DMpVciipMnHSpSVSGTjdTla3JEKCXIqLMdgV9H+a5XUMrMv5pD8L3xBHiZI65a/K4pc7DFZ92ezkLGeW+Rfm1g==",
"requires": {
"caller": "^1.0.1",
"chalk": "^4.1.2"
}
},
"ws": {
"version": "7.5.9",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz",
"integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==",
"peer": true,
"requires": {}
}
}
},
"streamsearch": {
"version": "1.1.0",
@ -1233,6 +1399,14 @@
"safe-buffer": "~5.2.0"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"requires": {
"has-flag": "^4.0.0"
}
},
"tar-stream": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",

Loading…
Cancel
Save