Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
feat(player): add option to export playing title to file (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Apr 5, 2020
1 parent ecce33f commit aaddffb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/xerus/monstercat/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/main/xerus/monstercat/api/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -167,7 +179,6 @@ object Player: FadingHBox(true, targetHeight = 25) {
}
}
}

updateCover(track.release.coverUrl)
}

Expand Down Expand Up @@ -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!!)
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/xerus/monstercat/tabs/TabSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit aaddffb

Please sign in to comment.