first release
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
const { spawn } = require('child_process');
|
||||
const logger = require('./logger');
|
||||
const settings = require('../settings.json');
|
||||
let settings;
|
||||
|
||||
try {
|
||||
settings = require('../settings.json');
|
||||
}
|
||||
catch (e) {
|
||||
console.warn("settings.json not found")
|
||||
}
|
||||
|
||||
const download = (socket, url) => {
|
||||
const ytldp = spawn('./lib/yt-dlp.exe',
|
||||
['-o', `${settings.download_path}%(title)s.%(ext)s`, url]
|
||||
['-o', `${settings.download_path || './downloads/'}%(title)s.%(ext)s`, url]
|
||||
)
|
||||
|
||||
ytldp.stdout.on('data', data => {
|
||||
@@ -27,12 +34,6 @@ const abortDownload = (socket) => {
|
||||
logger('download', 'Aborted')
|
||||
}
|
||||
|
||||
const kill = async () => {
|
||||
return process.platform === 'win32' ?
|
||||
spawn('taskkill', ['/IM', 'yt-dlp.exe', '/F', '/T']) :
|
||||
spawn('killall', ['yt-dlp'])
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
download: download,
|
||||
abortDownload: abortDownload
|
||||
|
||||
19
lib/event.js
19
lib/event.js
@@ -1,19 +0,0 @@
|
||||
var Transform = require('stream').Transform;
|
||||
|
||||
class SSE extends Transform{
|
||||
constructor(options) {
|
||||
super();
|
||||
|
||||
if (!(this instanceof SSE))
|
||||
return new SSE(options);
|
||||
|
||||
options = options || {};
|
||||
Transform.call(this, options);
|
||||
}
|
||||
_transform(data, enc, cb) {
|
||||
this.push('data: ' + data.toString('utf8') + '\n\n');
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SSE;
|
||||
16
lib/fetch-yt-dlp.js
Normal file
16
lib/fetch-yt-dlp.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const https = require('https');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
const file = fs.createWriteStream(path.join(
|
||||
__dirname, `yt-dlp${isWindows ? '.exe' : ''}`
|
||||
));
|
||||
|
||||
https.get(
|
||||
isWindows ?
|
||||
'https://github.com/yt-dlp/yt-dlp/releases/download/2021.11.10.1/yt-dlp.exe' :
|
||||
'https://github.com/yt-dlp/yt-dlp/releases/download/2021.11.10.1/yt-dlp',
|
||||
res => res.pipe(file)
|
||||
);
|
||||
Reference in New Issue
Block a user