Adding ability to queue one or more app IDs at once

This commit is contained in:
ilumos 2017-09-07 22:27:45 +01:00
parent 3a1894a880
commit 9029701e91
2 changed files with 43 additions and 42 deletions

View file

@ -72,9 +72,9 @@ Automatically fill a [lancache](https://github.com/zeropingheroes/lancache) with
* Authorise a Steam account to allow download of apps in their library.
* If no account is specified, you will be prompted for the username
`steam:queue-app appid [--windows] [--osx] [--linux]`
`steam:queue-app appid [appid, appid...] [--windows] [--osx] [--linux]`
* Queue a Steam app for downloading.
* Queue one or more Steam apps for downloading.
* Optionally the platform(s) to download can be specified as options
* If no platform option is specified, the Windows version of the app will be queued

View file

@ -15,7 +15,7 @@ class QueueApp extends Command
* @var string
*/
protected $signature = 'steam:queue-app
{app_id : The ID of the app}
{app_ids* : One or more app IDs to queue}
{--windows=true : Queue the Windows version of the app}
{--osx : Queue the OS X version of the app}
{--linux : Queue the Linux version of the app}';
@ -34,50 +34,51 @@ class QueueApp extends Command
*/
public function handle()
{
$appId = $this->argument('app_id');
$appIds = $this->argument('app_ids');
if (!$app = SteamApp::find($appId)) {
$this->error('Steam app with ID '.$this->argument('app_id').' not found');
die();
}
// Add platforms depending on options
if ($this->option('windows')) {
$platforms[] = 'windows';
}
if ($this->option('osx')) {
$platforms[] = 'osx';
}
if ($this->option('linux')) {
$platforms[] = 'linux';
}
// Queue each platform separately
foreach ($platforms as $platform) {
$alreadyQueued = SteamQueueItem::where('app_id', $app->id)
->where('platform', $platform)
->first();
if ($alreadyQueued) {
$this->error('Steam app "'.$app->name.'" on platform "'.ucfirst($platform).'" already in download queue');
continue;
foreach($appIds as $appId)
{
if (!$app = SteamApp::find($appId)) {
$this->error('Steam app with ID '.$appId.' not found');
die();
}
// Add the app to the download queue, specifying the platform and account
$steamQueueItem = new SteamQueueItem;
$steamQueueItem->app_id = $app->id;
$steamQueueItem->platform = $platform;
$steamQueueItem->status = 'queued';
if ($steamQueueItem->save()) {
$this->info('Added Steam app "'.$app->name.'" on platform "'.ucfirst($platform).'" to download queue');
// Add platforms depending on options
if ($this->option('windows')) {
$platforms[] = 'windows';
}
if ($this->option('osx')) {
$platforms[] = 'osx';
}
if ($this->option('linux')) {
$platforms[] = 'linux';
}
// Queue each platform separately
foreach ($platforms as $platform) {
$alreadyQueued = SteamQueueItem::where('app_id', $app->id)
->where('platform', $platform)
->first();
if ($alreadyQueued) {
$this->error('Steam app "'.$app->name.'" on platform "'.ucfirst($platform).'" already in download queue');
continue;
}
// Add the app to the download queue, specifying the platform and account
$steamQueueItem = new SteamQueueItem;
$steamQueueItem->app_id = $app->id;
$steamQueueItem->platform = $platform;
$steamQueueItem->status = 'queued';
if ($steamQueueItem->save()) {
$this->info('Added Steam app "'.$app->name.'" on platform "'.ucfirst($platform).'" to download queue');
}
}
}
}
}