mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-31 00:50:59 +03:00
Subscription videos being downloaded will get registered into the database as they are added to avoid having to wait until the subscription completes
This commit is contained in:
@@ -213,6 +213,29 @@ async function importUnregisteredFiles() {
|
||||
|
||||
}
|
||||
|
||||
async function preimportUnregisteredSubscriptionFile(sub, appendedBasePath) {
|
||||
const preimported_file_paths = [];
|
||||
|
||||
let dbPath = null;
|
||||
if (sub.user_uid)
|
||||
dbPath = users_db.get('users').find({uid: sub.user_uid}).get('subscriptions').find({id: sub.id}).get('videos');
|
||||
else
|
||||
dbPath = db.get('subscriptions').find({id: sub.id}).get('videos');
|
||||
|
||||
const files = await utils.getDownloadedFilesByType(appendedBasePath, sub.type);
|
||||
files.forEach(file => {
|
||||
// check if file exists in db, if not add it
|
||||
const file_is_registered = !!(dbPath.find({id: file.id}).value())
|
||||
if (!file_is_registered) {
|
||||
// add additional info
|
||||
registerFileDBManual(dbPath, file);
|
||||
preimported_file_paths.push(file['path']);
|
||||
logger.verbose(`Preemptively added subscription file to the database: ${file.id}`);
|
||||
}
|
||||
});
|
||||
return preimported_file_paths;
|
||||
}
|
||||
|
||||
async function getVideo(file_uid, uuid, sub_id) {
|
||||
const base_db_path = uuid ? users_db.get('users').find({uid: uuid}) : db;
|
||||
const sub_db_path = sub_id ? base_db_path.get('subscriptions').find({id: sub_id}).get('videos') : base_db_path.get('files');
|
||||
@@ -235,6 +258,7 @@ module.exports = {
|
||||
updatePlaylist: updatePlaylist,
|
||||
getFileDirectoriesAndDBs: getFileDirectoriesAndDBs,
|
||||
importUnregisteredFiles: importUnregisteredFiles,
|
||||
preimportUnregisteredSubscriptionFile: preimportUnregisteredSubscriptionFile,
|
||||
getVideo: getVideo,
|
||||
setVideoProperty: setVideoProperty
|
||||
}
|
||||
|
||||
@@ -277,6 +277,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
basePath = config_api.getConfigItem('ytdl_subscriptions_base_path');
|
||||
|
||||
let appendedBasePath = getAppendedBasePath(sub, basePath);
|
||||
fs.ensureDirSync(appendedBasePath);
|
||||
|
||||
let multiUserMode = null;
|
||||
if (user_uid) {
|
||||
@@ -292,8 +293,17 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
logger.verbose('Subscription: getting videos for subscription ' + sub.name);
|
||||
|
||||
return new Promise(resolve => {
|
||||
const preimported_file_paths = [];
|
||||
const PREIMPORT_INTERVAL = 5000;
|
||||
const preregister_check = setInterval(() => {
|
||||
if (sub.streamingOnly) return;
|
||||
db_api.preimportUnregisteredSubscriptionFile(sub, appendedBasePath);
|
||||
}, PREIMPORT_INTERVAL);
|
||||
youtubedl.exec(sub.url, downloadConfig, {maxBuffer: Infinity}, async function(err, output) {
|
||||
// cleanup
|
||||
updateSubscriptionProperty(sub, {downloading: false}, user_uid);
|
||||
clearInterval(preregister_check);
|
||||
|
||||
logger.verbose('Subscription: finished check for ' + sub.name);
|
||||
if (err && !output) {
|
||||
logger.error(err.stderr ? err.stderr : err.message);
|
||||
@@ -337,7 +347,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
}
|
||||
|
||||
const reset_videos = i === 0;
|
||||
handleOutputJSON(sub, sub_db, output_json, multiUserMode, reset_videos);
|
||||
handleOutputJSON(sub, sub_db, output_json, multiUserMode, preimported_file_paths, reset_videos);
|
||||
}
|
||||
|
||||
if (config_api.getConfigItem('ytdl_subscriptions_redownload_fresh_uploads')) {
|
||||
@@ -351,6 +361,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
}, err => {
|
||||
logger.error(err);
|
||||
updateSubscriptionProperty(sub, {downloading: false}, user_uid);
|
||||
clearInterval(preregister_check);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user