mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-22 02:13:18 +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+'); }
|
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;
|
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() {
|
async function startServer() {
|
||||||
if (process.env.USING_HEROKU && process.env.PORT) {
|
if (process.env.USING_HEROKU && process.env.PORT) {
|
||||||
// default to heroku port if using heroku
|
// 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);
|
return path.join(base_path, (sub.isPlaylist ? 'playlists/' : 'channels/'), sub.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function importUnregisteredFiles() {
|
function getFileDirectoriesAndDBs() {
|
||||||
let dirs_to_check = [];
|
let dirs_to_check = [];
|
||||||
let subscriptions_to_check = [];
|
let subscriptions_to_check = [];
|
||||||
const subscriptions_base_path = config_api.getConfigItem('ytdl_subscriptions_base_path'); // only for single-user mode
|
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
|
// 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) {
|
for (const dir_to_check of dirs_to_check) {
|
||||||
// recursively get all files in dir's path
|
// recursively get all files in dir's path
|
||||||
@@ -203,5 +209,6 @@ module.exports = {
|
|||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
registerFileDB: registerFileDB,
|
registerFileDB: registerFileDB,
|
||||||
updatePlaylist: updatePlaylist,
|
updatePlaylist: updatePlaylist,
|
||||||
|
getFileDirectoriesAndDBs: getFileDirectoriesAndDBs,
|
||||||
importUnregisteredFiles: importUnregisteredFiles
|
importUnregisteredFiles: importUnregisteredFiles
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function getTrueFileName(unfixed_path, type) {
|
|||||||
return fixed_path;
|
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
|
// return empty array if the path doesn't exist
|
||||||
if (!(await fs.pathExists(basePath))) return [];
|
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 id = file_path.substring(0, file_path.length-4);
|
||||||
var jsonobj = await getJSONByType(type, id, basePath);
|
var jsonobj = await getJSONByType(type, id, basePath);
|
||||||
if (!jsonobj) continue;
|
if (!jsonobj) continue;
|
||||||
|
if (full_metadata) {
|
||||||
|
jsonobj['id'] = id;
|
||||||
|
files.push(jsonobj);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var title = jsonobj.title;
|
var title = jsonobj.title;
|
||||||
var url = jsonobj.webpage_url;
|
var url = jsonobj.webpage_url;
|
||||||
var uploader = jsonobj.uploader;
|
var uploader = jsonobj.uploader;
|
||||||
|
|||||||
@@ -8,6 +8,18 @@
|
|||||||
</video>
|
</video>
|
||||||
</vg-player>
|
</vg-player>
|
||||||
</div>
|
</div>
|
||||||
|
<div *ngIf="file_obj" style="height: fit-content; width: 100%; margin-top: 10px;">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<ng-container *ngIf="file_obj">{{file_obj['local_play_count'] ? file_obj['local_play_count'] : 0}} <ng-container i18n="View count label">views</ng-container></ng-container>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div style="height: fit-content; width: 100%; margin-top: 10px;">
|
<div style="height: fit-content; width: 100%; margin-top: 10px;">
|
||||||
<mat-button-toggle-group cdkDropList [cdkDropListSortingDisabled]="!id" (cdkDropListDropped)="drop($event)" style="width: 80%; left: 9%" vertical name="videoSelect" aria-label="Video Select" #group="matButtonToggleGroup">
|
<mat-button-toggle-group cdkDropList [cdkDropListSortingDisabled]="!id" (cdkDropListDropped)="drop($event)" style="width: 80%; left: 9%" vertical name="videoSelect" aria-label="Video Select" #group="matButtonToggleGroup">
|
||||||
<mat-button-toggle cdkDrag *ngFor="let playlist_item of playlist; let i = index" [checked]="currentItem.title === playlist_item.title" (click)="onClickPlaylistItem(playlist_item, i)" class="toggle-button" [value]="playlist_item.title">{{playlist_item.label}}</mat-button-toggle>
|
<mat-button-toggle cdkDrag *ngFor="let playlist_item of playlist; let i = index" [checked]="currentItem.title === playlist_item.title" (click)="onClickPlaylistItem(playlist_item, i)" class="toggle-button" [value]="playlist_item.title">{{playlist_item.label}}</mat-button-toggle>
|
||||||
|
|||||||
Reference in New Issue
Block a user