PageRenderTime 60ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/mehmedbasic/scalaudiobookconverter
Scala | 49 lines | 31 code | 12 blank | 6 comment | 1 complexity | 1b85eadad2f4628b2bc80a95bb399262 MD5 | raw file
  1. package dk.mehmedbasic.audiobook.execution
  2. import java.io.File
  3. import dk.mehmedbasic.audiobook.conversion.AudioConfig
  4. /**
  5. * Command factory creates commands based on OS.
  6. *
  7. * @author Jesenko Mehmedbasic
  8. * created 20-01-13, 00:16
  9. */
  10. class ConversionCommandFactory(
  11. inputFile: File,
  12. outputConfig: AudioConfig) extends CommandFactory {
  13. def createTempFile(): String = {
  14. var file = File.createTempFile("scab_temp_", ".mp4")
  15. while (!file.exists()) {
  16. file = File.createTempFile("scab_temp_", ".mp4")
  17. }
  18. val result = file.getAbsolutePath
  19. file.delete()
  20. result
  21. }
  22. def getOutput: String = createTempFile()
  23. protected override def addParametersToCommand(command: Command): Unit = {
  24. command.addParameter("f", "u8")
  25. command.addParameter("i", "pipe:0")
  26. command.addParameter("ar", outputConfig.sampleFrequency)
  27. command.addParameter("ac", outputConfig.channels)
  28. command.addParameter("f", "mp4")
  29. command.addParameter(null, getOutput )
  30. }
  31. protected override def createWindowsCommand(): Command = {
  32. new Command("\"" + new File(".").getAbsolutePath + "\\external\\faac.exe\"")
  33. }
  34. protected override def createUnixCommand(): Command = {
  35. new Command("ffmpeg")
  36. }
  37. }