« get me outta code hell

Add --start-at option and 'track version' concept - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/pickers.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-10-12 23:04:47 -0300
committerFlorrie <towerofnix@gmail.com>2017-10-12 23:04:47 -0300
commitaa9a8404f426562ce049171fa97b5714305b1459 (patch)
tree472858df27cac402836a983fc7afbb2f0942d8ea /src/pickers.js
parentd16f7efae8f7b9a142ca9514bc98b41eb4ee16c8 (diff)
Add --start-at option and 'track version' concept
Diffstat (limited to 'src/pickers.js')
-rw-r--r--src/pickers.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/pickers.js b/src/pickers.js
index 245e16f..1afa0c2 100644
--- a/src/pickers.js
+++ b/src/pickers.js
@@ -15,7 +15,7 @@ const _seedRandom = require('seed-random')
 // Uncertain on how to handle serialization of tracks.. some tracks may appear twice in the same playlist (or two tracks of the same name appear); in this case the serialized path to the two track appearances is the same, when they really refer to two separate instances of the track within the playlist. Could track serialization instead be index-based (rather than name-based)..?
 
 const {
-  flattenGrouplike, isGroup, updatePlaylistFormat
+  flattenGrouplike, isGroup, updatePlaylistFormat, isSameTrack
 } = require('./playlist-utils')
 
 class HistoryController {
@@ -212,7 +212,20 @@ function generalPicker(sourcePlaylist, lastTrack, options) {
     // console.log('\x1b[1K\rDone indexing.')
   }
 
-  const index = playlist.items.indexOf(lastTrack)
+  let index
+
+  if (lastTrack !== null) {
+    // The "current" version of the last track (that is, the object
+    // representing this track which appears in the flattened/updated/cached
+    // playlist).
+    const currentLastTrack = playlist.items.find(
+      t => isSameTrack(t, lastTrack)
+    )
+
+    index = playlist.items.indexOf(currentLastTrack)
+  } else {
+    index = -1
+  }
 
   if (index === -1) {
     return playlist.items[0]