Allow to define temp folder

Some systems might have limited temp folder sizes.
A new option is added to configure the folder to use for temp files.
This commit is contained in:
Daniel Siepmann 2023-02-12 11:31:31 +01:00
parent 4fa3cef8c3
commit 8124631d5d
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 15 additions and 6 deletions

View file

@ -16,6 +16,7 @@ use Symfony\Component\Console\SingleCommandApplication;
->addArgument('end', InputArgument::REQUIRED, 'The end point of the video') ->addArgument('end', InputArgument::REQUIRED, 'The end point of the video')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force generation, even if target already exists.') ->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('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 "/".', []) ->addOption('ad', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Start and end of ads, separate start and end via "/".', [])
->setCode(new Command()) ->setCode(new Command())
->run(); ->run();

View file

@ -52,7 +52,7 @@ class Command
return 1; return 1;
} }
$cutting = new Cutting($videoInfo); $cutting = new Cutting($videoInfo, $input->getOption('tmp'));
$this->executeStep('Generating temp cutted video files.'); $this->executeStep('Generating temp cutted video files.');
foreach ($cutting->getCommandsForCutting() as $command) { foreach ($cutting->getCommandsForCutting() as $command) {

View file

@ -30,14 +30,22 @@ class Cutting
*/ */
private $video; private $video;
/**
* @var string
*/
private $tempFolder = '';
/** /**
* @var array * @var array
*/ */
private $tempFilenames = []; private $tempFilenames = [];
public function __construct(VideoInfo $video) public function __construct(
{ VideoInfo $video,
?string $tempFolder = null
) {
$this->video = $video; $this->video = $video;
$this->tempFolder = $tempFolder ?? sys_get_temp_dir();
} }
public function getCommandsForCutting(): \Generator public function getCommandsForCutting(): \Generator
@ -136,7 +144,7 @@ class Cutting
private function getNextTempFilename(): string private function getNextTempFilename(): string
{ {
$count = count($this->tempFilenames) + 1; $count = count($this->tempFilenames) + 1;
$nextName = sys_get_temp_dir() $nextName = $this->tempFolder
. DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
. $this->video->getOriginalFilenameWithSuffix('cut-' . $count); . $this->video->getOriginalFilenameWithSuffix('cut-' . $count);
@ -148,13 +156,13 @@ class Cutting
{ {
$file = new \SplFileInfo($this->video->getOriginalFilenameWithSuffix('metadata')); $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 private function getConcatFilename(): string
{ {
$file = new \SplFileInfo($this->video->getOriginalFilenameWithSuffix('concat')); $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';
} }
} }