« get me outta code hell

Add --filter - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/play.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-09-28 22:00:45 -0300
committerFlorrie <towerofnix@gmail.com>2017-09-28 22:00:45 -0300
commit94c68dbdca1bb57086cd5921f87f47b8a30e21fa (patch)
treed3deb7b744e648639fdbf0e76aca326e8235a51a /src/play.js
parenteadd4ad2e26f47c529ffcbc3c96685947ee8b81c (diff)
Add --filter
Diffstat (limited to 'src/play.js')
-rwxr-xr-xsrc/play.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/play.js b/src/play.js
index 6061d09..6adbb9c 100755
--- a/src/play.js
+++ b/src/play.js
@@ -14,7 +14,7 @@ const processSmartPlaylist = require('./smart-playlist')
 
 const {
   filterPlaylistByPathString, removeGroupByPathString, getPlaylistTreeString,
-  updatePlaylistFormat, collapseGrouplike
+  updatePlaylistFormat, collapseGrouplike, filterGrouplikeByProperty
 } = require('./playlist-utils')
 
 const readFile = promisify(fs.readFile)
@@ -300,6 +300,20 @@ 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.
+
+      const property = util.nextArg()
+      const value = util.nextArg()
+
+      const p = filterGrouplikeByProperty(activePlaylist, property, value)
+      activePlaylist = updatePlaylistFormat(p)
+    },
+
+    'f': util => util.alias('-filter'),
+
     '-collapse-groups': function() {
       // --collapse-groups  (alias: --collapse)
       // Collapses groups in the active playlist so that there is only one