« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js6
-rwxr-xr-xsrc/play.js4
-rw-r--r--src/playlist-utils.js15
3 files changed, 17 insertions, 8 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index e82e77e..83cbcfe 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -23,7 +23,7 @@ const {
 } = require('./downloaders')
 
 const {
-  getItemPathString, safeUnlink, parentSymbol
+  getItemPathString, safeUnlink, parentSymbol, sourceSymbol
 } = require('./playlist-utils')
 
 function createStatusLine({percentStr, curStr, lenStr}) {
@@ -450,7 +450,9 @@ class PlayController extends EventEmitter {
 
       if (next) {
         if (this.trackDisplayFile) {
-          await writeFile(this.trackDisplayFile, getItemPathString(this.currentTrack))
+          await writeFile(this.trackDisplayFile,
+            getItemPathString(this.currentTrack[sourceSymbol])
+          )
         }
 
         await this.playFile(next)
diff --git a/src/play.js b/src/play.js
index a3481ea..d5df591 100755
--- a/src/play.js
+++ b/src/play.js
@@ -158,7 +158,9 @@ async function main(args) {
 
     // ..And finally, we have to update the playlist format again, since
     // processSmartPlaylist might have added new (un-updated) items:
-    const finalPlaylist = updatePlaylistFormat(processedPlaylist)
+    const finalPlaylist = updatePlaylistFormat(processedPlaylist, true)
+    // We also pass true so that the playlist-format-updater knows that this
+    // is the source playlist.
 
     sourcePlaylist = finalPlaylist
 
diff --git a/src/playlist-utils.js b/src/playlist-utils.js
index 5343fb4..dad828c 100644
--- a/src/playlist-utils.js
+++ b/src/playlist-utils.js
@@ -8,8 +8,9 @@ const unlink = promisify(fs.unlink)
 
 const parentSymbol = Symbol('Parent group')
 const oldSymbol = Symbol('Old track or group reference')
+const sourceSymbol = Symbol('Source-playlist item reference')
 
-function updatePlaylistFormat(playlist) {
+function updatePlaylistFormat(playlist, firstTime = false) {
   const defaultPlaylist = {
     options: [],
     items: []
@@ -39,10 +40,10 @@ function updatePlaylistFormat(playlist) {
 
   const fullPlaylistObj = Object.assign(defaultPlaylist, playlistObj)
 
-  return updateGroupFormat(fullPlaylistObj)
+  return updateGroupFormat(fullPlaylistObj, firstTime)
 }
 
-function updateGroupFormat(group) {
+function updateGroupFormat(group, firstTime = false) {
   const defaultGroup = {
     name: '',
     items: [],
@@ -62,7 +63,7 @@ function updateGroupFormat(group) {
   groupObj.items = groupObj.items.map(item => {
     // Check if it's a group; if not, it's probably a track.
     if (typeof item[1] === 'array' || item.items) {
-      item = updateGroupFormat(item)
+      item = updateGroupFormat(item, firstTime)
     } else {
       item = updateTrackFormat(item)
 
@@ -79,6 +80,10 @@ function updateGroupFormat(group) {
 
     item[parentSymbol] = groupObj
 
+    if (firstTime) {
+      item[sourceSymbol] = item
+    }
+
     return item
   })
 
@@ -517,7 +522,7 @@ async function safeUnlink(file, playlist) {
 }
 
 module.exports = {
-  parentSymbol, oldSymbol,
+  parentSymbol, oldSymbol, sourceSymbol,
   updatePlaylistFormat, updateTrackFormat,
   flattenGrouplike,
   partiallyFlattenGrouplike, collapseGrouplike,