diff --git a/app/Commands/GetShow.php b/app/Commands/GetShow.php index 240298b..3d5f1ac 100644 --- a/app/Commands/GetShow.php +++ b/app/Commands/GetShow.php @@ -3,11 +3,13 @@ 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}' . @@ -19,24 +21,22 @@ class GetShow extends Command public function handle(): int { $this->line(json_encode($this->options())); - # $this->ask('What?'); - # throw new Quit('Nope', 5); - $files = $this->getFiles(); + $dest = $this->getDestination(); + $input = $this->getInput(); + if ($this->confirm('Do you wish to continue?', true)) { - $this->line(json_encode($files)); + $this->line(json_encode([$input, $dest])); } return static::SUCCESS; } - protected function getFiles(): array + protected function getInput(): Input { + $ret = new Input; $input = $this->option('input'); - if (empty($input)) { - throw new Quit('No files given'); - } - $files = array_map(function (string $file) { + $ret->files = array_map(function (string $file) { if (!file_exists($file)) { throw new Quit("$file is not a valid file"); } @@ -44,6 +44,22 @@ class GetShow extends Command return realpath($file); }, $input); - return $files; + // @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); } } diff --git a/app/Models/Input.php b/app/Models/Input.php new file mode 100644 index 0000000..1f9353f --- /dev/null +++ b/app/Models/Input.php @@ -0,0 +1,25 @@ +files) && empty($this->url), + Quit::class, + 'Must have either a valid file or URL' + ); + } + + public function hasURL(): bool + { + return !empty($this->url); + } +}