Skip to content

Commit

Permalink
Fix progress when mkvmerge ui-language is not English
Browse files Browse the repository at this point in the history
  • Loading branch information
MMauro94 committed Oct 28, 2021
1 parent 722d2dd commit 344217c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.github.mmauro94.mkvtoolnix_wrapper.MkvToolnixCommandResult.*
import com.github.mmauro94.mkvtoolnix_wrapper.MkvToolnixCommandResult.Line.Type
import com.github.mmauro94.mkvtoolnix_wrapper.utils.CachedSequence
import java.io.BufferedReader
import java.util.regex.Pattern

/**
* Abstract class that represents a result given by a MKV Toolnix binary.
Expand Down Expand Up @@ -33,9 +32,9 @@ sealed class MkvToolnixCommandResult<COMMAND : MkvToolnixCommand<*>>(val command

val progress by lazy {
if (type == Type.INFO) {
val m = PROGRESS_PATTERN.matcher(message)
if (m.matches()) {
m.group(1).toInt() / 100f
val m = PROGRESS_REGEX.matchEntire(message)
if (m != null) {
m.groupValues[1].toInt() / 100f
} else null
} else null
}
Expand All @@ -47,7 +46,7 @@ sealed class MkvToolnixCommandResult<COMMAND : MkvToolnixCommand<*>>(val command
}

companion object {
private val PROGRESS_PATTERN = Pattern.compile("^Progress:\\s+(\\d+)%$")
private val PROGRESS_REGEX = ".+?(100|\\d{1,2})%$".toRegex()
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/test/kotlin/MergeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.junit.Test
import java.io.File
import java.time.Duration
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class MergeTest {

Expand All @@ -18,9 +19,11 @@ class MergeTest {
val fileTitle = "COOL LOOKING TITLE"

OUTPUT_FILE.deleteAfter { of ->
MkvToolnix.merge(of).apply {
val result = MkvToolnix.merge(of).apply {
globalOptions {
title = fileTitle
additionalArgs.add("--ui-language")
additionalArgs.add("fr")
}
addInputFile(TEST_FILE) {
subtitleTracks.excludeAll()
Expand Down Expand Up @@ -49,6 +52,8 @@ class MergeTest {
}
}.executeAndAssert()

assertTrue(result.outputList.any { it.isProgressLine }, "No progress lines detected")

val actual = MkvToolnix.identify(of)
assertEquals(
EXPECTED_IDENTIFICATION.copy(
Expand Down
6 changes: 2 additions & 4 deletions src/test/kotlin/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ internal val EXPECTED_IDENTIFICATION by lazy {
/**
* Executes the command printing everything on standard output, and asserting that the command succeeds
*/
internal fun MkvToolnixCommand<*>.executeAndAssert() {
executeAndPrint(true).apply {
assertTrue(success, "Command exited with code: $exitCode")
}
internal fun MkvToolnixCommand<*>.executeAndAssert() = executeAndPrint(true).apply {
assertTrue(success, "Command exited with code: $exitCode")
}

/**
Expand Down

0 comments on commit 344217c

Please sign in to comment.