From b1385f451bcb8219332d4e6b7868308e5667efe7 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Sun, 1 Aug 2021 22:19:15 -0600 Subject: [PATCH] Added option to rate limit downloads Added option to force delay between videos in a subscription Fixed issue where file handle was maintained on files deleted through unsubscribing --- backend/app.js | 5 ++++ backend/appdata/default.json | 6 ++-- backend/config.js | 6 ++-- backend/consts.js | 8 +++++ backend/subscriptions.js | 31 +++++++++++++++++++- src/app/settings/settings.component.html | 37 +++++++++++++++++++----- 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/backend/app.js b/backend/app.js index 8074ff8..532d06a 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1114,6 +1114,11 @@ async function generateArgs(url, type, options) { } downloadConfig = downloadConfig.concat(globalArgs.split(',,')); } + + const rate_limit = config_api.getConfigItem('ytdl_download_rate_limit'); + if (rate_limit && downloadConfig.indexOf('-r') === -1 && downloadConfig.indexOf('--limit-rate') === -1) { + downloadConfig.push('-r', rate_limit); + } const default_downloader = utils.getCurrentDownloader() || config_api.getConfigItem('ytdl_default_downloader'); if (default_downloader === 'yt-dlp') { diff --git a/backend/appdata/default.json b/backend/appdata/default.json index b5d6b52..a6bb39c 100644 --- a/backend/appdata/default.json +++ b/backend/appdata/default.json @@ -12,7 +12,8 @@ "custom_args": "", "safe_download_override": false, "include_thumbnail": true, - "include_metadata": true + "include_metadata": true, + "download_rate_limit": "" }, "Extra": { "title_top": "YoutubeDL-Material", @@ -40,7 +41,8 @@ "allow_subscriptions": true, "subscriptions_base_path": "subscriptions/", "subscriptions_check_interval": "300", - "redownload_fresh_uploads": false + "redownload_fresh_uploads": false, + "download_delay": "" }, "Users": { "base_path": "users/", diff --git a/backend/config.js b/backend/config.js index d27e8cd..ec0935e 100644 --- a/backend/config.js +++ b/backend/config.js @@ -189,7 +189,8 @@ DEFAULT_CONFIG = { "custom_args": "", "safe_download_override": false, "include_thumbnail": true, - "include_metadata": true + "include_metadata": true, + "download_rate_limit": "" }, "Extra": { "title_top": "YoutubeDL-Material", @@ -217,7 +218,8 @@ DEFAULT_CONFIG = { "allow_subscriptions": true, "subscriptions_base_path": "subscriptions/", "subscriptions_check_interval": "300", - "redownload_fresh_uploads": false + "redownload_fresh_uploads": false, + "download_delay": "" }, "Users": { "base_path": "users/", diff --git a/backend/consts.js b/backend/consts.js index 36ffd7d..fc74b0c 100644 --- a/backend/consts.js +++ b/backend/consts.js @@ -42,6 +42,10 @@ let CONFIG_ITEMS = { 'key': 'ytdl_include_metadata', 'path': 'YoutubeDLMaterial.Downloader.include_metadata' }, + 'ytdl_download_rate_limit': { + 'key': 'ytdl_download_rate_limit', + 'path': 'YoutubeDLMaterial.Downloader.download_rate_limit' + }, // Extra 'ytdl_title_top': { @@ -130,6 +134,10 @@ let CONFIG_ITEMS = { 'key': 'ytdl_subscriptions_check_interval', 'path': 'YoutubeDLMaterial.Subscriptions.subscriptions_check_interval' }, + 'ytdl_subscriptions_download_delay': { + 'key': 'ytdl_subscriptions_download_delay', + 'path': 'YoutubeDLMaterial.Subscriptions.download_delay' + }, 'ytdl_subscriptions_redownload_fresh_uploads': { 'key': 'ytdl_subscriptions_redownload_fresh_uploads', 'path': 'YoutubeDLMaterial.Subscriptions.redownload_fresh_uploads' diff --git a/backend/subscriptions.js b/backend/subscriptions.js index 537c516..89f0ff6 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -149,6 +149,21 @@ async function unsubscribe(sub, deleteMode, user_uid = null) { let result_obj = { success: false, error: '' }; let id = sub.id; + + const sub_files = await db_api.getRecords('files', {sub_id: id}); + for (let i = 0; i < sub_files.length; i++) { + const sub_file = sub_files[i]; + if (config_api.descriptors[sub_file['uid']]) { + try { + for (let i = 0; i < config_api.descriptors[sub_file['uid']].length; i++) { + config_api.descriptors[sub_file['uid']][i].destroy(); + } + } catch(e) { + + } + } + } + await db_api.removeRecord('subscriptions', {id: id}); await db_api.removeAllRecords('files', {sub_id: id}); @@ -260,7 +275,7 @@ async function getVideosForSub(sub, user_uid = null) { const downloadConfig = await generateArgsForSubscription(sub, user_uid); // get videos - logger.verbose('Subscription: getting videos for subscription ' + sub.name); + logger.verbose(`Subscription: getting videos for subscription ${sub.name} with args: ${downloadConfig.join(',')}`); return new Promise(async resolve => { const preimported_file_paths = []; @@ -413,6 +428,20 @@ async function generateArgsForSubscription(sub, user_uid, redownload = false, de downloadConfig.push('--write-thumbnail'); } + const download_delay = config_api.getConfigItem('ytdl_subscriptions_download_delay'); + if (download_delay && downloadConfig.indexOf('--sleep-interval') === -1) { + if (!(+download_delay)) { + logger.warn(`Invalid download delay of ${download_delay}, please remember to use non-zero numbers.`); + } else { + downloadConfig.push('--sleep-interval', +download_delay); + } + } + + const rate_limit = config_api.getConfigItem('ytdl_download_rate_limit'); + if (rate_limit && downloadConfig.indexOf('-r') === -1 && downloadConfig.indexOf('--limit-rate') === -1) { + downloadConfig.push('-r', rate_limit); + } + const default_downloader = utils.getCurrentDownloader() || config_api.getConfigItem('ytdl_default_downloader'); if (default_downloader === 'yt-dlp') { downloadConfig.push('--no-clean-infojson'); diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 618270c..c747ec8 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -58,7 +58,13 @@ Unit is seconds, only include numbers. -
+
+ + + Units is seconds, will force youtube-dl to sleep between videos in a subscription by the specified number of seconds. Only include numbers. + +
+
Redownload fresh uploads
@@ -110,14 +116,14 @@ -
+
Path for video downloads. It is relative to YTDL-Material's root folder.
-