diff options
author | Florrie <towerofnix@gmail.com> | 2018-06-05 10:36:16 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-06-05 10:36:16 -0300 |
commit | 165d11534ebb20d100d14e8001f49afc50e5952a (patch) | |
tree | 89df927f0017c9bb6fb41c94cf7036856c32f5e5 | |
parent | 8207422459bce7fc3ca3f919ef426e54eaa826b0 (diff) |
Save current track to file / layout cleanup
-rw-r--r-- | ui.js | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/ui.js b/ui.js index 7a524ee..f91dd62 100644 --- a/ui.js +++ b/ui.js @@ -1,6 +1,6 @@ const { getDownloaderFor } = require('./downloaders') const { getPlayer } = require('./players') -const { parentSymbol, isGroup, isTrack, getItemPath } = require('./playlist-utils') +const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString } = require('./playlist-utils') const { shuffleArray } = require('./general-util') const ansi = require('./tui-lib/util/ansi') const Button = require('./tui-lib/ui/form/Button') @@ -12,6 +12,11 @@ const ListScrollForm = require('./tui-lib/ui/form/ListScrollForm') const Pane = require('./tui-lib/ui/Pane') const RecordStore = require('./record-store') const telc = require('./tui-lib/util/telchars') +const unic = require('./tui-lib/util/unichars') + +const fs = require('fs') +const { promisify } = require('util') +const writeFile = promisify(fs.writeFile) class AppElement extends FocusElement { constructor() { @@ -21,6 +26,7 @@ class AppElement extends FocusElement { this.recordStore = new RecordStore() this.queueGrouplike = {isTheQueue: true, items: []} + this.rootDirectory = process.env.HOME + '/.http-music' this.form = new Form() this.addChild(this.form) @@ -295,6 +301,14 @@ class AppElement extends FocusElement { if (!this.queueListingElement.isSelected) { this.queueListingElement.selectAndShow(item) } + + await Promise.all([ + writeFile(this.rootDirectory + '/current-track.txt', + getItemPathString(item)), + writeFile(this.rootDirectory + '/current-track.json', + JSON.stringify(item, null, 2)) + ]) + try { await this.player.playFile(downloadFile) } finally { @@ -672,6 +686,15 @@ class PlaybackInfoElement extends DisplayElement { this.progressBarLabel.y = 1 this.progressTextLabel.y = this.progressBarLabel.y this.downloadLabel.y = 2 + + if (this.currentTrack) { + const dl = this.currentTrack.downloaderArg + let dlText = dl.slice(Math.max(dl.length - this.w + 20, 0)) + if (dlText !== dl) { + dlText = unic.ELLIPSIS + dlText + } + this.downloadLabel.text = `(From: ${dlText})` + } } updateProgress({timeDone, timeLeft, duration, lenSecTotal, curSecTotal}) { @@ -681,12 +704,13 @@ class PlaybackInfoElement extends DisplayElement { } updateTrack(track) { + this.currentTrack = track this.trackNameLabel.text = track.name - this.downloadLabel.text = `(From: ${track.downloaderArg})` this.fixLayout() } clearInfo() { + this.currentTrack = null this.progressBarLabel.text = '' this.progressTextLabel.text = '' this.trackNameLabel.text = '' |