diff options
author | Florrie <towerofnix@gmail.com> | 2018-02-18 23:44:07 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-02-18 23:44:08 -0400 |
commit | b2ac9246886f72bef8b96cf218ed2d803397dafa (patch) | |
tree | df7c287fc517f9837de15fda35bce6faae2b8e22 /src/play.js | |
parent | 86e42f7a7ec5cf27e2186d111017fe7943acd079 (diff) |
Make completely new filter system
See the man page for how it works now.
Diffstat (limited to 'src/play.js')
-rwxr-xr-x | src/play.js | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/play.js b/src/play.js index 158c887..462cd88 100755 --- a/src/play.js +++ b/src/play.js @@ -335,16 +335,25 @@ async function main(args) { 'r': util => util.alias('-remove'), 'x': util => util.alias('-remove'), - '-filter': function(util) { - // --filter <property> <value> (alias: -f) - // Filters the playlist so that only tracks with the given property- - // value pair are kept. + '-filter': async function(util) { + // --filter <filterJSON> + // Filters the playlist so that only tracks that match the given filter + // are kept. FilterJSON should be a JSON object as described in the + // man page section "filters". - const property = util.nextArg() - const value = util.nextArg() + const filterJSON = util.nextArg() - const p = filterGrouplikeByProperty(activePlaylist, property, value) - activePlaylist = updatePlaylistFormat(p) + let filterObj + try { + filterObj = JSON.parse(filterJSON) + } catch (error) { + console.error('Invalid JSON for filter:', filterJSON) + return + } + + activePlaylist.filters = [filterObj] + activePlaylist = await processSmartPlaylist(activePlaylist) + activePlaylist = updatePlaylistFormat(activePlaylist) }, 'f': util => util.alias('-filter'), |