vid-queue/app/Commands/GetShow.php
2022-03-05 19:51:04 -06:00

65 lines
1.7 KiB
PHP

<?php
namespace App\Commands;
use App\Exceptions\Quit;
use App\Models\Input;
class GetShow extends Command
{
protected $signature = 'get:show ' .
'{--i|input=* : Input files} ' .
'{--u|url= : URL to download} ' .
'{--d|destination= : Directory of show} ' .
'{--t|title= : The title of the episode} ' .
'{--l|low : Put on low priority queue}' .
'{--s|sync : Run synchronously}'
;
protected $description = 'Queue a show to re-encode or download';
public function handle(): int
{
$this->line(json_encode($this->options()));
$dest = $this->getDestination();
$input = $this->getInput();
if ($this->confirm('Do you wish to continue?', true)) {
$this->line(json_encode([$input, $dest]));
}
return static::SUCCESS;
}
protected function getInput(): Input
{
$ret = new Input;
$input = $this->option('input');
$ret->files = array_map(function (string $file) {
if (!file_exists($file)) {
throw new Quit("$file is not a valid file");
}
return realpath($file);
}, $input);
// @todo Get additional files
$ret->url = $this->option('url');
$this->line(json_encode($ret));
$ret->assertValid();
return $ret;
}
protected function getDestination(): string
{
$dir = $this->option('destination');
throw_if(!is_dir($dir), Quit::class, "$dir is not a valid directory");
// @todo find show title
return realpath($dir);
}
}