Skip to content

Commit

Permalink
v1.0.2:
Browse files Browse the repository at this point in the history
- Fixed a bug
  • Loading branch information
randombyte-developer committed Jul 23, 2018
1 parent d5e1fdb commit ce6765e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group "de.randombyte"
version "1.0.1"
version "1.0.2"

repositories {
jcenter()
Expand Down
15 changes: 6 additions & 9 deletions src/main/kotlin/de/randombyte/discordrpcmusic/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ private fun <T> String.execute(lines: (Sequence<String>) -> T): T =
Runtime.getRuntime().exec(this).inputStream.bufferedReader().useLines(lines)

private class TrackInfo(val title: String, val artist: String) {
companion object {
fun fromPair(pair: Pair<String, String>) = TrackInfo(title = pair.first, artist = pair.second)
}

fun buildRichPresenceObject() = DiscordRichPresence {
details = title
state = artist
Expand All @@ -25,7 +21,7 @@ private class TrackInfo(val title: String, val artist: String) {
* @return TrackInfo of the currently playing (or paused) track or null if no track or multiple ones could be found
*/
private fun getCurrentTrackInfo(): TrackInfo? {
val trackInfoPair = "xprop -root".execute { lines ->
val trackInfo = "xprop -root".execute { lines ->
lines
.filter { XPROP_WINDOW_IDS_PROPERTY_PREFIX in it }
.map { it.removePrefix(XPROP_WINDOW_IDS_PROPERTY_PREFIX) }
Expand All @@ -39,16 +35,17 @@ private fun getCurrentTrackInfo(): TrackInfo? {
.map { it.removeSurrounding("\"") }
.filter { GOOGLE_PLAY_MUSIC_CHROME_WINDOW_NAME_SUFFIX in it }
.map { it.removeSuffix(GOOGLE_PLAY_MUSIC_CHROME_WINDOW_NAME_SUFFIX) }
.map {
val (title, artist) = it.split(" - ", limit = 2)
Pair(title, artist)
.mapNotNull innerMapNotNull@ {
val splits = it.split(" - ", limit = 2)
if (splits.size != 2) return@innerMapNotNull null
TrackInfo(title = splits[0], artist = splits[1])
}.singleOrNull()
}
}
.singleOrNull()
}

return trackInfoPair?.let { TrackInfo.fromPair(it) }
return trackInfo
}

fun main(args: Array<String>) {
Expand Down

0 comments on commit ce6765e

Please sign in to comment.