Skip to content

Commit

Permalink
Fix: Skip fetching already locally stored information (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Feb 8, 2025
1 parent a2cd442 commit 48b2716
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
15 changes: 2 additions & 13 deletions src/Command/TotalSizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$games = $this->getGames($input, $output, $this->ownedItemsManager);

$io->note('Note that if you have a lot of games, this command might take a long time.');

$unit = SizeUnit::tryFrom($input->getOption('unit'));
if ($unit === null) {
$io->error("Unsupported unit, please use --help to see list of available units.");
return Command::FAILURE;
}

$short = $input->getOption('short');
$httpTimeout = $input->getOption('idle-timeout');
$total = 0;
foreach ($games as $game) {
foreach ($game->downloads as $download) {
if ($output->isVeryVerbose()) {
$io->comment("[{$game->title}] Downloading file '{$download->name}'");
}
$size = $this->downloadManager->getFileSize($download, $httpTimeout);
if ($size === null && !$short) {
$io->warning("Failed getting size for {$download->name}, the results might be incomplete");
continue;
}
$total += $size;
$total += $download->size;
}
}

Expand All @@ -108,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}

private function formatToUnit(int $total, SizeUnit $unit): float
private function formatToUnit(float $total, SizeUnit $unit): float
{
return match ($unit) {
SizeUnit::Bytes => $total,
Expand Down
14 changes: 0 additions & 14 deletions src/Service/DownloadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ public function getFilename(DownloadDescription $download, int $httpTimeout = 3)
return urldecode(pathinfo($url, PATHINFO_BASENAME));
}

public function getFileSize(DownloadDescription $download, int $httpTimeout = 3): ?int
{
$url = $this->getRealDownloadUrl($download, $httpTimeout);
if (!$url) {
return null;
}

$response = $this->httpClient->request(
Request::METHOD_HEAD,
$url,
);
return $response->getHeaders()['content-length'][0] ?? null;
}

public function download(
DownloadDescription $download,
callable $callback,
Expand Down

0 comments on commit 48b2716

Please sign in to comment.