From aa9a8404f426562ce049171fa97b5714305b1459 Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 12 Oct 2017 23:04:47 -0300 Subject: Add --start-at option and 'track version' concept --- src/pickers.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/pickers.js') 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] -- cgit 1.3.0-6-gf8a5