diff --git a/cutvideo b/cutvideo index 0c1de8d..3592a13 100755 --- a/cutvideo +++ b/cutvideo @@ -16,6 +16,7 @@ use Symfony\Component\Console\SingleCommandApplication; ->addArgument('end', InputArgument::REQUIRED, 'The end point of the video') ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force generation, even if target already exists.') ->addOption('remove', 'r', InputOption::VALUE_NONE, 'Remove input file on success.') + ->addOption('tmp', 't', InputOption::VALUE_OPTIONAL, 'Temporary folder for temporary files. Defaults to system temp.') ->addOption('ad', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Start and end of ads, separate start and end via "/".', []) ->setCode(new Command()) ->run(); diff --git a/src/Command.php b/src/Command.php index 7998498..d8e09d6 100644 --- a/src/Command.php +++ b/src/Command.php @@ -52,7 +52,7 @@ class Command return 1; } - $cutting = new Cutting($videoInfo); + $cutting = new Cutting($videoInfo, $input->getOption('tmp')); $this->executeStep('Generating temp cutted video files.'); foreach ($cutting->getCommandsForCutting() as $command) { diff --git a/src/Cutting.php b/src/Cutting.php index fba687b..dacdb4f 100644 --- a/src/Cutting.php +++ b/src/Cutting.php @@ -30,14 +30,22 @@ class Cutting */ private $video; + /** + * @var string + */ + private $tempFolder = ''; + /** * @var array */ private $tempFilenames = []; - public function __construct(VideoInfo $video) - { + public function __construct( + VideoInfo $video, + ?string $tempFolder = null + ) { $this->video = $video; + $this->tempFolder = $tempFolder ?? sys_get_temp_dir(); } public function getCommandsForCutting(): \Generator @@ -136,7 +144,7 @@ class Cutting private function getNextTempFilename(): string { $count = count($this->tempFilenames) + 1; - $nextName = sys_get_temp_dir() + $nextName = $this->tempFolder . DIRECTORY_SEPARATOR . $this->video->getOriginalFilenameWithSuffix('cut-' . $count); @@ -148,13 +156,13 @@ class Cutting { $file = new \SplFileInfo($this->video->getOriginalFilenameWithSuffix('metadata')); - return sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt'; + return $this->tempFolder . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt'; } private function getConcatFilename(): string { $file = new \SplFileInfo($this->video->getOriginalFilenameWithSuffix('concat')); - return sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt'; + return $this->tempFolder . DIRECTORY_SEPARATOR . $file->getBasename('.' . $file->getExtension()) . '.txt'; } }