Added random and individual queuing from playlists.
This commit is contained in:
parent
e61d9deb52
commit
e629c63b2c
6 changed files with 244 additions and 57 deletions
|
|
@ -38,6 +38,8 @@ module.exports = class{
|
|||
socket.on("deleteChannelPlaylistMedia", (data) => {this.deleteChannelPlaylistMedia(socket, data)});
|
||||
socket.on("addToChannelPlaylist", (data) => {this.addToChannelPlaylist(socket, data)});
|
||||
socket.on("queueChannelPlaylist", (data) => {this.queueChannelPlaylist(socket, data)});
|
||||
socket.on("queueRandomFromChannelPlaylist", (data) => {this.queueRandomFromChannelPlaylist(socket, data)});
|
||||
socket.on("queueFromChannelPlaylist", (data) => {this.queueFromChannelPlaylist(socket, data)});
|
||||
socket.on("renameChannelPlaylist", (data) => {this.renameChannelPlaylist(socket, data)});
|
||||
socket.on("changeDefaultTitlesChannelPlaylist", (data) => {this.changeDefaultTitlesChannelPlaylist(socket, data)});
|
||||
}
|
||||
|
|
@ -108,7 +110,7 @@ module.exports = class{
|
|||
await chanDB.save();
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
this.getChannelPlaylists(socket, chanDB);
|
||||
}
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
|
|
@ -128,7 +130,7 @@ module.exports = class{
|
|||
await chanDB.deletePlaylistByName(data.playlist);
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
this.getChannelPlaylists(socket, chanDB);
|
||||
}
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
|
|
@ -171,11 +173,25 @@ module.exports = class{
|
|||
return;
|
||||
}
|
||||
|
||||
//Add media object to the given playlist
|
||||
await chanDB.addToPlaylist(data.playlist, mediaList[0]);
|
||||
//Find the playlist
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//delete media from playlist
|
||||
chanDB.media.playlists[playlist.listIndex].addMedia(mediaList);
|
||||
|
||||
//save the channel document
|
||||
await chanDB.save();
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
this.getChannelPlaylists(socket, chanDB);
|
||||
}
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
|
|
@ -198,6 +214,14 @@ module.exports = class{
|
|||
//Grab playlist from the DB
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Create an empty array to hold our media list
|
||||
const mediaList = [];
|
||||
|
||||
|
|
@ -207,7 +231,7 @@ module.exports = class{
|
|||
let mediaObj = item.rehydrate();
|
||||
|
||||
//Set media title from default titles
|
||||
mediaObj.title = playlist.defaultTitles[Math.floor(Math.random() * playlist.defaultTitles.length)];
|
||||
mediaObj.title = playlist.pickDefaultTitle();
|
||||
|
||||
//Push rehydrated item on to the mediaList
|
||||
mediaList.push(mediaObj);
|
||||
|
|
@ -221,6 +245,95 @@ module.exports = class{
|
|||
}
|
||||
}
|
||||
|
||||
async queueFromChannelPlaylist(socket, data, chanDB){
|
||||
try{
|
||||
//if we wherent handed a channel document
|
||||
if(chanDB == null){
|
||||
//Pull it based on channel name
|
||||
chanDB = await channelModel.findOne({name: this.channel.name});
|
||||
}
|
||||
|
||||
//Permcheck the user
|
||||
if((!this.channel.queue.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
|
||||
//Pull a valid start time from input, or make one up if we can't
|
||||
let start = this.channel.queue.getStart(data.start);
|
||||
|
||||
//Grab playlist
|
||||
const playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//If we don't have a valid UUID
|
||||
if(!validator.isUUID(data.uuid)){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, `'${data.uuid}' is not a valid UUID!`, "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Pull and rehydrate media from playlist
|
||||
const media = playlist.findMediaByUUID(data.uuid).rehydrate();
|
||||
|
||||
//Set title from default titles
|
||||
media.title = playlist.pickDefaultTitle();
|
||||
|
||||
//Queue found media
|
||||
this.channel.queue.scheduleMedia(queuedMedia.fromMediaArray([media], start), socket, chanDB);
|
||||
}
|
||||
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
async queueRandomFromChannelPlaylist(socket, data, chanDB){
|
||||
try{
|
||||
//if we wherent handed a channel document
|
||||
if(chanDB == null){
|
||||
//Pull it based on channel name
|
||||
chanDB = await channelModel.findOne({name: this.channel.name});
|
||||
}
|
||||
|
||||
//Permcheck the user
|
||||
if((!this.channel.queue.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
|
||||
//Pull a valid start time from input, or make one up if we can't
|
||||
let start = this.channel.queue.getStart(data.start);
|
||||
|
||||
//Grab playlist
|
||||
const playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Pick a random video ID based on the playlist's length
|
||||
const foundID = Math.round(Math.random() * (playlist.media.length - 1));
|
||||
|
||||
//Pull and rehydrate media from playlist
|
||||
const foundMedia = playlist.media[foundID].rehydrate();
|
||||
|
||||
//Set title from default titles
|
||||
foundMedia.title = playlist.pickDefaultTitle();
|
||||
|
||||
//Queue found media
|
||||
this.channel.queue.scheduleMedia(queuedMedia.fromMediaArray([foundMedia], start), socket, chanDB);
|
||||
}
|
||||
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
async renameChannelPlaylist(socket, data, chanDB){
|
||||
try{
|
||||
//if we wherent handed a channel document
|
||||
|
|
@ -252,6 +365,14 @@ module.exports = class{
|
|||
//Find playlist
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Change playlist name
|
||||
chanDB.media.playlists[playlist.listIndex].name = name;
|
||||
|
||||
|
|
@ -259,7 +380,7 @@ module.exports = class{
|
|||
await chanDB.save();
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
this.getChannelPlaylists(socket, chanDB);
|
||||
}
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
|
|
@ -278,6 +399,14 @@ module.exports = class{
|
|||
//Find playlist
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Create empty array to hold titles
|
||||
const safeTitles = [];
|
||||
|
||||
|
|
@ -297,7 +426,7 @@ module.exports = class{
|
|||
await chanDB.save();
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
this.getChannelPlaylists(socket, chanDB);
|
||||
}
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
|
|
@ -321,11 +450,25 @@ module.exports = class{
|
|||
return;
|
||||
}
|
||||
|
||||
//Delete media from channel playlist
|
||||
chanDB.deletePlaylistMediaByUUID(data.playlist, data.uuid);
|
||||
//Find the playlist
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//If we didn't find a real playlist
|
||||
if(playlist == null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, "Playlist not found!", "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//delete media from playlist
|
||||
chanDB.media.playlists[playlist.listIndex].deleteMedia(data.uuid);
|
||||
|
||||
//save the channel document
|
||||
await chanDB.save();
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
this.getChannelPlaylists(socket, chanDB);
|
||||
}
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ module.exports = class{
|
|||
//Get the current channel from the database
|
||||
const chanDB = await channelModel.findOne({name: socket.chan});
|
||||
|
||||
console.log(!this.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin');
|
||||
//Permcheck to make sure the user can fuck w/ the queue
|
||||
if((!this.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue