mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-21 06:23:20 +03:00
Added ability to add file to playlist using the context menu
This commit is contained in:
@@ -754,20 +754,6 @@ function generateEnvVarConfigItem(key) {
|
||||
return {key: key, value: process['env'][key]};
|
||||
}
|
||||
|
||||
function getThumbnailMp3(name)
|
||||
{
|
||||
var obj = utils.getJSONMp3(name, audioFolderPath);
|
||||
var thumbnailLink = obj.thumbnail;
|
||||
return thumbnailLink;
|
||||
}
|
||||
|
||||
function getThumbnailMp4(name)
|
||||
{
|
||||
var obj = utils.getJSONMp4(name, videoFolderPath);
|
||||
var thumbnailLink = obj.thumbnail;
|
||||
return thumbnailLink;
|
||||
}
|
||||
|
||||
function getFileSizeMp3(name)
|
||||
{
|
||||
var jsonPath = audioFolderPath+name+".mp3.info.json";
|
||||
@@ -1061,7 +1047,7 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
|
||||
// create playlist
|
||||
const playlist_name = file_objs.map(file_obj => file_obj.title).join(', ');
|
||||
const duration = file_objs.reduce((a, b) => a + utils.durationStringToNumber(b.duration), 0);
|
||||
container = await db_api.createPlaylist(playlist_name, file_objs.map(file_obj => file_obj.uid), type, file_objs[0]['thumbnailURL'], options.user);
|
||||
container = await db_api.createPlaylist(playlist_name, file_objs.map(file_obj => file_obj.uid), type, options.user);
|
||||
} else if (file_objs.length === 1) {
|
||||
container = file_objs[0];
|
||||
} else {
|
||||
@@ -2181,9 +2167,8 @@ app.post('/api/createPlaylist', optionalJwt, async (req, res) => {
|
||||
let playlistName = req.body.playlistName;
|
||||
let uids = req.body.uids;
|
||||
let type = req.body.type;
|
||||
let thumbnailURL = req.body.thumbnailURL;
|
||||
|
||||
const new_playlist = await db_api.createPlaylist(playlistName, uids, type, thumbnailURL, req.isAuthenticated() ? req.user.uid : null);
|
||||
const new_playlist = await db_api.createPlaylist(playlistName, uids, type, req.isAuthenticated() ? req.user.uid : null);
|
||||
|
||||
res.send({
|
||||
new_playlist: new_playlist,
|
||||
@@ -2216,8 +2201,18 @@ app.post('/api/getPlaylist', optionalJwt, async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/getPlaylists', optionalJwt, async (req, res) => {
|
||||
const uuid = req.isAuthenticated() ? req.user.uid : null;
|
||||
|
||||
const playlists = await db_api.getRecords('playlists', {user_uid: uuid});
|
||||
|
||||
res.send({
|
||||
playlists: playlists
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/updatePlaylistFiles', optionalJwt, async (req, res) => {
|
||||
let playlistID = req.body.playlistID;
|
||||
let playlistID = req.body.playlist_id;
|
||||
let uids = req.body.uids;
|
||||
|
||||
let success = false;
|
||||
@@ -2238,6 +2233,20 @@ app.post('/api/updatePlaylistFiles', optionalJwt, async (req, res) => {
|
||||
})
|
||||
});
|
||||
|
||||
app.post('/api/addFileToPlaylist', optionalJwt, async (req, res) => {
|
||||
let playlist_id = req.body.playlist_id;
|
||||
let file_uid = req.body.file_uid;
|
||||
|
||||
const playlist = await db_api.getRecord('playlists', {id: playlist_id});
|
||||
|
||||
playlist.uids.push(file_uid);
|
||||
|
||||
let success = await db_api.updatePlaylist(playlist);
|
||||
res.send({
|
||||
success: success
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/updatePlaylist', optionalJwt, async (req, res) => {
|
||||
let playlist = req.body.playlist;
|
||||
let success = await db_api.updatePlaylist(playlist, req.user && req.user.uid);
|
||||
@@ -2247,7 +2256,7 @@ app.post('/api/updatePlaylist', optionalJwt, async (req, res) => {
|
||||
});
|
||||
|
||||
app.post('/api/deletePlaylist', optionalJwt, async (req, res) => {
|
||||
let playlistID = req.body.playlistID;
|
||||
let playlistID = req.body.playlist_id;
|
||||
|
||||
let success = null;
|
||||
try {
|
||||
|
||||
@@ -411,23 +411,26 @@ exports.addMetadataPropertyToDB = async (property_key) => {
|
||||
}
|
||||
}
|
||||
|
||||
exports.createPlaylist = async (playlist_name, uids, type, thumbnail_url, user_uid = null) => {
|
||||
exports.createPlaylist = async (playlist_name, uids, type, user_uid = null) => {
|
||||
const first_video = await exports.getVideo(uids[0]);
|
||||
const thumbnailToUse = first_video['thumbnailURL'];
|
||||
|
||||
let new_playlist = {
|
||||
name: playlist_name,
|
||||
uids: uids,
|
||||
id: uuid(),
|
||||
thumbnailURL: thumbnail_url,
|
||||
thumbnailURL: thumbnailToUse,
|
||||
type: type,
|
||||
registered: Date.now(),
|
||||
randomize_order: false
|
||||
};
|
||||
|
||||
const duration = await exports.calculatePlaylistDuration(new_playlist, user_uid);
|
||||
new_playlist.duration = duration;
|
||||
|
||||
new_playlist.user_uid = user_uid ? user_uid : undefined;
|
||||
|
||||
await exports.insertRecordIntoTable('playlists', new_playlist);
|
||||
|
||||
const duration = await exports.calculatePlaylistDuration(new_playlist);
|
||||
await exports.updateRecord('playlists', {id: new_playlist.id}, {duration: duration});
|
||||
|
||||
return new_playlist;
|
||||
}
|
||||
@@ -463,10 +466,10 @@ exports.getPlaylist = async (playlist_id, user_uid = null, require_sharing = fal
|
||||
return playlist;
|
||||
}
|
||||
|
||||
exports.updatePlaylist = async (playlist, user_uid = null) => {
|
||||
exports.updatePlaylist = async (playlist) => {
|
||||
let playlistID = playlist.id;
|
||||
|
||||
const duration = await exports.calculatePlaylistDuration(playlist, user_uid);
|
||||
const duration = await exports.calculatePlaylistDuration(playlist);
|
||||
playlist.duration = duration;
|
||||
|
||||
return await exports.updateRecord('playlists', {id: playlistID}, playlist);
|
||||
@@ -486,12 +489,12 @@ exports.setPlaylistProperty = async (playlist_id, assignment_obj, user_uid = nul
|
||||
return success;
|
||||
}
|
||||
|
||||
exports.calculatePlaylistDuration = async (playlist, uuid, playlist_file_objs = null) => {
|
||||
exports.calculatePlaylistDuration = async (playlist, playlist_file_objs = null) => {
|
||||
if (!playlist_file_objs) {
|
||||
playlist_file_objs = [];
|
||||
for (let i = 0; i < playlist['uids'].length; i++) {
|
||||
const uid = playlist['uids'][i];
|
||||
const file_obj = await exports.getVideo(uid, uuid);
|
||||
const file_obj = await exports.getVideo(uid);
|
||||
if (file_obj) playlist_file_objs.push(file_obj);
|
||||
}
|
||||
}
|
||||
@@ -588,7 +591,7 @@ exports.getVideoUIDByID = async (file_id, uuid = null) => {
|
||||
return file_obj ? file_obj['uid'] : null;
|
||||
}
|
||||
|
||||
exports.getVideo = async (file_uid, uuid = null, sub_id = null) => {
|
||||
exports.getVideo = async (file_uid) => {
|
||||
return await exports.getRecord('files', {uid: file_uid});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user