Skip to content

Commit

Permalink
Add -nodelete argument
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
obruchez committed Jan 14, 2024
1 parent c94fffd commit 6ac5a8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/scala/org/bruchez/olivier/flactomp3/Arguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ case class Arguments(
srcPath: Path,
dstPath: Path,
trashPath: Path,
noDelete: Boolean = false,
inputExtensionsToConvert: Set[String] = Arguments.DefaultInputExtensionsToConvert,
outputFormat: Format = Aac,
outputBitrateOption: Option[Bitrate] = None,
Expand Down Expand Up @@ -60,6 +61,8 @@ object Arguments {
(arg match {
case TrashPathArgument if remainingArgs.nonEmpty =>
Success((arguments.copy(trashPath = Paths.get(remainingArgs.head)), remainingArgs.tail))
case NoDeleteArgument =>
Success((arguments.copy(noDelete = true), remainingArgs))
case InputExtensionsToConvertArgument if remainingArgs.nonEmpty =>
val extensions = remainingArgs.head.split(",").map(_.trim.toLowerCase).toSet
Success((arguments.copy(inputExtensionsToConvert = extensions), remainingArgs.tail))
Expand Down Expand Up @@ -131,6 +134,7 @@ object Arguments {
|Options:
|
|-trash trash_directory directory where removed destination files will be put (default is destination_directory/.FlacToMp3Trash)
|-nodelete do not delete any file in the destination directory
|-extensions extensions comma-separated list of extensions to convert using ffmpeg (default is ${DefaultInputExtensionsToConvert.toSeq.sorted
.mkString(",")})
|-format format output format (aac or mp3)
Expand All @@ -144,6 +148,7 @@ object Arguments {
|-noop do not convert, copy, or remove any file in the destination directory""".stripMargin

private val TrashPathArgument = "-trash"
private val NoDeleteArgument = "-nodelete"
private val InputExtensionsToConvertArgument = "-extensions"
private val OutputFormatArgument = "-format"
private val ConstantBitrateArgument = "-cbr"
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/org/bruchez/olivier/flactomp3/FlacToMp3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ object FlacToMp3 {
dstPaths.filter(Files.isSymbolicLink).map(RemoveSymbolicLinkAction)

val removeFileActions =
dstPaths.filterNot(expectedDestinationPaths.contains).map(RemoveFileAction)
if (!arguments.noDelete) {
dstPaths.filterNot(expectedDestinationPaths.contains).map(RemoveFileAction)
} else {
Seq()
}

val convertFileActions = filesToConvert.map { case (srcPath, dstPath) =>
ConvertFileAction(srcPath, dstPath)
Expand Down

0 comments on commit 6ac5a8c

Please sign in to comment.