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

Commit 79ed6a5

Browse files
author
Xerus
committed
Merge branch 'master' into genres
2 parents 2f8e685 + 5fe6419 commit 79ed6a5

23 files changed

+324
-221
lines changed

Readme.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,55 @@ Browse, stream and download Monstercat Songs, powered by the Monstercat API and
66

77
## Usage
88

9-
[Download](http://monsterutilities.bplaced.net/downloads?download)
9+
[Download](http://monsterutilities.bplaced.net/downloads?download) or use the GitHub releases.
1010

1111
> This is a pre-Release, you may encounter bugs.
1212
If you do, open an issue here or send feedback from inside the application.
1313
The latter will automatically include logs, which reside in `TEMP/monsterutilities/logs`
1414

1515
To run it, you need to have Java 8 by Oracle installed on your computer.
1616

17-
Read the initial guide and follow the tooltips. Improved user-friendliness is in development ;)
17+
Read the initial guide and follow the tooltips.
18+
Improved user-friendliness is in development ;)
19+
20+
### Troubleshooting
21+
22+
#### connect.sid
23+
24+
For downloading and listening to the latest Track, your `connect.sid`
25+
needs to be entered in the bottom of the Downloader. It is a cookie that
26+
identifies your Monstercat Account. Here's how to obtain it:
27+
28+
1) Log in on [monstercat.com](https://monstercat.com) and ensure that you have a valid Monstercat Gold subscription
29+
2) Go to your browser cookies and search for `connect.monstercat.com`
30+
[Quick link for Chrome](chrome://settings/cookies/detail?site=connect.monstercat.com)
31+
3) Find the content of `connect.sid`. It is a string starting with `s%3A` and has around 90 characters.
32+
4) Copy that string into the `connect.sid` Textfield at the bottom of the Downloader.
33+
34+
#### Downloader
35+
36+
Sometimes, the cache runs into issues and that may contribute to issues in the Downloader.
37+
Simply disable the cache, restart the application and enable it again.
38+
39+
> If you still have issues - no problem!
40+
> Hit me up on [Discord](https://discord.gg/ZEusvHS) or send Feedback directly from the application!
1841
1942
## Screenshots
2043

2144
### Catalog
2245

23-
The Catalog provides an overview of all Tracks ever released on the label and extensive possibilities of filtering them.
46+
The Catalog provides an overview of all Tracks ever released on the label and
47+
extensive possibilities of filtering them.
2448
> Tip: You can customize which columns to show by clicking on the `+` in the top right
2549
2650
![Catalog](assets/screenshots/catalog.png)
2751
![Catalog filtering](assets/screenshots/filtering.png)
2852

2953
### Streaming
3054

31-
In case you missed it in the other Screenshots: There's a player on top that can stream any Monstercat track,
32-
just like the website. Double-click on any piece in the Catalog or Downloader to load it into the Player!
33-
55+
In case you missed it in the other Screenshots:
56+
There's a player on top that can stream any Monstercat track, just like the website.
57+
Double-click on any piece in the Catalog or Downloader to load it into the Player!
3458
![Player](assets/screenshots/player.png)
3559

3660
### Downloader

build.gradle.kts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ version = "dev" + Scanner(Runtime.getRuntime().exec("git rev-list --count HEAD")
1212
file("src/resources/version").writeText(version as String)
1313

1414
plugins {
15-
kotlin("jvm") version "1.2.61"
15+
kotlin("jvm") version "1.2.70"
1616
application
1717
id("com.github.johnrengelman.shadow") version "2.0.4"
18-
id("com.github.ben-manes.versions") version "0.19.0"
18+
id("com.github.ben-manes.versions") version "0.20.0"
1919
}
2020

2121
// source directories
@@ -47,19 +47,19 @@ repositories {
4747
}
4848

4949
dependencies {
50-
compile("com.github.Xerus2000", "util", "master-SNAPSHOT")
51-
compile(kotlin("stdlib-jdk8"))
52-
compile(kotlin("reflect"))
50+
implementation(kotlin("reflect"))
5351

54-
compile("org.controlsfx", "controlsfx", "8.40.14")
52+
implementation("com.github.Xerus2000.util", "javafx", "-SNAPSHOT")
53+
implementation("org.controlsfx", "controlsfx", "8.40.14")
5554

56-
compile("be.bluexin", "drpc4k", "0.6-SNAPSHOT")
55+
implementation("ch.qos.logback", "logback-classic", "1.2.3")
56+
implementation("com.github.Xerus2000", "drpc4k", "-SNAPSHOT")
57+
implementation("org.apache.httpcomponents", "httpmime", "4.5.+")
58+
implementation("com.google.apis", "google-api-services-sheets", "v4-rev542-1.25.0")
5759

58-
compile("org.apache.httpcomponents", "httpmime", "4.5.5")
59-
compile("com.google.apis", "google-api-services-sheets", "v4-rev527-1.23.0")
60-
61-
testCompile("org.junit.jupiter", "junit-jupiter-api", "5.2.0")
62-
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.2.0")
60+
val junitVersion = "5.3.1"
61+
testCompile("org.junit.jupiter", "junit-jupiter-api", junitVersion)
62+
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junitVersion)
6363
}
6464

6565
val file
@@ -73,8 +73,8 @@ tasks {
7373

7474
"run"(JavaExec::class) {
7575
group = MAIN
76-
// Usage: gradle run -Dargs="FINE save"
77-
args = System.getProperty("args", "").split(" ")
76+
// Usage: gradle run -Dargs="--loglevel trace"
77+
args = System.getProperty("args", "--loglevel debug").split(" ")
7878
}
7979

8080
"shadowJar"(ShadowJar::class) {
@@ -112,7 +112,7 @@ tasks {
112112
setDelete(file(".").listFiles { f -> f.name.run { startsWith("MonsterUtilities-") && endsWith("jar") && this != file } })
113113
}
114114

115-
"test"(Test::class) {
115+
withType<Test> {
116116
useJUnitPlatform()
117117
}
118118

src/archive/Downloader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DownloaderSwing : BasePanel() {
4444
}
4545

4646
init {
47-
launch {
47+
GlobalScope.launch {
4848
logger.fine("DownloadWorker started")
4949

5050
var limit = LIMIT.int
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package xerus.monstercat
2+
3+
import ch.qos.logback.classic.Level
4+
import ch.qos.logback.classic.LoggerContext
5+
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
6+
import ch.qos.logback.classic.filter.LevelFilter
7+
import ch.qos.logback.classic.filter.ThresholdFilter
8+
import ch.qos.logback.classic.spi.Configurator
9+
import ch.qos.logback.classic.spi.ILoggingEvent
10+
import ch.qos.logback.core.ConsoleAppender
11+
import ch.qos.logback.core.FileAppender
12+
import ch.qos.logback.core.rolling.RollingFileAppender
13+
import ch.qos.logback.core.spi.ContextAwareBase
14+
import kotlinx.coroutines.experimental.GlobalScope
15+
import kotlinx.coroutines.experimental.launch
16+
import mu.KotlinLogging
17+
import org.slf4j.Logger
18+
import org.slf4j.LoggerFactory
19+
import xerus.ktutil.currentSeconds
20+
import xerus.ktutil.getStackTraceString
21+
import java.io.File
22+
23+
private val logDir: File
24+
get() = cacheDir.resolve("logs").apply { mkdirs() }
25+
private val logFile = logDir.resolve("log${currentSeconds()}.txt")
26+
private var logLevel: Level = Level.WARN
27+
28+
internal fun initLogging(args: Array<String>) {
29+
args.indexOf("--loglevel").takeIf { it > -1 }?.let {
30+
logLevel = args.getOrNull(it + 1)?.let { Level.toLevel(it, null) } ?: run {
31+
println("WARNING: Loglevel argument given without a valid value! Use one of {OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL}")
32+
return@let
33+
}
34+
}
35+
Thread.setDefaultUncaughtExceptionHandler { thread, ex ->
36+
LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).warn("Uncaught exception in $thread: ${ex.getStackTraceString()}")
37+
}
38+
val logger = KotlinLogging.logger { }
39+
logger.info("Console loglevel: $logLevel")
40+
logger.info("Logging to $logFile")
41+
GlobalScope.launch {
42+
val logs = logDir.listFiles()
43+
if (logs.size > 10) {
44+
logs.asSequence().sortedByDescending { it.name }.drop(5).filter {
45+
val timestamp = it.nameWithoutExtension.substring(3).toIntOrNull() ?: return@filter true
46+
timestamp + 200_000 < currentSeconds()
47+
}.also {
48+
val count = it.count()
49+
if (count > 0)
50+
logger.debug("Deleting $count old logs")
51+
}.forEach { it.delete() }
52+
}
53+
}
54+
}
55+
56+
internal class LogbackConfigurator : ContextAwareBase(), Configurator {
57+
58+
override fun configure(lc: LoggerContext) {
59+
60+
val encoder = PatternLayoutEncoder().apply {
61+
context = lc
62+
pattern = "%d{HH:mm:ss} [%-25.25thread] %-5level %-30logger{30} %msg%n"
63+
start()
64+
}
65+
66+
val consoleAppender = ConsoleAppender<ILoggingEvent>().apply {
67+
name = "console"
68+
context = lc
69+
this.encoder = encoder
70+
addFilter(ThresholdFilter().apply {
71+
setLevel(logLevel.toString())
72+
start()
73+
})
74+
start()
75+
}
76+
77+
val fileAppender = FileAppender<ILoggingEvent>().apply {
78+
name = "file"
79+
file = logFile.toString()
80+
context = lc
81+
this.encoder = encoder
82+
start()
83+
}
84+
85+
val rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME)
86+
if(logLevel.levelInt < Level.DEBUG_INT)
87+
rootLogger.level = logLevel
88+
rootLogger.addAppender(consoleAppender)
89+
rootLogger.addAppender(fileAppender)
90+
}
91+
92+
}

src/main/xerus/monstercat/Main.kt

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,60 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
44
import com.google.api.services.sheets.v4.SheetsScopes
55
import javafx.scene.Scene
66
import javafx.scene.image.Image
7-
import kotlinx.coroutines.experimental.asCoroutineDispatcher
8-
import kotlinx.coroutines.experimental.delay
9-
import kotlinx.coroutines.experimental.launch
10-
import xerus.ktutil.*
7+
import kotlinx.coroutines.experimental.*
8+
import mu.KotlinLogging
9+
import xerus.ktutil.SystemUtils
10+
import xerus.ktutil.getResource
1111
import xerus.ktutil.javafx.applySkin
1212
import xerus.ktutil.javafx.ui.App
1313
import xerus.ktutil.ui.SimpleFrame
1414
import java.io.File
1515
import java.net.URL
1616
import java.util.concurrent.ExecutorService
1717
import java.util.concurrent.Executors
18+
import java.util.concurrent.ThreadFactory
19+
import java.util.concurrent.atomic.AtomicInteger
1820
import javax.swing.JTextArea
1921

20-
typealias logger = XerusLogger
21-
2222
val VERSION = getResource("version")!!.readText()
2323
val isUnstable = VERSION.contains('-')
2424

25-
val logDir: File
26-
get() = cacheDir.resolve("logs").apply { mkdirs() }
25+
val cacheDir: File
26+
get() = (File("/var/tmp").takeIf { it.exists() } ?: File(System.getProperty("java.io.tmpdir")))
27+
.resolve("monsterutilities").apply { mkdirs() }
2728

2829
lateinit var monsterUtilities: MonsterUtilities
2930

30-
val globalThreadPool: ExecutorService = Executors.newCachedThreadPool()
31+
val globalThreadPool: ExecutorService = Executors.newCachedThreadPool(object : ThreadFactory {
32+
private val poolNumber = AtomicInteger(1)
33+
override fun newThread(r: Runnable) =
34+
Thread(Thread.currentThread().threadGroup, r, "global-" + poolNumber.getAndIncrement())
35+
})
3136
val globalDispatcher = globalThreadPool.asCoroutineDispatcher()
3237

33-
val location: URL = MonsterUtilities::class.java.protectionDomain.codeSource.location
34-
var checkUpdate = Settings.AUTOUPDATE() && location.toString().endsWith(".jar")
38+
val jarLocation: URL = MonsterUtilities::class.java.protectionDomain.codeSource.location
3539

3640
fun main(args: Array<String>) {
37-
XerusLogger.parseArgs(*args, defaultLevel = "finer")
38-
if (args.contains("--no-update"))
39-
checkUpdate = false
40-
Thread.setDefaultUncaughtExceptionHandler { thread, ex ->
41-
logger.warning("Uncaught exception in $thread: ${ex.getStackTraceString()}")
42-
}
43-
val logfile = logDir.resolve("log${currentSeconds()}.txt")
44-
try {
45-
XerusLogger.logToFile(logfile)
46-
logger.config("Logging to $logfile")
47-
launch {
48-
val logs = logDir.listFiles()
49-
if (logs.size > 10) {
50-
logs.asSequence().sortedByDescending { it.name }.drop(5).filter {
51-
val timestamp = it.nameWithoutExtension.substring(3).toIntOrNull() ?: return@filter true
52-
timestamp + 200_000 < currentSeconds()
53-
}.also {
54-
val count = it.count()
55-
if (count > 0)
56-
logger.finer("Deleting $count old logs")
57-
}.forEach { it.delete() }
58-
}
59-
}
60-
} catch (t: Throwable) {
61-
showErrorSafe(t, "Can't log to $logfile!")
62-
}
63-
if (!javaVersion().startsWith("1.8")) {
64-
SimpleFrame { add(JTextArea("Please install and use Java 8!\nThe current version is ${javaVersion()}").apply { isEditable = false }) }
41+
initLogging(args)
42+
val logger = KotlinLogging.logger {}
43+
44+
if (!SystemUtils.javaVersion.startsWith("1.8")) {
45+
SimpleFrame { add(JTextArea("Please install and use Java 8!\nThe current version is ${SystemUtils.javaVersion}").apply { isEditable = false }) }
6546
return
6647
}
67-
logger.info("Version: $VERSION, Java version: ${javaVersion()}")
68-
logger.config("Initializing Google Sheets API Service")
48+
logger.info("Version: $VERSION, Java version: ${SystemUtils.javaVersion}")
49+
50+
logger.info("Initializing Google Sheets API Service")
6951
Sheets.initService("MonsterUtilities", GoogleCredential().createScoped(listOf(SheetsScopes.SPREADSHEETS_READONLY)))
52+
53+
val checkUpdate = !args.contains("--no-update") && Settings.AUTOUPDATE() && jarLocation.toString().endsWith(".jar")
7054
App.launch("MonsterUtilities $VERSION", { stage ->
7155
stage.icons.addAll(arrayOf("img/icon64.png").map {
7256
getResource(it)?.let { Image(it.toExternalForm()) }
73-
?: null.apply { logger.warning("Resource $it not found") }
57+
?: null.apply { logger.warn("Resource $it not found!") }
7458
})
7559
}, {
76-
val scene = Scene(MonsterUtilities(), 800.0, 700.0)
60+
val scene = Scene(MonsterUtilities(checkUpdate), 800.0, 700.0)
7761
scene.applySkin(Settings.SKIN())
7862
scene
7963
})
@@ -82,7 +66,7 @@ fun main(args: Array<String>) {
8266
}
8367

8468
fun showErrorSafe(error: Throwable, title: String = "Error") {
85-
launch {
69+
GlobalScope.launch {
8670
var i = 0
8771
while (i < 100 && !::monsterUtilities.isInitialized) {
8872
delay(200)

0 commit comments

Comments
 (0)