mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Add artisan command to populate steam apps table
This commit is contained in:
@@ -19,6 +19,11 @@ class ColorCLI
|
||||
$this->climate = new CLImate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function debug(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -27,6 +32,11 @@ class ColorCLI
|
||||
$this->climate->lightGray()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function info(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -35,6 +45,11 @@ class ColorCLI
|
||||
$this->climate->magenta()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function notice(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -43,6 +58,11 @@ class ColorCLI
|
||||
$this->climate->blue()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function warning(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -51,6 +71,11 @@ class ColorCLI
|
||||
$this->climate->yellow()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function error(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -59,6 +84,11 @@ class ColorCLI
|
||||
$this->climate->red()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function primary(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -67,6 +97,11 @@ class ColorCLI
|
||||
$this->climate->green()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function header(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -75,6 +110,11 @@ class ColorCLI
|
||||
$this->climate->yellow()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function alternate(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -83,6 +123,11 @@ class ColorCLI
|
||||
$this->climate->magenta()->bold()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $newline
|
||||
* @return void
|
||||
*/
|
||||
public function tmuxOrange(string $str, bool $newline = false): void
|
||||
{
|
||||
if ($newline) {
|
||||
@@ -91,23 +136,47 @@ class ColorCLI
|
||||
$this->climate->yellow()->bold()->out($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
public function primaryOver(string $str): void
|
||||
{
|
||||
$this->climate->green()->inline($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
public function headerOver(string $str): void
|
||||
{
|
||||
$this->climate->yellow()->inline($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
public function alternateOver(string $str): void
|
||||
{
|
||||
$this->climate->magenta()->bold()->inline($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
public function warningOver(string $str): void
|
||||
{
|
||||
$this->climate->red()->inline($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function progress()
|
||||
{
|
||||
return $this->climate->progress();
|
||||
}
|
||||
}
|
||||
|
||||
+31
-33
@@ -5,6 +5,8 @@ namespace Blacklight;
|
||||
use App\Models\Settings;
|
||||
use App\Models\SteamApp;
|
||||
use b3rs3rk\steamfront\Main;
|
||||
use DivineOmega\CliProgressBar\ProgressBar;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* Class Steam.
|
||||
@@ -16,24 +18,24 @@ class Steam
|
||||
/**
|
||||
* @var string The parsed game name from searchname
|
||||
*/
|
||||
public $searchTerm;
|
||||
public string $searchTerm;
|
||||
|
||||
/**
|
||||
* @var int The ID of the Steam Game matched
|
||||
*/
|
||||
protected $steamGameID;
|
||||
protected int $steamGameID;
|
||||
|
||||
protected $lastUpdate;
|
||||
|
||||
/**
|
||||
* @var \b3rs3rk\steamfront\Main
|
||||
* @var Main
|
||||
*/
|
||||
protected $steamFront;
|
||||
protected Main $steamFront;
|
||||
|
||||
/**
|
||||
* @var \Blacklight\ColorCLI
|
||||
* @var ColorCLI
|
||||
*/
|
||||
protected $colorCli;
|
||||
protected ColorCLI $colorCli;
|
||||
|
||||
/**
|
||||
* Steam constructor.
|
||||
@@ -59,15 +61,15 @@ class Steam
|
||||
/**
|
||||
* Gets all Information for the game.
|
||||
*
|
||||
* @param int $appID
|
||||
* @param int $appID
|
||||
* @return array|false
|
||||
*/
|
||||
public function getAll($appID)
|
||||
public function getAll(int $appID): bool|array
|
||||
{
|
||||
$res = $this->steamFront->getAppDetails($appID);
|
||||
|
||||
if ($res !== false) {
|
||||
$result = [
|
||||
return [
|
||||
'title' => $res->name,
|
||||
'description' => $res->description['short'] ?? null,
|
||||
'cover' => $res->images['header'] ?? null,
|
||||
@@ -79,13 +81,9 @@ class Steam
|
||||
'releasedate' => $res->releasedate['date'] ?? null,
|
||||
'genres' => $res->genres !== null ? implode(',', array_column($res->genres, 'description')) : '',
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($res === false) {
|
||||
$this->colorCli->notice('Steam did not return game data');
|
||||
}
|
||||
$this->colorCli->notice('Steam did not return game data');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -93,19 +91,19 @@ class Steam
|
||||
/**
|
||||
* Searches Steam Apps table for best title match -- prefers 100% match but returns highest over 90%.
|
||||
*
|
||||
* @param string $searchTerm The parsed game name from the release searchname
|
||||
* @param string $searchTerm The parsed game name from the release searchname
|
||||
* @return false|int $bestMatch The Best match from the given search term
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function search($searchTerm)
|
||||
public function search(string $searchTerm): bool|int
|
||||
{
|
||||
$bestMatch = false;
|
||||
|
||||
if (empty($searchTerm)) {
|
||||
$this->colorCli->notice('Search term cannot be empty');
|
||||
|
||||
return $bestMatch;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->populateSteamAppsTable();
|
||||
@@ -147,6 +145,7 @@ class Steam
|
||||
*/
|
||||
public function populateSteamAppsTable(): void
|
||||
{
|
||||
$bar = new ProgressBar();
|
||||
$lastUpdate = Settings::settingValue('APIs.Steam.last_update');
|
||||
$this->lastUpdate = $lastUpdate > 0 ? $lastUpdate : 0;
|
||||
if ((time() - (int) $this->lastUpdate) > 86400) {
|
||||
@@ -155,25 +154,24 @@ class Steam
|
||||
$fullAppArray = $this->steamFront->getFullAppList();
|
||||
$inserted = $dupe = 0;
|
||||
$this->colorCli->info('Populating steam apps table');
|
||||
foreach ($fullAppArray as $appsArray) {
|
||||
foreach ($appsArray as $appArray) {
|
||||
foreach ($appArray as $app) {
|
||||
$dupeCheck = SteamApp::query()->where('appid', '=', $app['appid'])->first(['appid']);
|
||||
|
||||
if ($dupeCheck === null) {
|
||||
SteamApp::query()->insert(['name' => $app['name'], 'appid' => $app['appid']]);
|
||||
$inserted++;
|
||||
if ($inserted % 500 === 0) {
|
||||
echo PHP_EOL.number_format($inserted).' apps inserted.'.PHP_EOL;
|
||||
} else {
|
||||
echo '.';
|
||||
}
|
||||
} else {
|
||||
$dupe++;
|
||||
}
|
||||
$appsArray = Arr::pluck($fullAppArray, 'apps');
|
||||
$max = count($appsArray[0]);
|
||||
$bar->setMaxProgress($max);
|
||||
foreach ($appsArray as $appArray) {
|
||||
foreach ($appArray as $app) {
|
||||
$dupeCheck = SteamApp::query()->where('appid', '=', $app['appid'])->first(['appid']);
|
||||
if ($dupeCheck === null) {
|
||||
SteamApp::query()->insert(['name' => $app['name'], 'appid' => $app['appid']]);
|
||||
$inserted++;
|
||||
} else {
|
||||
$dupe++;
|
||||
}
|
||||
$bar->advance()->display();
|
||||
}
|
||||
}
|
||||
|
||||
$bar->complete();
|
||||
|
||||
echo PHP_EOL.'Added '.$inserted.' new steam app(s), '.$dupe.' duplicates skipped'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Blacklight\db\populate\AniDB;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NntmuxPopulateAniDB extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'nntmux:populate-anidb
|
||||
{--full : Populate full data}
|
||||
{--info : Populate info only}
|
||||
{--anidbid : Populate tables for specific anidbid}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Populate AniDB table';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->option('full')) {
|
||||
(new AniDB(['Echo' => true]))->populateTable('full');
|
||||
} elseif ($this->option('info') && is_numeric($this->option('anidbid'))) {
|
||||
(new AniDB(['Echo' => true]))->populateTable('info', $this->option('anidbid'));
|
||||
} elseif ($this->option('info')){
|
||||
(new AniDB(['Echo' => true]))->populateTable('info');
|
||||
}
|
||||
$this->info('AniDB tables populated with requested data');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Blacklight\Steam;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NntmuxPopulateSteam extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'nntmux:populate-steam';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Populate Steam Apps table';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$steam = new Steam();
|
||||
|
||||
$steam->populateSteamAppsTable();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/* This script is designed to gather all show data from anidb and add it to the anidb table for nntmux, as part of this process we need the number of PI queries that can be executed max and whether or not we want debuging the first argument if unset will try to do the entire list (a good way to get banned), the second option can be blank or true for debugging.
|
||||
* IF you are using this script then then you also want to edit anidb.php in www/lib and locate "604800" and replace it with 1204400, this will make sure it never tries to connect to anidb as this will fail
|
||||
*/
|
||||
require_once dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
|
||||
|
||||
use Blacklight\ColorCLI;
|
||||
use Blacklight\db\populate\AniDB;
|
||||
|
||||
if ($argc > 1 && $argv[1] === 'true' && isset($argv[2])) {
|
||||
if ($argv[2] === 'full') {
|
||||
(new AniDB(['Echo' => true]))->populateTable('full');
|
||||
} elseif ($argv[2] === 'info') {
|
||||
if ($argv[3] !== null && is_numeric($argv[3])) {
|
||||
(new AniDB(['Echo' => true]))->populateTable('info', $argv[3]);
|
||||
} else {
|
||||
(new AniDB(['Echo' => true]))->populateTable('info');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(new ColorCLI())->error(
|
||||
'To execute this script you must provide a boolean argument.'.PHP_EOL.
|
||||
'Argument1: true|false to run this script or not'.PHP_EOL.
|
||||
'Argument2: full|info for what type of data to populate.'.PHP_EOL.
|
||||
'Argument3 (optional) anidbid to fetch info for'.PHP_EOL.
|
||||
'WARNING: Argument "info" without third argument will get you banned from AniDB almost instantly'
|
||||
);
|
||||
}
|
||||
@@ -56,6 +56,7 @@
|
||||
"dariusiii/tmdb-laravel": "^6.0",
|
||||
"dariusiii/token": "^5.0",
|
||||
"dborsatto/php-giantbomb": "^2.0",
|
||||
"divineomega/php-cli-progress-bar": "^2.1",
|
||||
"doctrine/dbal": "^3.0",
|
||||
"fakerphp/faker": "^1.12",
|
||||
"genealabs/laravel-caffeine": "^10.0",
|
||||
|
||||
Generated
+104
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "f0cbb646147483a8138272a6f050f9d6",
|
||||
"content-hash": "a5896c29d62f20052346eff6a7a3ffdd",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aharen/omdbapi",
|
||||
@@ -1323,6 +1323,47 @@
|
||||
},
|
||||
"time": "2022-10-27T11:44:00+00:00"
|
||||
},
|
||||
{
|
||||
"name": "divineomega/php-cli-progress-bar",
|
||||
"version": "v2.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DivineOmega/php-cli-progress-bar.git",
|
||||
"reference": "0c2d8d64d27dce8c2f214260c1e28f9fb4821bdc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/DivineOmega/php-cli-progress-bar/zipball/0c2d8d64d27dce8c2f214260c1e28f9fb4821bdc",
|
||||
"reference": "0c2d8d64d27dce8c2f214260c1e28f9fb4821bdc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"khill/php-duration": "^1.0",
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"DivineOmega\\CliProgressBar\\": "./src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0-only"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jordan Hall",
|
||||
"email": "jordan@hall05.co.uk"
|
||||
}
|
||||
],
|
||||
"description": "Progress bar for command line PHP scripts",
|
||||
"support": {
|
||||
"issues": "https://github.com/DivineOmega/php-cli-progress-bar/issues",
|
||||
"source": "https://github.com/DivineOmega/php-cli-progress-bar/tree/master"
|
||||
},
|
||||
"time": "2020-02-06T21:58:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/cache",
|
||||
"version": "2.2.0",
|
||||
@@ -3677,6 +3718,68 @@
|
||||
},
|
||||
"time": "2018-05-30T08:34:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "khill/php-duration",
|
||||
"version": "1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kevinkhill/php-duration.git",
|
||||
"reference": "dcb222fd0c9eb459676c9eef6fb9f9d2baf749b1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/kevinkhill/php-duration/zipball/dcb222fd0c9eb459676c9eef6fb9f9d2baf749b1",
|
||||
"reference": "dcb222fd0c9eb459676c9eef6fb9f9d2baf749b1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/instantiator": "1.0.4",
|
||||
"phpstan/phpstan": "^0.12.81",
|
||||
"phpunit/phpunit": "~4.8|~5.0",
|
||||
"satooshi/php-coveralls": "~1.0",
|
||||
"symfony/config": "~2.0",
|
||||
"symfony/console": "~2.0",
|
||||
"symfony/filesystem": "~2.0",
|
||||
"symfony/stopwatch": "~2.0",
|
||||
"symfony/yaml": "~2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Khill\\Duration\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kevin Hill",
|
||||
"email": "kevinkhill@gmail.com",
|
||||
"role": "Creator"
|
||||
},
|
||||
{
|
||||
"name": "Duration Community",
|
||||
"homepage": "https://github.com/kevinkhill/php-duration/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Converts between colon formatted time, human-readable time and seconds",
|
||||
"keywords": [
|
||||
"convert",
|
||||
"duration",
|
||||
"seconds",
|
||||
"time"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/kevinkhill/php-duration/issues",
|
||||
"source": "https://github.com/kevinkhill/php-duration/tree/1.1.0"
|
||||
},
|
||||
"time": "2021-03-17T11:34:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v10.4.1",
|
||||
|
||||
Reference in New Issue
Block a user