update: fix stout bursts
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const { spawn } = require('child_process');
|
||||
const logger = require('./logger');
|
||||
const { from, interval } = require('rxjs');
|
||||
const { throttle } = require('rxjs/operators');
|
||||
let settings;
|
||||
|
||||
try {
|
||||
@@ -16,8 +18,15 @@ const download = (socket, url) => {
|
||||
['-o', `${settings.download_path || 'downloads/'}%(title)s.%(ext)s`, url]
|
||||
)
|
||||
ytldp.stdout.on('data', data => {
|
||||
socket.emit('progress', data.toString())
|
||||
logger('download', `Fetching ${data.toString()}`)
|
||||
// reactive programming magic
|
||||
from(Promise.resolve(data)) // stout as promise => Observable
|
||||
.pipe(throttle(() => interval(500))) // discard events closer than 500ms
|
||||
.subscribe({
|
||||
next: () => {
|
||||
socket.emit('progress', data.toString()) // finally, emit
|
||||
logger('download', `Fetching ${data.toString()}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
ytldp.on('exit', () => {
|
||||
socket.emit('progress', 'Done!')
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
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