mirror of
https://github.com/zeropingheroes/lancache-autofill
synced 2024-11-26 01:10:18 +00:00
Adding ability to queue popular apps
This commit is contained in:
parent
9029701e91
commit
d339dfb067
3 changed files with 115 additions and 9 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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
src/Commands/Steam/QueuePopularApps.php
Normal file
102
src/Commands/Steam/QueuePopularApps.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue