filename override, addressing #22

This commit is contained in:
2023-01-07 12:04:07 +01:00
parent 97eb686eb1
commit 3754750f61
7 changed files with 324 additions and 169 deletions

View File

@@ -23,6 +23,7 @@ class Process {
private pid: number;
private metadata?: IDownloadMetadata;
private exePath = join(__dirname, 'yt-dlp');
private customFileName?: string;
private readonly template = `download:
{
@@ -34,13 +35,14 @@ class Process {
.replace(/\s\s+/g, ' ')
.replace('\n', '');
constructor(url: string, params: Array<string>, settings: any) {
constructor(url: string, params: Array<string>, settings: any, customFileName?: string) {
this.url = url;
this.params = params || [];
this.settings = settings
this.stdout = undefined;
this.pid = undefined;
this.metadata = undefined;
this.customFileName = customFileName;
}
/**
@@ -59,7 +61,7 @@ class Process {
const ytldp = spawn(this.exePath,
[
'-o', `${this.settings?.download_path || 'downloads/'}%(title)s.%(ext)s`,
'-o', `${this.settings?.download_path || 'downloads/'}${this.customFileName || '%(title)s'}.%(ext)s`,
'--progress-template', this.template,
'--no-colors',
]
@@ -73,6 +75,10 @@ class Process {
log.info('proc', `Spawned a new process, pid: ${this.pid}`)
if (callback) {
callback()
}
return this;
}

View File

@@ -62,12 +62,14 @@ export async function download(socket: Socket, payload: IPayload) {
payload.params.split(' ') :
payload.params;
const renameTo = payload.renameTo
const scopedSettings: ISettings = {
...settings,
download_path: payload.path
}
let p = new Process(url, params, scopedSettings);
let p = new Process(url, params, scopedSettings, renameTo);
p.start().then(downloader => {
mem_db.add(downloader)
@@ -114,7 +116,7 @@ function streamProcess(process: Process, socket: Socket) {
});
}
from(process.getStdout().removeAllListeners()) // stdout as observable
from(process.getStdout().removeAllListeners()) // stdout as observable
.pipe(
throttle(() => interval(500)), // discard events closer than 500ms
map(stdout => formatter(String(stdout), process.getPid()))

View File

@@ -4,9 +4,10 @@
export interface IPayload {
url: string
params: Array<string> | string,
path: string,
title?: string,
thumbnail?: string,
size?: string,
params: Array<string> | string
path: string
title?: string
thumbnail?: string
size?: string
renameTo?: string
}