diff --git a/backend/app.js b/backend/app.js index 0cdd414..148e94c 100644 --- a/backend/app.js +++ b/backend/app.js @@ -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 diff --git a/backend/db.js b/backend/db.js index a2ddb7a..9436715 100644 --- a/backend/db.js +++ b/backend/db.js @@ -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 } diff --git a/backend/utils.js b/backend/utils.js index ed3b584..33b877a 100644 --- a/backend/utils.js +++ b/backend/utils.js @@ -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; diff --git a/src/app/player/player.component.html b/src/app/player/player.component.html index 6774ace..73ea9eb 100644 --- a/src/app/player/player.component.html +++ b/src/app/player/player.component.html @@ -8,6 +8,18 @@ +
+
+
+
+ {{file_obj['local_play_count'] ? file_obj['local_play_count'] : 0}} views +
+
+ +
+
+
+
{{playlist_item.label}}