/src/main/scala-2.12/dk/mehmedbasic/audiobook/execution/ConcatCommandFactory.scala

https://bitbucket.org/mehmedbasic/scalaudiobookconverter · Scala · 44 lines · 28 code · 10 blank · 6 comment · 0 complexity · f338fccc3fd844bfb9586263cb197752 MD5 · raw file

  1. package dk.mehmedbasic.audiobook.execution
  2. import java.io.{File, FileOutputStream, PrintStream}
  3. /**
  4. * A command factory for the concat command.
  5. *
  6. * @author Jesenko Mehmedbasic
  7. * created 25-01-13, 01:27
  8. */
  9. class ConcatCommandFactory(convertedFiles: List[File], output: File) extends CommandFactory {
  10. val fileList: File = createFileList()
  11. protected def createWindowsCommand(): Command = {
  12. new Command("\"" + new File(".").getAbsolutePath + "\\external\\ffmpeg.exe\"")
  13. }
  14. protected def createUnixCommand(): Command = new Command("ffmpeg")
  15. protected def addParametersToCommand(command: Command) :Unit={
  16. command.addParameter("f", "concat")
  17. command.addParameter("i", "\"" + fileList.getAbsolutePath + "\"")
  18. command.addParameter("c", "copy")
  19. command.addParameter(null, "\"" + temporaryOutput + "\"")
  20. }
  21. def createFileList(): File = {
  22. val inputFiles = File.createTempFile(System.nanoTime() + "_files", ".input")
  23. val stream: PrintStream = new PrintStream(new FileOutputStream(inputFiles))
  24. convertedFiles foreach (file => {
  25. stream.print("file '")
  26. stream.print(file.getAbsolutePath)
  27. stream.println("'")
  28. })
  29. stream.close()
  30. inputFiles
  31. }
  32. def getFileList: File = fileList
  33. def temporaryOutput: String = output.getAbsolutePath + ".m4a"
  34. }