Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MMauro94/mkvtoolnix-wrapper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: MMauro94/mkvtoolnix-wrapper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 14 commits
  • 27 files changed
  • 1 contributor

Commits on Jan 21, 2020

  1. tests fix

    MMauro94 committed Jan 21, 2020
    Copy the full SHA
    e6644ae View commit details

Commits on Jan 22, 2020

  1. Copy the full SHA
    4a691d5 View commit details

Commits on Jan 23, 2020

  1. Fixes

    MMauro94 committed Jan 23, 2020
    Copy the full SHA
    7c14588 View commit details

Commits on Mar 1, 2020

  1. Copy the full SHA
    1fc6b72 View commit details

Commits on Mar 8, 2020

  1. Copy the full SHA
    c375fd6 View commit details

Commits on Oct 28, 2021

  1. Updated grandle and koltin

    MMauro94 committed Oct 28, 2021
    Copy the full SHA
    501ac29 View commit details
  2. Upgrade klaxon library

    MMauro94 committed Oct 28, 2021
    Copy the full SHA
    bfe60c8 View commit details
  3. Copy the full SHA
    94739a3 View commit details
  4. Copy the full SHA
    4cf27f2 View commit details
  5. Fix publishing

    MMauro94 committed Oct 28, 2021
    Copy the full SHA
    dca5b25 View commit details
  6. Increment version

    MMauro94 committed Oct 28, 2021
    Copy the full SHA
    722d2dd View commit details
  7. Copy the full SHA
    344217c View commit details
  8. Copy the full SHA
    2d2c5f6 View commit details
  9. Version bump

    MMauro94 committed Oct 28, 2021
    Copy the full SHA
    2f87c63 View commit details
Showing with 439 additions and 120 deletions.
  1. +70 −56 build.gradle
  2. BIN gradle/wrapper/gradle-wrapper.jar
  3. +3 −3 gradle/wrapper/gradle-wrapper.properties
  4. +1 −1 gradlew
  5. +1 −1 gradlew.bat
  6. +7 −0 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/Exceptions.kt
  7. +5 −1 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/MkvToolnix.kt
  8. +2 −1 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/MkvToolnixBinary.kt
  9. +9 −7 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/MkvToolnixCommand.kt
  10. +5 −6 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/MkvToolnixCommandResult.kt
  11. +10 −8 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/MkvToolnixFileIdentification.kt
  12. +25 −15 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/MkvToolnixLanguage.kt
  13. +25 −0 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/extract/MkvExtractAttachmentExtractionMode.kt
  14. +82 −0 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/extract/MkvExtractCommand.kt
  15. +5 −0 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/extract/MkvExtractExtractionMode.kt
  16. +61 −0 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/extract/MkvExtractTrackExtractionMode.kt
  17. +12 −1 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/json/BigIntegerConverter.kt
  18. +1 −1 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/json/MkvToolnixLanguageConverter.kt
  19. +2 −2 src/main/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/merge/MkvMergeCommand.kt
  20. +1 −1 ...in/kotlin/com/github/mmauro94/mkvtoolnix_wrapper/propedit/MkvPropEditCommandPropertyEditAction.kt
  21. +36 −1 src/test/kotlin/BaseTests.kt
  22. +43 −0 src/test/kotlin/ExtractTests.kt
  23. +15 −9 src/test/kotlin/MergeTest.kt
  24. +9 −6 src/test/kotlin/TestUtils.kt
  25. 0 src/test/resources/empty_file
  26. +1 −0 src/test/resources/invalid_file
  27. +8 −0 src/test/resources/test.srt
126 changes: 70 additions & 56 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
}
}

plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
id 'com.bmuschko.nexus' version "2.3.1"
id 'io.codearte.nexus-staging' version '0.11.0'
id 'maven-publish'
id 'signing'
id 'org.jetbrains.kotlin.jvm' version "1.5.31"
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}


group 'com.github.mmauro94'
version '1.0.0'

sourceCompatibility = 1.8

version '2.0.1'

repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'

compile 'com.beust:klaxon:5.0.5'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31"
implementation 'com.beust:klaxon:5.5'

testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation "org.jetbrains.kotlin:kotlin-reflect"
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation "org.jetbrains.kotlin:kotlin-test:1.5.31"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.5.31"
}

compileKotlin {
@@ -42,46 +29,73 @@ compileKotlin {
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

modifyPom {
//noinspection GroovyAssignabilityCheck
project {
name = "mkvtoolnix-wrapper"
description = "An easy to use light kotlin-jvm wrapper for most common mkvmerge and mkvpropedit CLI commands"
url = "https://github.com/MMauro94/mkvtoolnix-wrapper"
inceptionYear = 2019
//Requirements in gradle.properties to publish:
// - sonatypeUsername and sonatypePassword variables, with the USER TOKEN (profile page on oss.sonatype.org)
// - generate a private key with `gpg --gen-key`
// - `gpg2 --list-keys` to list keys
// - publish the key with `gpg2 --keyserver hkp://pool.sks-keyservers.net --send-keys XXXXX` where XXXXX is the id of the key
// - signing.keyId, signing.password and signing.secretKeyRingFile variables (use short key id)
// - singing.secretKeyRingFile should be a gpg file, if not present export one with `gpg --export-secret-keys > secring.gpg`

scm {
url = 'scm:git:git://github.com/MMauro94/mkvtoolnix-wrapper.git'
connection = 'scm:git:ssh://github.com:MMauro94/mkvtoolnix-wrapper.git'
developerConnection = 'http://github.com/MMauro94/mkvtoolnix-wrapper/tree/master'
}
// PUBLISH WITH COMMAND gradle publishToSonatype closeAndReleaseSonatypeStagingRepository

licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
distribution = 'repo'
}
}
nexusPublishing {
repositories {
sonatype()
}
}

developers {
developer {
id = 'MMauro94'
name = 'Mauro Molin'
email = 'molin.mauro@gmail.com'
publishing {
publications {
maven(MavenPublication) {
from components.java
pom {
name = "mkvtoolnix-wrapper"
description = "An easy to use light kotlin-jvm wrapper for most common mkvmerge and mkvpropedit CLI commands"
url = "https://github.com/MMauro94/mkvtoolnix-wrapper"

licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
distribution = 'repo'
}
}
developers {
developer {
id = 'MMauro94'
name = 'Mauro Molin'
email = 'molin.mauro@gmail.com'
}
}
scm {
url = 'scm:git:git://github.com/MMauro94/mkvtoolnix-wrapper.git'
connection = 'scm:git:ssh://github.com:MMauro94/mkvtoolnix-wrapper.git'
developerConnection = 'http://github.com/MMauro94/mkvtoolnix-wrapper/tree/master'
}
}
}

}
}
extraArchive {
sources = true
tests = true
javadoc = true

java {
withJavadocJar()
withSourcesJar()
}
nexus {
sign = true
repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'

javadoc {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

signing {
required { !project.version.endsWith("-SNAPSHOT") && !project.hasProperty("skipSigning") }

sign publishing.publications.maven
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Mar 03 15:49:41 CET 2019
#Wed Jan 22 00:14:14 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
zipStoreBase=GRADLE_USER_HOME
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.mmauro94.mkvtoolnix_wrapper

import com.github.mmauro94.mkvtoolnix_wrapper.extract.MkvExtractCommand
import com.github.mmauro94.mkvtoolnix_wrapper.merge.MkvMergeCommand
import com.github.mmauro94.mkvtoolnix_wrapper.propedit.MkvPropEditCommand

@@ -19,6 +20,12 @@ sealed class MkvToolnixCommandException(open val result: MkvToolnixCommandResult
cause: Throwable? = null
) : MkvToolnixCommandException(result, message, cause)

class MkvExtractException internal constructor(
override val result: MkvToolnixCommandResult<MkvExtractCommand>,
message: String? = null,
cause: Throwable? = null
) : MkvToolnixCommandException(result, message, cause)

}

internal typealias ExceptionInitializer<COMMAND> = (MkvToolnixCommandResult<COMMAND>, String?, Throwable?) -> MkvToolnixCommandException
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.mmauro94.mkvtoolnix_wrapper

import com.github.mmauro94.mkvtoolnix_wrapper.extract.MkvExtractCommand
import com.github.mmauro94.mkvtoolnix_wrapper.merge.MkvMergeCommand
import com.github.mmauro94.mkvtoolnix_wrapper.propedit.MkvPropEditCommand
import java.io.File
@@ -20,7 +21,10 @@ object MkvToolnix {

fun merge(outputFile : File) = MkvMergeCommand(outputFile)

fun propedit(outputFile : File) = MkvPropEditCommand(outputFile)
fun propedit(sourceFile : File) = MkvPropEditCommand(sourceFile)

fun extract(sourceFile : File) = MkvExtractCommand(sourceFile)

}

internal fun String.mkvtoolnixEscape() : String {
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ import java.util.regex.Pattern
*/
enum class MkvToolnixBinary(val binaryName: String) {
MKV_PROP_EDIT("mkvpropedit"),
MKV_MERGE("mkvmerge");
MKV_MERGE("mkvmerge"),
MKV_EXTRACT("mkvextract");

/**
* The file pointing to this binary, or `null` if the the binary should be searched using the environment PATH
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ abstract class MkvToolnixCommand<SELF : MkvToolnixCommand<SELF>>(val binary: Mkv
}

/**
* Starts the execution of the command, returning the result object immediately, lazingly parsing the output.
* Starts the execution of the command, returning the result object immediately, lazily parsing the output.
* The output can be iterated while the program is running. Calling [MkvToolnixCommandResult.exitCode] will obviously halt until the command terminates.
*
* WARNING! If you call this method, you will be responsible for closing the input stream. You can do so by calling [MkvToolnixCommandResult.Lazy.close] on the returned object. It is therefore suggested to [use] the returned object immediately
@@ -35,12 +35,14 @@ abstract class MkvToolnixCommand<SELF : MkvToolnixCommand<SELF>>(val binary: Mkv

val reader = BufferedReader(InputStreamReader(p.inputStream))
val output = reader.lineSequence().map { line ->
val (msg, type) = if (line.startsWith(WARNING_PREFIX)) {
line.substring(WARNING_PREFIX.length).trimStart() to MkvToolnixCommandResult.Line.Type.WARNING
} else if (line.startsWith(ERROR_PREFIX)) {
line.substring(ERROR_PREFIX.length).trimStart() to MkvToolnixCommandResult.Line.Type.ERROR
} else {
line to MkvToolnixCommandResult.Line.Type.INFO
val (msg, type) = when {
line.startsWith(WARNING_PREFIX, ignoreCase = true) -> {
line.substring(WARNING_PREFIX.length).trimStart() to MkvToolnixCommandResult.Line.Type.WARNING
}
line.startsWith(ERROR_PREFIX, ignoreCase = true) -> {
line.substring(ERROR_PREFIX.length).trimStart() to MkvToolnixCommandResult.Line.Type.ERROR
}
else -> line to MkvToolnixCommandResult.Line.Type.INFO
}
if (type != MkvToolnixCommandResult.Line.Type.INFO || msg.isNotBlank()) {
MkvToolnixCommandResult.Line(msg, type)
Original file line number Diff line number Diff line change
@@ -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.
@@ -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
}
@@ -47,7 +46,7 @@ sealed class MkvToolnixCommandResult<COMMAND : MkvToolnixCommand<*>>(val command
}

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

@@ -92,7 +91,7 @@ sealed class MkvToolnixCommandResult<COMMAND : MkvToolnixCommand<*>>(val command
*/
fun toString(printCommand: Boolean = false, printOutput: Boolean = true, printExitCode: Boolean = true) = StringBuilder().apply {
outputLines(printCommand, printOutput, printExitCode).forEach {
appendln(it)
appendLine(it)
}
}.toString()

Original file line number Diff line number Diff line change
@@ -7,24 +7,24 @@ import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader

data class MkvToolnixFileIdentification(
data class MkvToolnixFileIdentification internal constructor(
@Json("attachments")
val attachments: List<MkvToolnixAttachment>,
val attachments: List<MkvToolnixAttachment> = emptyList(),

@Json("chapters")
val chapters: List<MkvToolnixChapter>,
val chapters: List<MkvToolnixChapter> = emptyList(),

@Json("container")
val container: MkvToolnixContainer,
val container: MkvToolnixContainer = MkvToolnixContainer(recognized = false, supported = false),

@Json("errors")
val errors: List<String>,

@Json("file_name")
val fileName: File,
var fileName: File,

@Json("tracks")
val tracks: List<MkvToolnixTrack>,
val tracks: List<MkvToolnixTrack> = emptyList(),

@Json("warnings")
val warnings: List<String>
@@ -35,7 +35,7 @@ data class MkvToolnixFileIdentification(
*/
fun propedit() = MkvToolnix.propedit(fileName)

internal fun applyInfoToTracks() = apply{
internal fun applyInfoToTracks() = apply {
tracks.forEachIndexed { index, t ->
t._fileIdentification = this
t._trackPosition = index + 1
@@ -51,7 +51,9 @@ data class MkvToolnixFileIdentification(
fun identify(file: File): MkvToolnixFileIdentification {
val p = MkvToolnixBinary.MKV_MERGE.processBuilder("-J", file.absolutePath).start()
return BufferedReader(InputStreamReader(p.inputStream)).use { input ->
klaxon().parse<MkvToolnixFileIdentification>(input)!!.applyInfoToTracks()
val jsonObject = klaxon().parseJsonObject(input)
jsonObject.putIfAbsent("file_name", file.absolutePath)
klaxon().maybeParse<MkvToolnixFileIdentification>(jsonObject)!!.applyInfoToTracks()
}
}
}
Loading