« get me outta code hell

Case-insensitive group matching - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-06-12 09:40:21 -0300
committerliam4 <towerofnix@gmail.com>2017-06-12 09:40:21 -0300
commit27a65ba0f50529bfb0c72b7c9967b86bcd186e05 (patch)
tree82d26137c1b93b4ae867e17f9ddedb2a0f46ec44
parentbafe90fb6a0c7fcb911df537ef448bbbb9ecf457 (diff)
Case-insensitive group matching
-rw-r--r--src/playlist-utils.js23
-rw-r--r--todo.txt6
2 files changed, 24 insertions, 5 deletions
diff --git a/src/playlist-utils.js b/src/playlist-utils.js
index f65e247..b0eb4f0 100644
--- a/src/playlist-utils.js
+++ b/src/playlist-utils.js
@@ -24,12 +24,25 @@ function filterPlaylistByPath(playlist, pathParts) {
   // function encounters an item in the group path that is not found, it logs
   // a warning message and returns the group found up to that point.
 
-  let cur = pathParts[0]
+  const titleMatch = (group, caseInsensitive = false) => {
+    let a = getGroupTitle(group)
+    let b = cur
 
-  const match = playlist.find(group => {
-    const title = getGroupTitle(group)
-    return title === cur || title === cur + '/'
-  })
+    if (caseInsensitive) {
+      a = a.toLowerCase()
+      b = b.toLowerCase()
+    }
+
+    return a === b
+  }
+
+  const cur = pathParts[0]
+
+  let match = playlist.find(g => titleMatch(g, false))
+
+  if (!match) {
+    match = playlist.find(g => titleMatch(g, true))
+  }
 
   if (match) {
     if (pathParts.length > 1) {
diff --git a/todo.txt b/todo.txt
index 129805c..bbb23f2 100644
--- a/todo.txt
+++ b/todo.txt
@@ -122,3 +122,9 @@ TODO: Figure out how to attempt to avoid being forced to convert every file..
       converting a 10MB MP3 into an 80MB WAV is never good, even if we're
       storing it as a tempfile!
       (Done!)
+
+TODO: Let playlist filter match things lowercase. '72 Minutes Of Fame' should
+      be matched if '72 Minutes of Fame' can't be! (However, it would also be
+      best to prioritize a case-sensitive match before a non-case-sensitive
+      one. Given the input 'FoObAR', prioritize 'FoObAR' over 'Foobar'.)
+      (Done!)