From d339dfb06739a102b6b058c6dc39d709ad125c9c Mon Sep 17 00:00:00 2001 From: ilumos Date: Fri, 8 Sep 2017 21:22:38 +0100 Subject: [PATCH] Adding ability to queue popular apps --- README.md | 8 ++ lancache-autofill | 14 ++-- src/Commands/Steam/QueuePopularApps.php | 102 ++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 src/Commands/Steam/QueuePopularApps.php diff --git a/README.md b/README.md index d757758..a293f5d 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/lancache-autofill b/lancache-autofill index 10dd4d3..bfccdb2 100755 --- a/lancache-autofill +++ b/lancache-autofill @@ -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()); \ No newline at end of file diff --git a/src/Commands/Steam/QueuePopularApps.php b/src/Commands/Steam/QueuePopularApps.php new file mode 100644 index 0000000..5302a34 --- /dev/null +++ b/src/Commands/Steam/QueuePopularApps.php @@ -0,0 +1,102 @@ +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; + } + } + } +} \ No newline at end of file