mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-09 07:51:27 +03:00
Added ability to add more metadata to db through migrations, and added scaffolding for supporting description and play count in the player component
This commit is contained in:
@@ -216,6 +216,16 @@ async function checkMigrations() {
|
||||
else { logger.error('Migration failed: 3.5->3.6+'); }
|
||||
}
|
||||
|
||||
// 4.1->4.2 migration
|
||||
|
||||
const add_description_migration_complete = false; // db.get('add_description_migration_complete').value();
|
||||
if (!add_description_migration_complete) {
|
||||
logger.info('Beginning migration: 4.1->4.2+')
|
||||
const success = await addMetadataPropertyToDB('description');
|
||||
if (success) { logger.info('4.1->4.2+ migration complete!'); }
|
||||
else { logger.error('Migration failed: 4.1->4.2+'); }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -251,6 +261,28 @@ async function runFilesToDBMigration() {
|
||||
}
|
||||
}
|
||||
|
||||
async function addMetadataPropertyToDB(property_key) {
|
||||
try {
|
||||
const dirs_to_check = db_api.getFileDirectoriesAndDBs();
|
||||
for (const dir_to_check of dirs_to_check) {
|
||||
// recursively get all files in dir's path
|
||||
const files = await utils.getDownloadedFilesByType(dir_to_check.basePath, dir_to_check.type, true);
|
||||
for (const file of files) {
|
||||
if (file[property_key]) {
|
||||
dir_to_check.dbPath.find({id: file.id}).assign({[property_key]: file[property_key]}).write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sets migration to complete
|
||||
db.set('add_description_migration_complete', true).write();
|
||||
return true;
|
||||
} catch(err) {
|
||||
logger.error(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function startServer() {
|
||||
if (process.env.USING_HEROKU && process.env.PORT) {
|
||||
// default to heroku port if using heroku
|
||||
|
||||
@@ -115,7 +115,7 @@ function getAppendedBasePathSub(sub, base_path) {
|
||||
return path.join(base_path, (sub.isPlaylist ? 'playlists/' : 'channels/'), sub.name);
|
||||
}
|
||||
|
||||
async function importUnregisteredFiles() {
|
||||
function getFileDirectoriesAndDBs() {
|
||||
let dirs_to_check = [];
|
||||
let subscriptions_to_check = [];
|
||||
const subscriptions_base_path = config_api.getConfigItem('ytdl_subscriptions_base_path'); // only for single-user mode
|
||||
@@ -181,6 +181,12 @@ async function importUnregisteredFiles() {
|
||||
});
|
||||
}
|
||||
|
||||
return dirs_to_check;
|
||||
}
|
||||
|
||||
async function importUnregisteredFiles() {
|
||||
const dirs_to_check = getFileDirectoriesAndDBs();
|
||||
|
||||
// run through check list and check each file to see if it's missing from the db
|
||||
for (const dir_to_check of dirs_to_check) {
|
||||
// recursively get all files in dir's path
|
||||
@@ -203,5 +209,6 @@ module.exports = {
|
||||
initialize: initialize,
|
||||
registerFileDB: registerFileDB,
|
||||
updatePlaylist: updatePlaylist,
|
||||
getFileDirectoriesAndDBs: getFileDirectoriesAndDBs,
|
||||
importUnregisteredFiles: importUnregisteredFiles
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ function getTrueFileName(unfixed_path, type) {
|
||||
return fixed_path;
|
||||
}
|
||||
|
||||
async function getDownloadedFilesByType(basePath, type) {
|
||||
async function getDownloadedFilesByType(basePath, type, full_metadata = false) {
|
||||
// return empty array if the path doesn't exist
|
||||
if (!(await fs.pathExists(basePath))) return [];
|
||||
|
||||
@@ -36,6 +36,11 @@ async function getDownloadedFilesByType(basePath, type) {
|
||||
var id = file_path.substring(0, file_path.length-4);
|
||||
var jsonobj = await getJSONByType(type, id, basePath);
|
||||
if (!jsonobj) continue;
|
||||
if (full_metadata) {
|
||||
jsonobj['id'] = id;
|
||||
files.push(jsonobj);
|
||||
continue;
|
||||
}
|
||||
var title = jsonobj.title;
|
||||
var url = jsonobj.webpage_url;
|
||||
var uploader = jsonobj.uploader;
|
||||
|
||||
Reference in New Issue
Block a user