Skip to content

Commit b57732d

Browse files
authored
chore: add fallbacks for missing input
1 parent 9327263 commit b57732d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Diff for: app/Commands/DownloadCommand.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class DownloadCommand extends Command
1616
{
1717
/** {@inheritdoc} */
18-
protected $signature = 'download { trakt-user : Trakt username for the list }
18+
protected $signature = 'download { trakt-user= : Trakt username for the list }
1919
{ --l|list=watchlist : A custom list id or stub }
2020
{ --o|output=./torrents : The directory to output data to }
2121
{ --quality=1080p : The quality to download (720p, 1080p or 3D) }
@@ -27,7 +27,7 @@ class DownloadCommand extends Command
2727
/** @var Collection<Movie> */
2828
private Collection $traktList;
2929

30-
private Quality|null $quality;
30+
private Quality $quality;
3131

3232
private TraktClient $trakt;
3333

@@ -38,23 +38,27 @@ public function handle(TraktClient $traktClient): void
3838
$this->trakt = $traktClient;
3939
$this->yts = $ytsClient;
4040

41-
$this->quality = Quality::tryFrom($this->option('quality'));
41+
$
42+
$this->quality = Quality::tryFrom($this->option('quality')) ?? Quality::Q_1080P;
4243

4344
try {
44-
$this->retrieveTraktList()->downloadTorrentsFromYts();
45+
$this->retrieveTraktList(
46+
$this->argument('trakt-user') ?? $this->ask('What is the Trakt username'),
47+
$this->option('list') ?? $this->ask('What is the list slug or id'),
48+
)->downloadTorrentsFromYts();
4549
} catch (\RuntimeException $exception) {
4650
$this->warn($exception->getMessage());
4751

4852
return;
4953
}
5054
}
5155

52-
private function retrieveTraktList(): self
56+
private function retrieveTraktList(string $username, string|null $list): self
5357
{
54-
$this->traktList = $this->trakt->getList($this->argument('trakt-user'), $this->option('list'));
58+
$this->traktList = $this->trakt->getList($username, $list);
5559

5660
$this->comment(
57-
"<options=bold>{$this->option('list')}</> (<options=bold>{$this->argument('trakt-user')}</>): Retrieved successfully",
61+
"<options=bold>{$list}</> (<options=bold>{$username}</>): Retrieved successfully",
5862
OutputInterface::VERBOSITY_VERY_VERBOSE
5963
);
6064

@@ -104,7 +108,7 @@ private function downloadTorrentsFromYts(): void
104108

105109
if (! $matchedTorrent) {
106110
$this->components->warn(
107-
"'{$movie->title} ({$movie->year})': No torrent available in '{$this->quality?->value}' quality",
111+
"'{$movie->title} ({$movie->year})': No torrent available in '{$this->quality->value}' quality",
108112
OutputInterface::VERBOSITY_VERY_VERBOSE
109113
);
110114

0 commit comments

Comments
 (0)