vid-queue/app/Commands/GetShow.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2022-03-03 22:55:57 -06:00
<?php
namespace App\Commands;
use App\Exceptions\Quit;
2022-03-05 19:51:04 -06:00
use App\Models\Input;
2022-03-03 22:55:57 -06:00
class GetShow extends Command
{
protected $signature = 'get:show ' .
'{--i|input=* : Input files} ' .
2022-03-05 19:51:04 -06:00
'{--u|url= : URL to download} ' .
2022-03-03 22:55:57 -06:00
'{--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()));
2022-03-05 19:51:04 -06:00
$dest = $this->getDestination();
$input = $this->getInput();
2022-03-03 22:55:57 -06:00
if ($this->confirm('Do you wish to continue?', true)) {
2022-03-05 19:51:04 -06:00
$this->line(json_encode([$input, $dest]));
2022-03-03 22:55:57 -06:00
}
return static::SUCCESS;
}
2022-03-05 19:51:04 -06:00
protected function getInput(): Input
2022-03-03 22:55:57 -06:00
{
2022-03-05 19:51:04 -06:00
$ret = new Input;
2022-03-03 22:55:57 -06:00
$input = $this->option('input');
2022-03-05 19:51:04 -06:00
$ret->files = array_map(function (string $file) {
2022-03-03 22:55:57 -06:00
if (!file_exists($file)) {
throw new Quit("$file is not a valid file");
}
return realpath($file);
}, $input);
2022-03-05 19:51:04 -06:00
// @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);
2022-03-03 22:55:57 -06:00
}
}