Skip to content

Commit

Permalink
Adding ability to queue popular apps
Browse files Browse the repository at this point in the history
  • Loading branch information
ilumos committed Sep 8, 2017
1 parent 9029701 commit d339dfb
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ Automatically fill a [lancache](https://github.com/zeropingheroes/lancache) with
* 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

`steam:queue-popular-apps [top=100] [--free] [--windows] [--osx] [--linux]`

* Queue the top most popular apps on Steam in the past 2 weeeks
* Optionally
* Only queue top X apps (default 100)
* Only queue free apps
* Specify the platform(s) to download (default - windows)

`steam:dequeue [--app_id=] [--platform=] [--status=] [--message=]`

* Dequeue a items from the download queue.
Expand Down
14 changes: 5 additions & 9 deletions lancache-autofill
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Zeropingheroes\LancacheAutofill\Commands\App\{
InitialiseDatabase, InitialiseDownloadsDirectory
};
use Zeropingheroes\LancacheAutofill\Commands\Steam\{
AuthoriseAccount, Dequeue, Initialise, QueueApp, Requeue, SearchApps, ShowQueue, StartDownloading, UpdateAppList
AuthoriseAccount, Dequeue, Initialise, QueueApp, QueuePopularApps, Requeue, SearchApps, ShowQueue, StartDownloading, UpdateAppList
};

// Load Composer's autoloader
Expand All @@ -28,11 +28,6 @@ $dotenv = new Dotenv(__DIR__);
$dotenv->load();
$dotenv->required(['DOWNLOADS_DIRECTORY', 'STEAMCMD_PATH']);

// TODO: Move to class so existance of SteamCMD can be checked at the appropriate time
//if (!file_exists(getenv('STEAMCMD_PATH'))) {
// die('SteamCMD not found - please check the STEAMCMD_PATH environment variable is set correctly');
//}

// Set up the console app
$app = new Application(new Container, new Dispatcher, '5.5');

Expand All @@ -49,15 +44,16 @@ $capsule->bootEloquent();
$app->add(new InitialiseDatabase);
$app->add(new InitialiseDownloadsDirectory);

$app->add(new Initialise);
$app->add(new UpdateAppList);
$app->add(new SearchApps);
$app->add(new QueueApp);
$app->add(new QueuePopularApps);
$app->add(new ShowQueue);
$app->add(new StartDownloading);
$app->add(new AuthoriseAccount);
$app->add(new Dequeue);
$app->add(new Requeue);
$app->add(new AuthoriseAccount);
$app->add(new Initialise);
$app->add(new StartDownloading);

// Run the console app
$app->run(new ArgvInput(), new ConsoleOutput());
102 changes: 102 additions & 0 deletions src/Commands/Steam/QueuePopularApps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace Zeropingheroes\LancacheAutofill\Commands\Steam;

use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Zeropingheroes\LancacheAutofill\Models\SteamQueueItem;

class QueuePopularApps extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'steam:queue-popular-apps
{top=100 : Limit how many apps are queued}
{--windows=true : Queue the Windows version of the apps}
{--osx : Queue the OS X version of the apps}
{--linux : Queue the Linux version of the apps}
{--free : Only queue free apps}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Queue popular Steam apps for downloading';

/**
* The URL to get the list of popular Steam apps from.
*
* @var string
*/
const POPULAR_STEAM_APP_LIST_URL = 'http://steamspy.com/api.php?request=top100in2weeks';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$top = $this->argument('top');
$free = $this->option('free');

// Add platforms depending on options
if ($this->option('windows')) {
$platforms[] = 'windows';
}

if ($this->option('osx')) {
$platforms[] = 'osx';
}

if ($this->option('linux')) {
$platforms[] = 'linux';
}

$client = new Client();
$result = $client->request('GET', self::POPULAR_STEAM_APP_LIST_URL);

if ($result->getStatusCode() != 200) {
$this->error('Web API unreachable');
die();
}

$apps = json_decode($result->getBody(), true);

foreach ($apps as $appId => $app) {
if ($free && $app['price'] != 0) {
continue;
}

// Queue each platform separately
foreach ($platforms as $platform) {

$alreadyQueued = SteamQueueItem::where('app_id', $appId)
->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 = $appId;
$steamQueueItem->platform = $platform;
$steamQueueItem->status = 'queued';

if ($steamQueueItem->save()) {
$this->info('Added Steam app "'.$app['name'].'" on platform "'.ucfirst($platform).'" to download queue');
}
}
if (++$i == $top) {
break;
}
}
}
}

0 comments on commit d339dfb

Please sign in to comment.