cache download metadata to speedup resume phase.
This commit is contained in:
@@ -20,6 +20,7 @@ class Process {
|
||||
private settings: ISettings;
|
||||
private stdout: Readable;
|
||||
private pid: number;
|
||||
private metadata?: IDownloadInfo;
|
||||
private exePath = join(__dirname, 'yt-dlp');
|
||||
|
||||
constructor(url: string, params: Array<string>, settings: any) {
|
||||
@@ -28,6 +29,7 @@ class Process {
|
||||
this.settings = settings
|
||||
this.stdout = undefined;
|
||||
this.pid = undefined;
|
||||
this.metadata = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +60,7 @@ class Process {
|
||||
* @returns Promise to the lock
|
||||
*/
|
||||
public getInfo(): Promise<IDownloadInfo> {
|
||||
if (!this.metadata) {
|
||||
let stdoutChunks = [];
|
||||
const ytdlpInfo = spawn(this.exePath, ['-j', this.url]);
|
||||
|
||||
@@ -70,7 +73,7 @@ class Process {
|
||||
try {
|
||||
const buffer = Buffer.concat(stdoutChunks);
|
||||
const json = JSON.parse(buffer.toString());
|
||||
resolve({
|
||||
const info = {
|
||||
formats: json.formats.map((format: IDownloadInfoSection) => {
|
||||
return {
|
||||
format_id: format.format_id ?? '',
|
||||
@@ -91,7 +94,9 @@ class Process {
|
||||
},
|
||||
thumbnail: json.thumbnail,
|
||||
title: json.title,
|
||||
});
|
||||
}
|
||||
resolve(info);
|
||||
this.metadata = info;
|
||||
|
||||
} catch (e) {
|
||||
reject('failed fetching formats, downloading best available');
|
||||
@@ -99,6 +104,8 @@ class Process {
|
||||
});
|
||||
})
|
||||
}
|
||||
return new Promise((resolve) => { resolve(this.metadata!) });
|
||||
}
|
||||
|
||||
/**
|
||||
* function that kills the current process
|
||||
|
||||
Reference in New Issue
Block a user