From 1b5d6f8f96baae53367a7a7d0f9485a42029eaa3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 16 Feb 2018 11:02:51 -0400 Subject: Make --track-display-file show SOURCE path to track This also means we're keeping track of the source item of items, which is sure to be useful more later. --- src/loop-play.js | 6 ++++-- src/play.js | 4 +++- src/playlist-utils.js | 15 ++++++++++----- 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, -- cgit 1.3.0-6-gf8a5