Skip to content

Commit

Permalink
Add -convertedonly argument
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
obruchez committed Jan 6, 2024
1 parent 2a0582e commit c94fffd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Options:
-vbr quality VBR quality (1-5 for AAC and 0-9 for MP3)
-volume mode volume mode (track for track ReplayGain application, album for album ReplayGain application)
-threads count number of parallel threads to use
-convertedonly only copy converted files (i.e. do not copy other files)
-copycovers copy cover art to sub-directories (useful for e.g. Logitech Media Server)
-force force convert/copy even if destination file exists and is up-to-date
-noop do not convert, copy, or remove any file in the destination directory
Expand Down
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name := "flac-to-mp3"
version := "1.2"
scalaVersion := "2.13.8"
version := "1.3"
scalaVersion := "2.13.12"

libraryDependencies += "commons-io" % "commons-io" % "2.6"
libraryDependencies += "commons-io" % "commons-io" % "2.11.0"

mainClass in assembly := Some("org.bruchez.olivier.flactomp3.FlacToMp3")
assembly / mainClass := Some("org.bruchez.olivier.flactomp3.FlacToMp3")

assemblyJarName in assembly := "flac-to-mp3.jar"
assembly / assemblyJarName := "flac-to-mp3.jar"

scalafmtOnCompile in ThisBuild := true
ThisBuild / scalafmtOnCompile := true
8 changes: 7 additions & 1 deletion src/main/scala/org/bruchez/olivier/flactomp3/Arguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ case class Arguments(
outputBitrateOption: Option[Bitrate] = None,
volume: Volume = NoVolumeChange,
threadCount: Int = Math.max(1, Runtime.getRuntime.availableProcessors()),
convertedOnly: Boolean = false,
copyCoversToSubDirectories: Boolean = false,
force: Boolean = false,
noop: Boolean = false
Expand All @@ -23,7 +24,8 @@ case class Arguments(
}

object Arguments {
val DefaultInputExtensionsToConvert = Set("flac", "flv", "m4a", "mp2", "mp3", "mpc", "ogg", "wav")
private val DefaultInputExtensionsToConvert =
Set("flac", "flv", "m4a", "mp2", "mp3", "mpc", "ogg", "wav")

def apply(args: Array[String]): Try[Arguments] = {
if (args.length >= 2) {
Expand Down Expand Up @@ -104,6 +106,8 @@ object Arguments {
new IllegalArgumentException(s"Unexpected thread count: ${remainingArgs.head}")
)
}
case ConvertedOnlyArgument =>
Success((arguments.copy(convertedOnly = true), remainingArgs))
case CopyCoversToSubDirectoriesArgument =>
Success((arguments.copy(copyCoversToSubDirectories = true), remainingArgs))
case ForceArgument =>
Expand Down Expand Up @@ -134,6 +138,7 @@ object Arguments {
|-vbr quality VBR quality (1-5 for AAC and 0-9 for MP3)
|-volume mode volume mode (track for track ReplayGain application, album for album ReplayGain application)
|-threads count number of parallel threads to use
|-convertedonly only copy converted files (i.e. do not copy other files)
|-copycovers copy cover art to sub-directories (useful for e.g. Logitech Media Server)
|-force force convert/copy even if destination file exists and is up-to-date
|-noop do not convert, copy, or remove any file in the destination directory""".stripMargin
Expand All @@ -145,6 +150,7 @@ object Arguments {
private val VariableBitrateArgument = "-vbr"
private val VolumeArgument = "-volume"
private val ThreadCountArgument = "-threads"
private val ConvertedOnlyArgument = "-convertedonly"
private val CopyCoversToSubDirectoriesArgument = "-copycovers"
private val ForceArgument = "-force"
private val NoopArgument = "-noop"
Expand Down
12 changes: 9 additions & 3 deletions src/main/scala/org/bruchez/olivier/flactomp3/FlacToMp3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ object FlacToMp3 {
)
}
}
// scalastyle:on method.length

private def actionGroups(srcPaths: Seq[Path], dstPaths: Seq[Path])(implicit
arguments: Arguments
Expand Down Expand Up @@ -109,9 +108,16 @@ object FlacToMp3 {
ConvertFileAction(srcPath, dstPath)
}

val copyFileActions = filesToCopy.map { case (srcPath, dstPath) =>
CopyFileAction(srcPath, dstPath)
val copyFileActions = {
if (!arguments.convertedOnly) {
filesToCopy.map { case (srcPath, dstPath) =>
CopyFileAction(srcPath, dstPath)
}
} else {
Seq()
}
}
// scalastyle:on method.length

Seq(
ActionGroup("Symbolic link removal", removeSymbolicLinkActions, parallelExecution = true),
Expand Down

0 comments on commit c94fffd

Please sign in to comment.