Skip to content

Commit

Permalink
improve print, bump to 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Colerar committed Mar 22, 2022
1 parent d6d5260 commit d77d818
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import java.time.ZonedDateTime
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("com.github.gmazzo.buildconfig") version "3.0.3"
id("com.github.gmazzo.buildconfig")
id("org.jlleitschuh.gradle.ktlint")
id("org.jlleitschuh.gradle.ktlint-idea")
id("com.github.johnrengelman.shadow")
application
}

group = "moe.sdl.tracks"
version = "1.2.1"
version = "1.2.2"

val commitHash by lazy {
val commitHashCommand = "git rev-parse --short HEAD"
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/moe/sdl/tracks/cmd/Dig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ class Dig : CliktCommand(

// Mux video and audio
when {
skipMux -> echo("@|cyan,bold 根据选项跳过混流...|@".color)
skipMux || only != null -> echo("@|cyan,bold 根据选项跳过混流...|@".color)
videoDst?.exists() == true || audioDst?.exists() == true -> {
echo("@|magenta ==>|@ @|bold 开始混流...|@".color)
val context = placeholderContext + videoStreamContext + audioStreamContext
Expand Down Expand Up @@ -888,7 +888,9 @@ class Dig : CliktCommand(
printJob.cancel()
}.onSuccess {
echo()
echo("下载完成! 文件路径: ${dst.toPath().normalize().toFile().absolutePath}")
if (!onlyArtifact || only != null) {
echo("下载完成! 文件路径: ${dst.toPath().normalize().toFile().absolutePath}")
}
}.onFailure {
if (it is CancellationException) throw it else echo(it)
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/moe/sdl/tracks/util/string/ProgressBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ fun CoroutineScope.progressBar(
str += " "
}
str += String.format("%.1f%%", min(rate * 100, 100.0)).padEnd(7, ' ')
val delta = (Clock.System.now() - start).inWholeMilliseconds
val deltaDuration = Clock.System.now() - start
val delta = deltaDuration.inWholeMilliseconds
val avg = if (delta > 0) Size(cur.value).toBandwidthMs(delta).toBytesBandwidth() else BytesBandwidth(0)
str += "avg: " + avg.toShow().padEnd(10, ' ')
val etaSeconds = if (avg.bytes > 0) (total - cur.value) / avg.bytes else 0
str += " eta: " + etaSeconds.toInt().secondsToDuration().padEnd(5, ' ')
val etaSeconds: Double = if (avg.bytes > 0L) (total.toDouble() - cur.value) / avg.bytes else 0.0
str += if (etaSeconds <= 0.1 && avg.bytes > 1) {
" costed: ${deltaDuration.toHms()}"
} else {
" eta: " + etaSeconds.toInt().secondsToDuration().padEnd(5, ' ')
}

print(StringBuilder("\u0008").repeat(lastLen))
print(str)
lastLen = str.length
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/moe/sdl/tracks/util/string/ToString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.isDistantFuture
import kotlinx.datetime.toLocalDateTime
import kotlin.math.pow
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration

Expand Down Expand Up @@ -96,6 +97,13 @@ fun LocalDateTime.toAbsTime() =
year.toString() + "-" + monthNumber.padZero() + "-" + dayOfMonth.padZero() + " " +
hour.padZero() + ":" + minute.padZero() + ":" + second.padZero()

fun Duration.toHms(): String = toComponents { hours, minutes, seconds, _ ->
val h = hours.toString().padStart(2, '0')
val m = minutes.toString().padStart(2, '0')
val s = seconds.toString().padStart(2, '0')
"$h:$m:$s"
}

private const val BANDWIDTH_SCALE: Double = 1000.0

/**
Expand Down
2 changes: 2 additions & 0 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#### suppress inspection "SpellCheckingInspection" for whole file
#### suppress inspection "UnusedProperty" for whole file

plugin.com.github.gmazzo.buildconfig=3.0.3

plugin.com.github.johnrengelman.shadow=7.1.2

plugin.org.jlleitschuh.gradle.ktlint-idea=10.2.1
Expand Down

0 comments on commit d77d818

Please sign in to comment.