refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { spawn } = require('child_process')
|
||||
const logger = require('./logger')
|
||||
let settings
|
||||
const { spawn } = require('child_process');
|
||||
const logger = require('./logger');
|
||||
let settings;
|
||||
|
||||
try {
|
||||
settings = require('../settings.json')
|
||||
@@ -13,14 +13,15 @@ const isWindows = process.platform === 'win32'
|
||||
|
||||
const download = (socket, url) => {
|
||||
const ytldp = spawn(`./lib/yt-dlp${isWindows ? '.exe' : ''}`,
|
||||
['-o', `${settings.download_path || './downloads/'}%(title)s.%(ext)s`, url]
|
||||
['-o', `${settings.download_path || 'downloads/'}%(title)s.%(ext)s`, url]
|
||||
)
|
||||
ytldp.stdout.on('data', data => {
|
||||
socket.emit('progress', data.toString())
|
||||
console.log(data.toString())
|
||||
logger('download', `Fetching ${data.toString()}`)
|
||||
})
|
||||
ytldp.on('exit', () => {
|
||||
socket.emit('progress', 'Done!')
|
||||
logger('download', 'Done!')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ const abortDownload = (socket) => {
|
||||
spawn('killall', ['yt-dlp'])
|
||||
res.stdout.on('data', data => {
|
||||
socket.emit('progress', 'Aborted!')
|
||||
console.log(data.toString())
|
||||
logger('download', `Aborting ${data.toString()}`)
|
||||
})
|
||||
logger('download', 'Aborted')
|
||||
}
|
||||
|
||||
15
lib/fetch-yt-dlp.sh
Executable file
15
lib/fetch-yt-dlp.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
echo "Downloading latest yt-dlp..."
|
||||
|
||||
rm -f yt-dlp
|
||||
|
||||
RELEASE=$(curl --silent "https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest" |
|
||||
grep '"tag_name":' |
|
||||
sed -E 's/.*"([^"]+)".*/\1/'
|
||||
)
|
||||
|
||||
wget "https://github.com/yt-dlp/yt-dlp/releases/download/$RELEASE/yt-dlp"
|
||||
|
||||
chmod +x yt-dlp
|
||||
|
||||
echo "Done!"
|
||||
Reference in New Issue
Block a user