-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] Import Commands
- Loading branch information
Showing
512 changed files
with
8,246 additions
and
31,202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Anime; | ||
use Illuminate\Console\Command; | ||
use JsonMachine\JsonDecoder\ExtJsonDecoder; | ||
use JsonMachine\JsonMachine; | ||
|
||
class ImportAnimeID extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:anime-ids'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Imports anime ids for different services.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
$file = storage_path('app/anime-offline-database.json'); | ||
$fileSize = filesize($file); | ||
$animes = JsonMachine::fromFile($file, '/data', new ExtJsonDecoder); | ||
|
||
$progressBar = $this->output->createProgressBar($fileSize); | ||
$progressBar->start(); | ||
|
||
foreach ($animes as $data) { | ||
$sources = $this->filterSources($data->sources); | ||
|
||
if (array_key_exists('mal_id', $sources)) { | ||
$anime = Anime::firstWhere([ | ||
['mal_id', $sources['mal_id']], | ||
]); | ||
|
||
if (!empty($anime)) { | ||
$anime->update($sources); | ||
} | ||
} | ||
|
||
$progress = $animes->getPosition(); | ||
$progressBar->setProgress($progress); | ||
} | ||
|
||
$progressBar->finish(); | ||
return 1; | ||
} | ||
|
||
/** | ||
* Returns an array of the sources as key_id => id. | ||
* | ||
* @param array $sources | ||
* @return array | ||
*/ | ||
protected function filterSources(array $sources): array | ||
{ | ||
if (empty($sources)) { | ||
return $sources; | ||
} | ||
$regexSearch = [ | ||
'anidb_id' => '#https:\/\/anidb.net\/anime\/(\w+)$#i', | ||
'anilist_id' => '#https:\/\/anilist.co\/anime\/(\w+)$#i', | ||
'kitsu_id' => '#https:\/\/kitsu.io\/anime\/(\w+)$#i', | ||
'mal_id' => '#https:\/\/myanimelist.net\/anime/(\w+)$#i', | ||
'notify_id' => '#https:\/\/notify.moe\/anime/(\w+)$#i', | ||
]; | ||
$matchedSources = []; | ||
|
||
foreach ($regexSearch as $key => $regex) { | ||
$matchArray = preg_grep($regex, $sources); | ||
|
||
if (!empty($matchArray)) { | ||
foreach ($matchArray as $item) { | ||
$matchCount = preg_match($regex, $item, $match); | ||
|
||
if ($matchCount) { | ||
$matchedSources[$key] = $match[1]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $matchedSources; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\KDashboard; | ||
|
||
use App\Jobs\ProcessImportAnime; | ||
use App\Models\KDashboard\Anime as KAnime; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class ImportAnime extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:anime'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Imports the anime from the KDashboard database.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
KAnime::chunk(1000, function (Collection $kAnimes) { | ||
ProcessImportAnime::dispatch($kAnimes); | ||
}); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\KDashboard; | ||
|
||
use App\Jobs\ProcessImportAnimeCast; | ||
use App\Models\KDashboard\AnimeCharacter as KAnimeCast; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class ImportAnimeCasts extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:anime-cast'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Imports the anime casts from the KDashboard database.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
KAnimeCast::where([ | ||
['id', '>', 250000], | ||
])->chunk(1000, function (Collection $kAnimeCasts) { | ||
ProcessImportAnimeCast::dispatch($kAnimeCasts); | ||
}); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\KDashboard; | ||
|
||
use App\Jobs\ProcessImportAnimeGenre; | ||
use App\Models\KDashboard\MediaGenre as KMediaGenre; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class ImportAnimeGenres extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:anime-genres'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Imports the anime genres from the KDashboard database.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
KMediaGenre::where('type', 'anime')->chunk(1000, function (Collection $kMediaGenres) { | ||
ProcessImportAnimeGenre::dispatch($kMediaGenres); | ||
}); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\KDashboard; | ||
|
||
use App\Jobs\ProcessImportAnimeRelations; | ||
use App\Models\KDashboard\MediaRelated as KMediaRelated; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class ImportAnimeRelations extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:anime-relations'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Imports the anime relations from the KDashboard database'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
KMediaRelated::where([ | ||
['media_type', 'anime'], | ||
['related_type', 'anime'], | ||
])->chunk(1000, function (Collection $kMediaRelated) { | ||
ProcessImportAnimeRelations::dispatch($kMediaRelated); | ||
}); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\KDashboard; | ||
|
||
use App\Jobs\ProcessImportAnimeSong; | ||
use App\Models\KDashboard\Song as KSong; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class ImportAnimeSongs extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'import:anime-songs'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Imports the anime songs from the KDashboard database.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(): int | ||
{ | ||
KSong::chunk(1000, function (Collection $kAnimeSongs) { | ||
ProcessImportAnimeSong::dispatch($kAnimeSongs); | ||
}); | ||
|
||
return 1; | ||
} | ||
} |
Oops, something went wrong.