From aaddffb39246655be9f01f0fd7ff83f6968eefe6 Mon Sep 17 00:00:00 2001 From: xerus <27jf@pm.me> Date: Sun, 5 Apr 2020 21:49:53 +0200 Subject: [PATCH] feat(player): add option to export playing title to file (#73) --- src/main/xerus/monstercat/Settings.kt | 2 ++ src/main/xerus/monstercat/api/Player.kt | 15 +++++++++++++-- src/main/xerus/monstercat/tabs/TabSettings.kt | 10 +++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/xerus/monstercat/Settings.kt b/src/main/xerus/monstercat/Settings.kt index 78d2c03..f717131 100644 --- a/src/main/xerus/monstercat/Settings.kt +++ b/src/main/xerus/monstercat/Settings.kt @@ -15,6 +15,7 @@ import xerus.monstercat.tabs.TabSettings import xerus.monstercat.tabs.availableColumns import xerus.monstercat.tabs.defaultColumns import java.io.File +import java.nio.file.Paths object Settings: SettingsNode("xerus/monsterutilities") { private val logger = KotlinLogging.logger { } @@ -24,6 +25,7 @@ object Settings: SettingsNode("xerus/monsterutilities") { val PLAYERSCROLLSENSITIVITY = create("playerSeekbarScrollSensitivity", 6.0) val PLAYERSEEKBARHEIGHT = create("playerSeekbarHeight", 8.0) val PLAYERARTPRIORITY = create("coverartPriorityList", TabSettings.PriorityList.SGL_ALB_COL) { TabSettings.PriorityList.valueOf(it) } + val PLAYEREXPORTFILE = create("playerExportFile", Paths.get("")) val SKIPUNLICENSABLE = create("skipUnlicensable", false) // Equalizer diff --git a/src/main/xerus/monstercat/api/Player.kt b/src/main/xerus/monstercat/api/Player.kt index 050e352..a0996f8 100644 --- a/src/main/xerus/monstercat/api/Player.kt +++ b/src/main/xerus/monstercat/api/Player.kt @@ -25,10 +25,13 @@ import xerus.ktutil.javafx.ui.controls.FadingHBox import xerus.ktutil.javafx.ui.transitionToHeight import xerus.ktutil.javafx.ui.verticalFade import xerus.ktutil.square +import xerus.ktutil.write import xerus.monstercat.Settings import xerus.monstercat.api.response.Release import xerus.monstercat.api.response.Track import xerus.monstercat.monsterUtilities +import java.nio.file.Files +import java.nio.file.StandardOpenOption import java.util.* import java.util.concurrent.TimeUnit import kotlin.concurrent.schedule @@ -79,6 +82,7 @@ object Player: FadingHBox(true, targetHeight = 25) { } private val label = Label() + /** clears the [children] and shows the [label] with [text] */ private fun showText(text: String) { ensureVisible() @@ -109,6 +113,10 @@ object Player: FadingHBox(true, targetHeight = 25) { /** hides the Player and appears again displaying the latest Release */ fun reset() { fadeOut() + if(!Files.isDirectory(Settings.PLAYEREXPORTFILE())) { + Files.write(Settings.PLAYEREXPORTFILE(), arrayListOf(""), StandardOpenOption.CREATE) + logger.debug("Cleared export file (${Settings.PLAYEREXPORTFILE()}) from its contents") + } GlobalScope.launch { val latest = Cache.getReleases().firstOrNull() ?: return@launch while(fading) delay(50) @@ -157,6 +165,10 @@ object Player: FadingHBox(true, targetHeight = 25) { setOnEndOfMedia { playNext() } setOnReady { label.text = "Now Playing: $track" + if(!Files.isDirectory(Settings.PLAYEREXPORTFILE())) { + Files.write(Settings.PLAYEREXPORTFILE(), arrayListOf("$track"), StandardOpenOption.CREATE) + logger.debug("""Wrote "$track" into export file (${Settings.PLAYEREXPORTFILE()})""") + } val total = totalDuration.toMillis() seekBar.progressProperty().dependOn(currentTimeProperty()) { it.toMillis() / total } seekBar.transitionToHeight(Settings.PLAYERSEEKBARHEIGHT(), 1.0) @@ -167,7 +179,6 @@ object Player: FadingHBox(true, targetHeight = 25) { } } } - updateCover(track.release.coverUrl) } @@ -221,7 +232,7 @@ object Player: FadingHBox(true, targetHeight = 25) { if(coverUrl != null) { val imageView = ImageView(Covers.getThumbnailImage(coverUrl!!, 24)) imageView.setOnMouseClicked { - if (it.button == MouseButton.PRIMARY) { + if(it.button == MouseButton.PRIMARY) { monsterUtilities.viewCover(coverUrl!!) } } diff --git a/src/main/xerus/monstercat/tabs/TabSettings.kt b/src/main/xerus/monstercat/tabs/TabSettings.kt index c598068..909e78e 100644 --- a/src/main/xerus/monstercat/tabs/TabSettings.kt +++ b/src/main/xerus/monstercat/tabs/TabSettings.kt @@ -26,8 +26,12 @@ import org.controlsfx.validation.Validator import xerus.ktutil.byteCountString import xerus.ktutil.helpers.Named import xerus.ktutil.javafx.* -import xerus.ktutil.javafx.properties.* +import xerus.ktutil.javafx.properties.ImmutableObservable +import xerus.ktutil.javafx.properties.ImmutableObservableList +import xerus.ktutil.javafx.properties.dependOn +import xerus.ktutil.javafx.properties.listen import xerus.ktutil.javafx.ui.App +import xerus.ktutil.javafx.ui.FileChooser import xerus.ktutil.javafx.ui.createAlert import xerus.monstercat.Settings import xerus.monstercat.api.Cache @@ -91,6 +95,10 @@ class TabSettings: VTab() { }) addLabeled("Player Coverart priorities:", createComboBox(Settings.PLAYERARTPRIORITY)) + // Export chooser + val exportFileChooser = FileChooser(App.stage, Settings.PLAYEREXPORTFILE().toFile(), "", "export file").apply { selectedFile.listen { Settings.PLAYEREXPORTFILE.set(it.toPath()) } } + addRow(Label("Export currently played track :"), exportFileChooser.button().allowExpand(vertical = false), exportFileChooser.textField()) + addLabeled("Internet Bandwidth", createComboBox(Settings.CONNECTIONSPEED)) add(CheckBox("Enable Streamer Mode (hover to read more)").bind(Settings.SKIPUNLICENSABLE))