From a1b32e2851824b1b644e9ee7a21e5f201b764d42 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Wed, 20 Jan 2021 08:32:16 -0500 Subject: [PATCH 1/4] Added yt-dlp support Simplified update youtube-dl code --- backend/app.js | 58 +++++++++++++++++------- src/app/settings/settings.component.html | 3 +- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/backend/app.js b/backend/app.js index 04edd6a..209906e 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1659,11 +1659,24 @@ async function startYoutubeDL() { // auto updates the underlying youtube-dl binary, not YoutubeDL-Material async function autoUpdateYoutubeDL() { + const download_sources = { + 'youtube-dl': { + 'tags_url': 'https://api.github.com/repos/ytdl-org/youtube-dl/tags', + 'func': downloadLatestYoutubeDLBinary + }, + 'youtube-dlc': { + 'tags_url': 'https://api.github.com/repos/blackjack4494/yt-dlc/tags', + 'func': downloadLatestYoutubeDLCBinary + }, + 'yt-dlp': { + 'tags_url': 'https://api.github.com/repos/pukkandan/yt-dlp/tags', + 'func': downloadLatestYoutubeDLPBinary + } + } return new Promise(async resolve => { const default_downloader = config_api.getConfigItem('ytdl_default_downloader'); const using_youtube_dlc = default_downloader === 'youtube-dlc'; - const youtube_dl_tags_url = 'https://api.github.com/repos/ytdl-org/youtube-dl/tags' - const youtube_dlc_tags_url = 'https://api.github.com/repos/blackjack4494/yt-dlc/tags' + const tags_url = download_sources[default_downloader]['tags_url']; // get current version let current_app_details_path = 'node_modules/youtube-dl/bin/details'; let current_app_details_exists = fs.existsSync(current_app_details_path); @@ -1674,6 +1687,7 @@ async function autoUpdateYoutubeDL() { } let current_app_details = JSON.parse(fs.readFileSync(current_app_details_path)); let current_version = current_app_details['version']; + let current_downloader = current_app_details['downloader']; let stored_binary_path = current_app_details['path']; if (!stored_binary_path || typeof stored_binary_path !== 'string') { // logger.info(`INFO: Failed to get youtube-dl binary path at location: ${current_app_details_path}, attempting to guess actual path...`); @@ -1690,15 +1704,9 @@ async function autoUpdateYoutubeDL() { } // got version, now let's check the latest version from the youtube-dl API - let youtubedl_api_path = using_youtube_dlc ? youtube_dlc_tags_url : youtube_dl_tags_url; - if (default_downloader === 'youtube-dl') { - await downloadLatestYoutubeDLBinary('unknown', 'unknown'); - resolve(true); - return; - } - fetch(youtubedl_api_path, {method: 'Get'}) + fetch(tags_url, {method: 'Get'}) .then(async res => res.json()) .then(async (json) => { // check if the versions are different @@ -1708,16 +1716,16 @@ async function autoUpdateYoutubeDL() { return false; } const latest_update_version = json[0]['name']; - if (current_version !== latest_update_version) { - // versions different, download new update + if (current_version !== latest_update_version || default_downloader !== current_downloader) { + // versions different or different downloader is being used, download new update logger.info(`Found new update for ${default_downloader}. Updating binary...`); try { await checkExistsWithTimeout(stored_binary_path, 10000); } catch(e) { logger.error(`Failed to update ${default_downloader} - ${e}`); } - if (using_youtube_dlc) await downloadLatestYoutubeDLCBinary(latest_update_version); - else await downloadLatestYoutubeDLBinary(current_version, latest_update_version); + + await download_sources[default_downloader]['func'](latest_update_version); resolve(true); } else { @@ -1731,7 +1739,7 @@ async function autoUpdateYoutubeDL() { }); } -async function downloadLatestYoutubeDLBinary(current_version, new_version) { +async function downloadLatestYoutubeDLBinary() { return new Promise(resolve => { let binary_path = 'node_modules/youtube-dl/bin'; downloader(binary_path, function error(err, done) { @@ -1741,6 +1749,7 @@ async function downloadLatestYoutubeDLBinary(current_version, new_version) { resolve(false); } logger.info(`youtube-dl successfully updated!`); + updateDetailsJSON(null, 'youtube-dl'); resolve(true); }); }); @@ -1754,10 +1763,25 @@ async function downloadLatestYoutubeDLCBinary(new_version) { await fetchFile(download_url, output_path, `youtube-dlc ${new_version}`); - const details_path = 'node_modules/youtube-dl/bin/details'; - const details_json = fs.readJSONSync('node_modules/youtube-dl/bin/details'); - details_json['version'] = new_version; + updateDetailsJSON(new_version, 'youtube-dlc'); +} +async function downloadLatestYoutubeDLPBinary(new_version) { + const file_ext = is_windows ? '.exe' : ''; + + const download_url = `https://github.com/pukkandan/yt-dlp/releases/latest/download/youtube-dlc${file_ext}`; + const output_path = `node_modules/youtube-dl/bin/youtube-dl${file_ext}`; + + await fetchFile(download_url, output_path, `yt-dlp ${new_version}`); + + updateDetailsJSON(new_version, 'yt-dlp'); +} + +function updateDetailsJSON(new_version, downloader) { + const details_path = 'node_modules/youtube-dl/bin/details'; + const details_json = fs.readJSONSync(details_path); + if (new_version) details_json['version'] = new_version; + details_json['downloader'] = downloader; fs.writeJSONSync(details_path, details_json); } diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index bd085b1..fe7d81c 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -286,8 +286,9 @@ Select a downloader - youtube-dlc youtube-dl + youtube-dlc + yt-dlp From c660c284229be2c6f0132aa9c2ca8439d6871a17 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Mon, 22 Feb 2021 12:53:21 -0700 Subject: [PATCH 2/4] youtube-dl now updates in the same way as the other forks --- backend/app.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/backend/app.js b/backend/app.js index 209906e..e639ff1 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1681,9 +1681,8 @@ async function autoUpdateYoutubeDL() { let current_app_details_path = 'node_modules/youtube-dl/bin/details'; let current_app_details_exists = fs.existsSync(current_app_details_path); if (!current_app_details_exists) { - logger.error(`Failed to get youtube-dl binary details at location '${current_app_details_path}'. Cancelling update check.`); - resolve(false); - return; + logger.warn(`Failed to get youtube-dl binary details at location '${current_app_details_path}'. Generating file...`); + fs.writeJSONSync('node_modules/youtube-dl/bin/details', {"version":"2020.00.00", "downloader": default_downloader}); } let current_app_details = JSON.parse(fs.readFileSync(current_app_details_path)); let current_version = current_app_details['version']; @@ -1739,20 +1738,15 @@ async function autoUpdateYoutubeDL() { }); } -async function downloadLatestYoutubeDLBinary() { - return new Promise(resolve => { - let binary_path = 'node_modules/youtube-dl/bin'; - downloader(binary_path, function error(err, done) { - if (err) { - logger.error(`youtube-dl failed to update. Restart the server to try again.`); - logger.error(err); - resolve(false); - } - logger.info(`youtube-dl successfully updated!`); - updateDetailsJSON(null, 'youtube-dl'); - resolve(true); - }); - }); +async function downloadLatestYoutubeDLBinary(new_version) { + const file_ext = is_windows ? '.exe' : ''; + + const download_url = `https://github.com/ytdl-org/youtube-dl/releases/latest/download/youtube-dl${file_ext}`; + const output_path = `node_modules/youtube-dl/bin/youtube-dl${file_ext}`; + + await fetchFile(download_url, output_path, `youtube-dl ${new_version}`); + + updateDetailsJSON(new_version, 'youtube-dl'); } async function downloadLatestYoutubeDLCBinary(new_version) { From d11f77a6c9a6c8e420fb99153dbf383be70da58b Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Tue, 16 Mar 2021 22:16:57 -0600 Subject: [PATCH 3/4] Updated yt-dlp paths --- backend/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app.js b/backend/app.js index e639ff1..29781e7 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1669,7 +1669,7 @@ async function autoUpdateYoutubeDL() { 'func': downloadLatestYoutubeDLCBinary }, 'yt-dlp': { - 'tags_url': 'https://api.github.com/repos/pukkandan/yt-dlp/tags', + 'tags_url': 'https://api.github.com/repos/yt-dlp/yt-dlp/tags', 'func': downloadLatestYoutubeDLPBinary } } @@ -1763,7 +1763,7 @@ async function downloadLatestYoutubeDLCBinary(new_version) { async function downloadLatestYoutubeDLPBinary(new_version) { const file_ext = is_windows ? '.exe' : ''; - const download_url = `https://github.com/pukkandan/yt-dlp/releases/latest/download/youtube-dlc${file_ext}`; + const download_url = `https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp${file_ext}`; const output_path = `node_modules/youtube-dl/bin/youtube-dl${file_ext}`; await fetchFile(download_url, output_path, `yt-dlp ${new_version}`); From 160cffc737f4eb0d130988d65200ee0417ff9f0c Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Tue, 20 Jul 2021 22:09:40 -0600 Subject: [PATCH 4/4] Added support for yt-dlp's --no-clean-infojson --- backend/app.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/app.js b/backend/app.js index 144f33a..a0e01db 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1184,6 +1184,11 @@ async function generateArgs(url, type, options) { } downloadConfig = downloadConfig.concat(globalArgs.split(',,')); } + + const default_downloader = getCurrentDownloader() || config_api.getConfigItem('ytdl_default_downloader'); + if (default_downloader === 'yt-dlp') { + downloadConfig.push('--no-clean-infojson'); + } } @@ -1359,7 +1364,6 @@ async function autoUpdateYoutubeDL() { } return new Promise(async resolve => { const default_downloader = config_api.getConfigItem('ytdl_default_downloader'); - const using_youtube_dlc = default_downloader === 'youtube-dlc'; const tags_url = download_sources[default_downloader]['tags_url']; // get current version let current_app_details_path = 'node_modules/youtube-dl/bin/details'; @@ -1463,6 +1467,12 @@ function updateDetailsJSON(new_version, downloader) { fs.writeJSONSync(details_path, details_json); } +function getCurrentDownloader() { + const details_path = 'node_modules/youtube-dl/bin/details'; + const details_json = fs.readJSONSync(details_path); + return details_json['downloader']; +} + async function checkExistsWithTimeout(filePath, timeout) { return new Promise(function (resolve, reject) {