mirror of
https://github.com/Expand-sys/spotdlweb
synced 2025-12-15 13:32:25 +11:00
aaa
This commit is contained in:
parent
3e83c2c0de
commit
05e7d22776
6 changed files with 103 additions and 29 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
.env
|
||||
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
67
index.ts
67
index.ts
|
|
@ -1,8 +1,15 @@
|
|||
const fastify = require('fastify')({
|
||||
logger: true
|
||||
logger: false
|
||||
})
|
||||
const path = require("path");
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs")
|
||||
const Spotify = require('spotifydl-core').default
|
||||
const credentials = {
|
||||
clientId: process.env.clientID,
|
||||
clientSecret: process.env.clientSecret
|
||||
}
|
||||
const spotify = new Spotify(credentials)
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
|
||||
|
|
@ -14,7 +21,16 @@ fastify.register(require("@fastify/view"), {
|
|||
pug: require("pug")
|
||||
}
|
||||
});
|
||||
|
||||
fastify.register(require("fastify-socket.io"), {
|
||||
cors: {
|
||||
origin: "*:*",
|
||||
methods: ["GET", "POST"]
|
||||
}
|
||||
})
|
||||
fastify.register(require('@fastify/formbody'))
|
||||
await fastify.register(require("@fastify/cors"), {
|
||||
origin: true
|
||||
})
|
||||
|
||||
fastify.register(require("@fastify/static"), {
|
||||
root: path.join(__dirname,"public"),
|
||||
|
|
@ -22,14 +38,55 @@ fastify.register(require("@fastify/static"), {
|
|||
});
|
||||
|
||||
|
||||
// Declare a route
|
||||
fastify.get('/', function (request: any, reply: any) {
|
||||
reply.view('views/index.pug',{
|
||||
request: request
|
||||
})
|
||||
})
|
||||
|
||||
fastify.listen({ port: 3000 }, function (err: any, address: any) {
|
||||
|
||||
fastify.post('/download', function (request: any, reply: any) {
|
||||
reply.view('views/download.pug',{
|
||||
body: request.body
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
fastify.ready((err) => {
|
||||
if (err) throw err;
|
||||
|
||||
|
||||
console.log("ready")
|
||||
|
||||
fastify.io.on("connect", (socket:any) => {
|
||||
console.log("connected")
|
||||
socket.on("message", (socket:any) => {
|
||||
console.log("eans")
|
||||
console.log(socket)
|
||||
})
|
||||
socket.on("submit", async (socket:any) => {
|
||||
if(socket.option == "Single"){
|
||||
const details = await spotify.getTrack(socket.URL)
|
||||
console.log(details)
|
||||
const song = await spotify.downloadTrack(socket.URL)
|
||||
console.log(song)
|
||||
let filepath = path.join(__dirname,"public/download/${details.name}-${details.artists[0]}")
|
||||
fs.writeFileSync(filepath, song)
|
||||
}
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
fastify.io.on("connect_error", (err) => {
|
||||
console.log(`connect_error due to ${err.message}`);
|
||||
});
|
||||
|
||||
|
||||
fastify.listen({ port: 3000, host: "127.0.0.1" }, function (err: any, address: any) {
|
||||
if (err) {
|
||||
fastify.log.error(err)
|
||||
process.exit(1)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "spotdlweb",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"bun-types": "latest"
|
||||
},
|
||||
|
|
@ -9,10 +8,16 @@
|
|||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^8.4.0",
|
||||
"@fastify/formbody": "^7.4.0",
|
||||
"@fastify/static": "^6.11.2",
|
||||
"@fastify/view": "^8.2.0",
|
||||
"fastify": "^4.23.2",
|
||||
"fastify-socket.io": "^5.0.0",
|
||||
"path": "^0.12.7",
|
||||
"pug": "^3.0.2"
|
||||
"pug": "^3.0.2",
|
||||
"socket.io": "^4.7.2",
|
||||
"spotify-dl": "^1.1.2",
|
||||
"spotifydl-core": "^0.2.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -5,24 +5,36 @@ block content
|
|||
.container
|
||||
h1 SO YE WANT TO PIRATE SOM MUSIC???
|
||||
.card.shadow-lg
|
||||
form(action='/add_movie', method='POST')
|
||||
form(action='submit', id="form")
|
||||
p
|
||||
| URL:
|
||||
input(type='text', name='URL', value='')
|
||||
| Spotify username:
|
||||
input(type='text', name='USR', value='')
|
||||
| Spotify Password:
|
||||
input(type='text', name='PASS', value='')
|
||||
p
|
||||
|
|
||||
input(class="form" type='text', name='URL', value='')
|
||||
p Type
|
||||
select(name="option" class="form")
|
||||
option(value="Single") Single
|
||||
option(value="Playlist") Playlist
|
||||
br
|
||||
|
||||
input#html(type='radio' name='fav_language' value='HTML')
|
||||
label(for='html') HTML
|
||||
br
|
||||
input#css(type='radio' name='fav_language' value='CSS')
|
||||
label(for='css') CSS
|
||||
br
|
||||
input#javascript(type='radio' name='fav_language' value='JavaScript')
|
||||
label(for='javascript') JavaScript
|
||||
br
|
||||
input(type='submit', value='Submit')
|
||||
input#testButton(type='submit', value='Submit')
|
||||
script(src="https://code.jquery.com/jquery-3.7.1.min.js")
|
||||
script(src='socket.io/socket.io.js')
|
||||
script(type='module').
|
||||
let socket = io.connect();
|
||||
socket.on("connect", function(data) {
|
||||
const form = document.getElementById('form');
|
||||
const elements = document.getElementsByClassName("form");
|
||||
let array = [];
|
||||
let obj = {}
|
||||
for(var i = 0; i < elements.length; i++) {
|
||||
obj[elements[i].name] = elements[i].value;
|
||||
}
|
||||
|
||||
console.log(elements)
|
||||
$('#testButton').click(function(event) {
|
||||
event.preventDefault();
|
||||
socket.emit('submit', obj);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
|
@ -6,6 +6,8 @@ html
|
|||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
|
||||
link(rel="preconnect" href="https://fonts.gstatic.com")
|
||||
link(href="https://fonts.googleapis.com/css2?family=Lato&family=Montserrat&display=swap" rel="stylesheet")
|
||||
|
||||
|
||||
|
||||
body
|
||||
nav.navbar.navbar-expand-lg.navbar-dark.shadow-lg
|
||||
|
|
@ -28,8 +30,4 @@ html
|
|||
br
|
||||
block content
|
||||
br
|
||||
hr
|
||||
|
||||
script(src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI="
|
||||
crossorigin="anonymous")
|
||||
script(src='/js/main.js')
|
||||
hr
|
||||
Loading…
Reference in a new issue