diff --git a/backend/app.js b/backend/app.js index 178fd98..758af3d 100644 --- a/backend/app.js +++ b/backend/app.js @@ -590,17 +590,6 @@ function generateEnvVarConfigItem(key) { return {key: key, value: process['env'][key]}; } -// currently only works for single urls -async function getUrlInfos(url) { - const {parsed_output, err} = await youtubedl_api.runYoutubeDL(url, ['--dump-json']); - if (!parsed_output || parsed_output.length !== 1) { - logger.error(`Failed to retrieve available formats for url: ${url}`); - if (err) logger.error(err); - return null; - } - return parsed_output[0]; -} - // youtube-dl functions async function startYoutubeDL() { @@ -1871,11 +1860,11 @@ app.post('/api/clearAllLogs', optionalJwt, async function(req, res) { }); app.post('/api/getFileFormats', optionalJwt, async (req, res) => { - let url = req.body.url; - let result = await getUrlInfos(url); + const url = req.body.url; + const result = await downloader_api.getVideoInfoByURL(url); res.send({ - result: result, - success: !!result + result: result && result.length === 1 ? result[0] : null, + success: result && result.length === 0 }) }); diff --git a/backend/youtube-dl.js b/backend/youtube-dl.js index f9bf5e4..7dcd9e3 100644 --- a/backend/youtube-dl.js +++ b/backend/youtube-dl.js @@ -118,10 +118,16 @@ async function downloadLatestYoutubeDLBinaryGeneric(youtubedl_fork, new_version, const download_url = `${exports.youtubedl_forks[youtubedl_fork]['download_url']}${file_ext}`; const output_path = custom_output_path || getYoutubeDLPath(youtubedl_fork); - await utils.fetchFile(download_url, output_path, `${youtubedl_fork} ${new_version}`); - fs.chmod(output_path, 0o777); - - updateDetailsJSON(new_version, youtubedl_fork, output_path); + try { + await utils.fetchFile(download_url, output_path, `${youtubedl_fork} ${new_version}`); + fs.chmod(output_path, 0o777); + + updateDetailsJSON(new_version, youtubedl_fork, output_path); + } catch (e) { + logger.error(`Failed to download new ${youtubedl_fork} version: ${new_version}`); + logger.error(e); + return; + } } exports.getLatestUpdateVersion = async (youtubedl_fork) => { diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 3a4058b..fb6e656 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -548,7 +548,7 @@ export class MainComponent implements OnInit { } if (!(this.cachedAvailableFormats[url] && this.cachedAvailableFormats[url]['formats'])) { this.cachedAvailableFormats[url]['formats_loading'] = true; - this.postsService.getFileFormats([url]).subscribe(res => { + this.postsService.getFileFormats(url).subscribe(res => { this.cachedAvailableFormats[url]['formats_loading'] = false; const infos = res['result']; if (!infos || !infos.formats) { diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 7bde6d9..d4884e0 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -460,7 +460,7 @@ export class PostsService implements CanActivate { return this.http.post(this.path + 'deleteArchiveItems', body, this.httpOptions); } - getFileFormats(url) { + getFileFormats(url: string) { const body: GetFileFormatsRequest = {url: url}; return this.http.post(this.path + 'getFileFormats', body, this.httpOptions); }