auto dj upgrades

This commit is contained in:
IrosTheBeggar 2019-12-09 14:42:30 -05:00
parent cea3a4518a
commit c9f41b8b95
6 changed files with 78 additions and 44 deletions

View File

@ -25,7 +25,7 @@ if (config.error) {
const colors = require('colors');
console.clear();
console.log(colors.bold(`
v4.5.4 ____ _
v4.6.0 ____ _
_ __ ___ / ___|| |_ _ __ ___ __ _ _ __ ___
| '_ \` _ \\\\___ \\| __| '__/ _ \\/ _\` | '_ \` _ \\
| | | | | |___) | |_| | | __/ (_| | | | | | |

View File

@ -463,8 +463,7 @@ exports.setup = function (mstream, program) {
res.status(500).json({ error: 'No files in DB' });
return;
};
// Ignore songs with star rating of 2 or under
let ignoreRating = false;
// Ignore list
let ignoreList = [];
if (req.body.ignoreList && Array.isArray(req.body.ignoreList)) {
@ -472,33 +471,34 @@ exports.setup = function (mstream, program) {
}
let ignorePercentage = .5;
if (req.body.ignorePercentage && typeof req.body.ignorePercentage === 'number' && req.body.ignorePercentage < 1 && req.body.ignorePercentage < 0) {
if (req.body.ignorePercentage && typeof req.body.ignorePercentage === 'number' && req.body.ignorePercentage < 1 && !req.body.ignorePercentage < 0) {
ignorePercentage = req.body.ignorePercentage;
}
// // Preference for recently played or not played recently
// // Preference for starred songs
let orClause;
if (req.user.vpaths.length === 1 && ignoreRating == false) {
orClause = { 'vpath': { '$eq': req.user.vpaths[0] } }
} else {
orClause = { '$or': [] }
for (let vpath of req.user.vpaths) {
orClause['$or'].push({ 'vpath': { '$eq': vpath } })
let orClause = { '$or': [] };
for (let vpath of req.user.vpaths) {
if (req.body.ignoreVPaths && typeof req.body.ignoreVPaths === 'object' && req.body.ignoreVPaths[vpath] === true) {
continue;
}
orClause['$or'].push({ 'vpath': { '$eq': vpath } });
}
if (ignoreRating) {
// Add Rating clause
}
let minRating = Number(req.body.minRating);
// Add Rating clause
if (minRating && typeof minRating === 'number' && minRating <= 10 && !minRating < 1) {
orClause = {'$and': [
orClause,
{ 'rating': { '$gte': req.body.minRating } }
]};
}
// Print list
const results = fileCollection.find(orClause);
const count = results.length;
if (count === 0) {
res.status(444).json({ error: 'No songs that match criterai' });
res.status(444).json({ error: 'No songs that match criteria' });
return;
}
@ -532,7 +532,6 @@ exports.setup = function (mstream, program) {
}
});
ignoreList.push(randomNumber);
returnThis.ignoreList = ignoreList;
res.json(returnThis);

View File

@ -1,6 +1,6 @@
{
"name": "mstream",
"version": "4.5.4",
"version": "4.6.0",
"description": "music streaming server",
"main": "cli-boot-wrapper.js",
"bin": {

View File

@ -140,9 +140,6 @@ p {
.row, .inner-wrap, .off-canvas-wrap {
height: 100%; }
div#jp_container_N {
right: 25px; }
.logo {
width: 181px;
height: auto;
@ -155,14 +152,6 @@ div#jp_container_N {
position: relative;
z-index: 3; }
.masterlist {
border: solid 1px #E0E0E0;
background: #FFF;
-webkit-box-shadow: 0 0 10px #D6D6D6;
-moz-box-shadow: 0 0 10px #D6D6D6;
box-shadow: 0 0 10px #D6D6D6;
padding: 10px; }
.filez, .dirz, .fileplaylistz, .back, .artistz, .albumz, .playlist_row_container, .playlist-item, #playlist_container ul li {
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
cursor: pointer;
@ -276,13 +265,6 @@ div#jp_container_N {
width: calc(100% - 99px);
}
#mplayer{
margin-left: 0px !important;
}
ul.jp-controls li {
list-style-type: none !important; }
#downform {
display: none;
position: absolute; }
@ -376,8 +358,6 @@ h3 {
margin: 0;
max-width: none; }
@media (min-width: 644px) {
.content {
width: 50%;
@ -529,8 +509,6 @@ h3 {
supported by Chrome and Opera */
}
.meta-box{
width: 100%;
height: 160px;
@ -550,7 +528,6 @@ h3 {
height:5px;
}
.meta-info{
height: 100%;
width: calc(100% - 155px);
@ -844,3 +821,13 @@ ul.left-nav-menu li.selected svg {
overflow-y: scroll;
max-height: 300px;
}
input[name="autodj-folders"] {
cursor: pointer;
}
#autodj-ratings{
cursor: pointer;
margin-left: 10px;
max-width: calc(100% - 20px);
}

View File

@ -1337,10 +1337,49 @@ $(document).ready(function () {
currentBrowsingList = [];
$('#directory_bar').hide();
var newHtml = '<div></div>';
var newHtml = '<br><p>Auto DJ randomly generates a playlist. CLick the \'DJ\' button on the bottom enable it</p><h3>Use Folders</h3><p>';
for (var i = 0; i < MSTREAMAPI.currentServer.vpaths.length; i++) {
var checkedString = '';
if (!MSTREAMPLAYER.ignoreVPaths[MSTREAMAPI.currentServer.vpaths[i]]) {
checkedString = 'checked';
}
newHtml += '<input ' + checkedString + ' id="autodj-folder-'+ MSTREAMAPI.currentServer.vpaths[i] +'" type="checkbox" value="'+MSTREAMAPI.currentServer.vpaths[i]+'" name="autodj-folders"><label for="autodj-folder-'+ MSTREAMAPI.currentServer.vpaths[i] +'">' + MSTREAMAPI.currentServer.vpaths[i] + '</label><br>';
}
newHtml += '</p><h3>Minimum Rating</h3> <select id="autodj-ratings">';
for (var i = 0; i < 11; i++) {
var selectedString = (Number(MSTREAMPLAYER.minRating) === i) ? 'selected' : '';
var optionString = (i ===0) ? 'Disabled' : +(i/2).toFixed(1) ;
newHtml += '<option '+selectedString+' value="'+i+'">'+ optionString + '</option>';
}
newHtml += '</select>';
$('#filelist').html(newHtml);
});
$('#filelist').on('click', 'input[name="autodj-folders"]', function(){
// Don't allow user to deselct all options
if ($('input[name="autodj-folders"]:checked').length < 1) {
$(this).prop('checked', true);
iziToast.warning({
title: 'Auto DJ requires a directory',
position: 'topCenter',
timeout: 3500
});
return;
}
if ($(this).is(':checked')) {
MSTREAMPLAYER.ignoreVPaths[$(this).val()] = false;
} else {
MSTREAMPLAYER.ignoreVPaths[$(this).val()] = true;
}
});
$('#filelist').on('change', '#autodj-ratings', function(){
MSTREAMPLAYER.minRating = $(this).val();
});
//////////////////////// Transcode
$('.transcode-panel').on('click', function () {
$('ul.left-nav-menu li').removeClass('selected');

View File

@ -62,7 +62,13 @@ var MSTREAMPLAYER = (function () {
}
mstreamModule.getRandomSong = function (callback) {
MSTREAMAPI.getRandomSong({ ignoreList: autoDjIgnoreArray }, function (res, err) {
const params = {
ignoreList: autoDjIgnoreArray,
minRating: mstreamModule.minRating,
ignoreVPaths: mstreamModule.ignoreVPaths
};
MSTREAMAPI.getRandomSong(params, function (res, err) {
if (err) {
callback(null, err);
return;
@ -78,6 +84,7 @@ var MSTREAMPLAYER = (function () {
// Call mStream API for random song
mstreamModule.getRandomSong(function (res, err) {
if (err) {
mstreamModule.playerStats.autoDJ = false;
iziToast.warning({
title: 'Auto DJ Failed',
message: err.responseJSON.error ? err.responseJSON.error : '',
@ -859,6 +866,8 @@ var MSTREAMPLAYER = (function () {
// AutoDJ
mstreamModule.playerStats.autoDJ = false;
var autoDjIgnoreArray = [];
mstreamModule.ignoreVPaths = {};
mstreamModule.minRating = 0;
mstreamModule.toggleAutoDJ = function () {
mstreamModule.playerStats.autoDJ = !mstreamModule.playerStats.autoDJ;