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:
Isaac Abadi
2021-03-16 20:06:05 -06:00
parent f32b394715
commit 1f0153b17e
2 changed files with 36 additions and 1 deletions

View File

@@ -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
}