mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-29 08:00:57 +03:00
Categories will now auto-generate playlists
This commit is contained in:
@@ -79,7 +79,7 @@ const logger = winston.createLogger({
|
||||
});
|
||||
|
||||
config_api.initialize(logger);
|
||||
auth_api.initialize(users_db, logger);
|
||||
auth_api.initialize(db, users_db, logger);
|
||||
db_api.initialize(db, users_db, logger);
|
||||
subscriptions_api.initialize(db, users_db, logger, db_api);
|
||||
categories_api.initialize(db, users_db, logger, db_api);
|
||||
@@ -1215,7 +1215,7 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
|
||||
const customPath = options.noRelativePath ? path.dirname(full_file_path).split(path.sep).pop() : null;
|
||||
|
||||
// registers file in DB
|
||||
file_uid = db_api.registerFileDB(file_path, type, multiUserMode, null, customPath);
|
||||
file_uid = db_api.registerFileDB(file_path, type, multiUserMode, null, customPath, category);
|
||||
|
||||
if (file_name) file_names.push(file_name);
|
||||
}
|
||||
@@ -2014,10 +2014,37 @@ app.post('/api/getAllFiles', optionalJwt, async function (req, res) {
|
||||
// get basic info depending on multi-user mode being enabled
|
||||
if (req.isAuthenticated()) {
|
||||
files = auth_api.getUserVideos(req.user.uid);
|
||||
playlists = auth_api.getUserPlaylists(req.user.uid);
|
||||
playlists = auth_api.getUserPlaylists(req.user.uid, files);
|
||||
} else {
|
||||
files = db.get('files').value();
|
||||
playlists = db.get('playlists').value();
|
||||
playlists = JSON.parse(JSON.stringify(db.get('playlists').value()));
|
||||
const categories = db.get('categories').value();
|
||||
if (categories) {
|
||||
categories.forEach(category => {
|
||||
const audio_files = files && files.filter(file => file.category && file.category.uid === category.uid && file.isAudio);
|
||||
const video_files = files && files.filter(file => file.category && file.category.uid === category.uid && !file.isAudio);
|
||||
if (audio_files && audio_files.length > 0) {
|
||||
playlists.push({
|
||||
name: category['name'],
|
||||
thumbnailURL: audio_files[0].thumbnailURL,
|
||||
thumbnailPath: audio_files[0].thumbnailPath,
|
||||
fileNames: audio_files.map(file => file.id),
|
||||
type: 'audio',
|
||||
auto: true
|
||||
});
|
||||
}
|
||||
if (video_files && video_files.length > 0) {
|
||||
playlists.push({
|
||||
name: category['name'],
|
||||
thumbnailURL: video_files[0].thumbnailURL,
|
||||
thumbnailPath: video_files[0].thumbnailPath,
|
||||
fileNames: video_files.map(file => file.id),
|
||||
type: 'video',
|
||||
auto: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// loop through subscriptions and add videos
|
||||
|
||||
@@ -15,15 +15,16 @@ var JwtStrategy = require('passport-jwt').Strategy,
|
||||
|
||||
// other required vars
|
||||
let logger = null;
|
||||
var users_db = null;
|
||||
let db = null;
|
||||
let users_db = null;
|
||||
let SERVER_SECRET = null;
|
||||
let JWT_EXPIRATION = null;
|
||||
let opts = null;
|
||||
let saltRounds = null;
|
||||
|
||||
exports.initialize = function(input_users_db, input_logger) {
|
||||
exports.initialize = function(input_db, input_users_db, input_logger) {
|
||||
setLogger(input_logger)
|
||||
setDB(input_users_db);
|
||||
setDB(input_db, input_users_db);
|
||||
|
||||
/*************************
|
||||
* Authentication module
|
||||
@@ -61,7 +62,8 @@ function setLogger(input_logger) {
|
||||
logger = input_logger;
|
||||
}
|
||||
|
||||
function setDB(input_users_db) {
|
||||
function setDB(input_db, input_users_db) {
|
||||
db = input_db;
|
||||
users_db = input_users_db;
|
||||
}
|
||||
|
||||
@@ -310,9 +312,39 @@ exports.removePlaylist = function(user_uid, playlistID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
exports.getUserPlaylists = function(user_uid) {
|
||||
exports.getUserPlaylists = function(user_uid, user_files = null) {
|
||||
const user = users_db.get('users').find({uid: user_uid}).value();
|
||||
return user['playlists'];
|
||||
const playlists = JSON.parse(JSON.stringify(user['playlists']));
|
||||
const categories = db.get('categories').value();
|
||||
if (categories && user_files) {
|
||||
categories.forEach(category => {
|
||||
const audio_files = user_files && user_files.filter(file => file.category && file.category.uid === category.uid && file.isAudio);
|
||||
const video_files = user_files && user_files.filter(file => file.category && file.category.uid === category.uid && !file.isAudio);
|
||||
if (audio_files && audio_files.length > 0) {
|
||||
playlists.push({
|
||||
name: category['name'],
|
||||
thumbnailURL: audio_files[0].thumbnailURL,
|
||||
thumbnailPath: audio_files[0].thumbnailPath,
|
||||
fileNames: audio_files.map(file => file.id),
|
||||
type: 'audio',
|
||||
uid: user_uid,
|
||||
auto: true
|
||||
});
|
||||
}
|
||||
if (video_files && video_files.length > 0) {
|
||||
playlists.push({
|
||||
name: category['name'],
|
||||
thumbnailURL: video_files[0].thumbnailURL,
|
||||
thumbnailPath: video_files[0].thumbnailPath,
|
||||
fileNames: video_files.map(file => file.id),
|
||||
type: 'video',
|
||||
uid: user_uid,
|
||||
auto: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return playlists;
|
||||
}
|
||||
|
||||
exports.getUserPlaylist = function(user_uid, playlistID, requireSharing = false) {
|
||||
|
||||
Reference in New Issue
Block a user