Skip to content

Commit

Permalink
Categorize playlists in folders
Browse files Browse the repository at this point in the history
Added playlists: tracks added in last 1 week/3 months/6 months/1 year
  • Loading branch information
ivesdebruycker committed Dec 1, 2016
1 parent e57df00 commit 0c45b38
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 94 deletions.
34 changes: 5 additions & 29 deletions UIConfig.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
{
"id": "section_random",
"element": "section",
"label": "Random playlists",
"label": "Live playlists",
"icon": "fa-list-ol",
"onSave": {"type":"controller", "endpoint":"music_service/live_playlists", "method":"savePluginOptions"},
"saveButton": {
"label": "Save",
"data": [
"filter_path",
"random_10",
"random_50",
"random_100",
"random_500",
"random",
"latest"
]
},
Expand All @@ -30,31 +27,10 @@
"value": ""
},
{
"id":"random_10",
"id":"random",
"element": "switch",
"doc": "Playlist with 10 items",
"label": "10 items",
"value": true
},
{
"id":"random_50",
"element": "switch",
"doc": "Playlist with 50 items",
"label": "50 items",
"value": true
},
{
"id":"random_100",
"element": "switch",
"doc": "Playlist with 100 items",
"label": "100 items",
"value": true
},
{
"id":"random_500",
"element": "switch",
"doc": "Playlist with 500 items",
"label": "500 items",
"doc": "Playlists with random tracks",
"label": "Random",
"value": true
},
{
Expand Down
14 changes: 1 addition & 13 deletions config.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@
"type": "string",
"value": ""
},
"random_10":{
"random":{
"type": "boolean",
"value": true
},
"random_50":{
"type": "boolean",
"value": true
},
"random_100":{
"type": "boolean",
"value": true
},
"random_500":{
"type": "boolean",
"value": false
},
"latest":{
"type": "boolean",
"value": true
Expand Down
193 changes: 141 additions & 52 deletions index.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var libQ = require('kew');
var libMpd = require('mpd');
var moment = require('moment');

module.exports = live_playlists;

Expand Down Expand Up @@ -29,6 +30,7 @@ live_playlists.prototype.onVolumioStart = function () {
live_playlists.prototype.onStart = function () {
var self = this;
self.addToBrowseSources();

return libQ.resolve();
}

Expand Down Expand Up @@ -65,52 +67,107 @@ live_playlists.prototype.handleBrowseUri = function (curUri) {
});*/

if(curUri == 'live_playlists') {
if (self.config.get('random_10')) {
list.push({
type: 'playlist',
title: '10 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_10'
});
}
if (self.config.get('random_50')) {
list.push({
type: 'playlist',
title: '50 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_50'
});
}
if (self.config.get('random_100')) {
list.push({
type: 'playlist',
title: '100 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_100'
});
}
if (self.config.get('random_500')) {
if (self.config.get('random')) {
list.push({
type: 'playlist',
title: '500 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_500'
service: 'live_playlists',
type: 'folder',
title: 'Random tracks',
artist: '',
album: '',
icon: 'fa fa-folder-open-o',
uri: 'live_playlists_random'
});
}
if (self.config.get('latest')) {
list.push({
type: 'playlist',
title: 'Latest tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
service: 'live_playlists',
type: 'folder',
title: 'Recently added tracks',
artist: '',
album: '',
icon: 'fa fa-folder-open-o',
uri: 'live_playlists_latest'
});
}
list.push({
service: 'live_playlists',
type: 'folder',
title: 'Tracks by decade',
artist: '',
album: '',
icon: 'fa fa-folder-open-o',
uri: 'live_playlists_decade'
});
} else if (curUri == 'live_playlists_random') {
response.navigation.prev.uri = "live_playlists";
list.push({
type: 'playlist',
title: '10 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_10'
});
list.push({
type: 'playlist',
title: '50 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_50'
});
list.push({
type: 'playlist',
title: '100 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_100'
});
list.push({
type: 'playlist',
title: '500 random tracks',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_random_500'
});
} else if (curUri == 'live_playlists_latest') {
response.navigation.prev.uri = "live_playlists";
list.push({
type: 'playlist',
title: 'Tracks added in last week',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_latest_1_week'
});
list.push({
type: 'playlist',
title: 'Tracks added in last month',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_latest_1_month'
});
list.push({
type: 'playlist',
title: 'Tracks added in last 3 months',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_latest_3_months'
});
list.push({
type: 'playlist',
title: 'Tracks added in last 6 months',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_latest_6_months'
});
list.push({
type: 'playlist',
title: 'Tracks added in last year',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_latest_1_year'
});
} else if (curUri == 'live_playlists_decade') {
response.navigation.prev.uri = "live_playlists";
/*list.push({
type: 'playlist',
title: 'Tracks from 2015',
service:'live_playlists',
Expand All @@ -123,7 +180,7 @@ live_playlists.prototype.handleBrowseUri = function (curUri) {
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_year_2016'
});
});*/
list.push({
type: 'playlist',
title: 'Tracks from the 80s',
Expand All @@ -138,8 +195,23 @@ live_playlists.prototype.handleBrowseUri = function (curUri) {
icon: 'fa fa-list-ol',
uri: 'live_playlists_year_90s'
});
defer.resolve(response);
list.push({
type: 'playlist',
title: 'Tracks from the 00s',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_year_00s'
});
list.push({
type: 'playlist',
title: 'Tracks from the 10s',
service:'live_playlists',
icon: 'fa fa-list-ol',
uri: 'live_playlists_year_10s'
});
}

defer.resolve(response);
}
return defer.promise;
}
Expand Down Expand Up @@ -184,14 +256,37 @@ live_playlists.prototype.explodeUri = function(uri) {
case 'live_playlists_year_90s':
return self.findByYearRange(1990, 1999);
break;
case 'live_playlists_year_00s':
return self.findByYearRange(2000, 2009);
break;
case 'live_playlists_year_10s':
return self.findByYearRange(2010, 2019);
break;
default:
return self.findByYear(2000);
break;
}
}

if (uri === 'live_playlists_latest') {
return self.findLastAdded();
if (uri.startsWith('live_playlists_latest_')) {
switch (uri) {
case 'live_playlists_latest_1_week':
return self.findLastAdded(1, 'weeks');
break;
case 'live_playlists_latest_1_month':
return self.findLastAdded(1, 'months');
break;
case 'live_playlists_latest_3_months':
return self.findLastAdded(3, 'months');
break;
case 'live_playlists_latest_6_months':
return self.findLastAdded(6, 'months');
break;
case 'live_playlists_latest_1_year':
default:
return self.findLastAdded(1, 'years');
break;
}
}
};

Expand Down Expand Up @@ -228,13 +323,13 @@ live_playlists.prototype.getRandom = function(count) {
return defer.promise;
};

live_playlists.prototype.findLastAdded = function() {
live_playlists.prototype.findLastAdded = function(num, timeUnit) {
var filter_path = '';
if (this.config.get('filter_path')) {
filter_path = 'base "' + this.config.get('filter_path') + '"';
}

return this.executeFind('modified-since "2016-06-01T00:00:00Z" ' + filter_path);
return this.executeFind('modified-since "' + moment().startOf('date').subtract(num, timeUnit).utc().format('YYYY-MM-DD[T]HH:mm:ss[Z]') + '" ' + filter_path);
};

live_playlists.prototype.findByYear = function(year) {
Expand Down Expand Up @@ -390,12 +485,8 @@ live_playlists.prototype.getUIConfig = function() {
.then(function(uiconf)
{
uiconf.sections[0].content[0].value = self.config.get('filter_path');
uiconf.sections[0].content[1].value = self.config.get('random_10');
uiconf.sections[0].content[2].value = self.config.get('random_50');
uiconf.sections[0].content[3].value = self.config.get('random_100');
uiconf.sections[0].content[4].value = self.config.get('random_500');
uiconf.sections[0].content[5].value = self.config.get('latest');

uiconf.sections[0].content[1].value = self.config.get('random');
uiconf.sections[0].content[2].value = self.config.get('latest');
defer.resolve(uiconf);
})
.fail(function()
Expand Down Expand Up @@ -448,9 +539,7 @@ live_playlists.prototype.savePluginOptions = function (data) {
var defer = libQ.defer();

self.config.set('filter_path', data.filter_path);
self.config.set('random_10', data.random_10);
self.config.set('random_50', data.random_50);
self.config.set('random_100', data.random_100);
self.config.set('random', data.random);
self.config.set('latest', data.latest);

self.logger.info('Live playlists configurations have been set');
Expand Down
1 change: 1 addition & 0 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"kew": "^0.7.0",
"moment": "^2.17.0",
"mpd": "^1.3.0",
"v-conf": "^0.10.0"
},
Expand Down

0 comments on commit 0c45b38

Please sign in to comment.