mirror of
https://github.com/Expand-sys/spotdlweb
synced 2026-03-22 11:17:07 +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')({
|
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 { fileURLToPath } from 'url';
|
||||||
import { dirname } from 'path';
|
import { dirname } from 'path';
|
||||||
|
|
||||||
|
|
@ -14,7 +21,16 @@ fastify.register(require("@fastify/view"), {
|
||||||
pug: require("pug")
|
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"), {
|
fastify.register(require("@fastify/static"), {
|
||||||
root: path.join(__dirname,"public"),
|
root: path.join(__dirname,"public"),
|
||||||
|
|
@ -22,14 +38,55 @@ fastify.register(require("@fastify/static"), {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Declare a route
|
|
||||||
fastify.get('/', function (request: any, reply: any) {
|
fastify.get('/', function (request: any, reply: any) {
|
||||||
reply.view('views/index.pug',{
|
reply.view('views/index.pug',{
|
||||||
request: request
|
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) {
|
if (err) {
|
||||||
fastify.log.error(err)
|
fastify.log.error(err)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "spotdlweb",
|
"name": "spotdlweb",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bun-types": "latest"
|
"bun-types": "latest"
|
||||||
},
|
},
|
||||||
|
|
@ -9,10 +8,16 @@
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@fastify/cors": "^8.4.0",
|
||||||
|
"@fastify/formbody": "^7.4.0",
|
||||||
"@fastify/static": "^6.11.2",
|
"@fastify/static": "^6.11.2",
|
||||||
"@fastify/view": "^8.2.0",
|
"@fastify/view": "^8.2.0",
|
||||||
"fastify": "^4.23.2",
|
"fastify": "^4.23.2",
|
||||||
|
"fastify-socket.io": "^5.0.0",
|
||||||
"path": "^0.12.7",
|
"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
|
.container
|
||||||
h1 SO YE WANT TO PIRATE SOM MUSIC???
|
h1 SO YE WANT TO PIRATE SOM MUSIC???
|
||||||
.card.shadow-lg
|
.card.shadow-lg
|
||||||
form(action='/add_movie', method='POST')
|
form(action='submit', id="form")
|
||||||
p
|
p
|
||||||
| URL:
|
| URL:
|
||||||
input(type='text', name='URL', value='')
|
input(class="form" type='text', name='URL', value='')
|
||||||
| Spotify username:
|
p Type
|
||||||
input(type='text', name='USR', value='')
|
select(name="option" class="form")
|
||||||
| Spotify Password:
|
option(value="Single") Single
|
||||||
input(type='text', name='PASS', value='')
|
option(value="Playlist") Playlist
|
||||||
p
|
br
|
||||||
|
|
|
||||||
|
|
||||||
input#html(type='radio' name='fav_language' value='HTML')
|
|
||||||
label(for='html') HTML
|
|
||||||
br
|
br
|
||||||
input#css(type='radio' name='fav_language' value='CSS')
|
input#testButton(type='submit', value='Submit')
|
||||||
label(for='css') CSS
|
script(src="https://code.jquery.com/jquery-3.7.1.min.js")
|
||||||
br
|
script(src='socket.io/socket.io.js')
|
||||||
input#javascript(type='radio' name='fav_language' value='JavaScript')
|
script(type='module').
|
||||||
label(for='javascript') JavaScript
|
let socket = io.connect();
|
||||||
br
|
socket.on("connect", function(data) {
|
||||||
input(type='submit', value='Submit')
|
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);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,6 +7,8 @@ html
|
||||||
link(rel="preconnect" href="https://fonts.gstatic.com")
|
link(rel="preconnect" href="https://fonts.gstatic.com")
|
||||||
link(href="https://fonts.googleapis.com/css2?family=Lato&family=Montserrat&display=swap" rel="stylesheet")
|
link(href="https://fonts.googleapis.com/css2?family=Lato&family=Montserrat&display=swap" rel="stylesheet")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
body
|
body
|
||||||
nav.navbar.navbar-expand-lg.navbar-dark.shadow-lg
|
nav.navbar.navbar-expand-lg.navbar-dark.shadow-lg
|
||||||
.container
|
.container
|
||||||
|
|
@ -29,7 +31,3 @@ html
|
||||||
block content
|
block content
|
||||||
br
|
br
|
||||||
hr
|
hr
|
||||||
|
|
||||||
script(src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI="
|
|
||||||
crossorigin="anonymous")
|
|
||||||
script(src='/js/main.js')
|
|
||||||
Loading…
Reference in a new issue