From 9436a3cd81d593de15653840ce4f69cee5cb573f Mon Sep 17 00:00:00 2001 From: horus Date: Thu, 19 Mar 2020 02:56:04 +0100 Subject: Add more data from anilist, namely synopsis, official hashtag and user preferred title. --- app/Libraries/Background.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'app/Libraries') diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 1c271f1..d0126f0 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -138,6 +138,10 @@ class Background { sleep(10); $anime->fill( $entry->getMalID(), $is_airing=true ); + if ( "" == $anime->mal_url ) { + continue; + } + if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) { $anime->save(); } @@ -178,4 +182,44 @@ class Background { } } } + + public function addEnhancementToAnime( Anime $anime ) { + /** + * Try to get Data from Anilist. + * On error return early. + */ + try { + $enhancement = $anime->getEnhancementFromAnilist(); + } catch( \Exception $e ) { + echo "addEnhancementToAnime: Getting Data from Anilist failed for anime: " . $anime->title_pref . " (" . $anime->mal_id . ")\n"; + return; + } + if ( "" == $enhancement ) { + return; + } + + $update = array(); + if ( ! is_null( $enhancement->description ) ) { + $update["synopsis"] = str_replace('
', '%%br%%', $enhancement->description); + } + if ( ! is_null( $enhancement->hashtag ) ) { + $update["hashtag"] = $enhancement->hashtag; + } + if ( ! is_null( $enhancement->title->userPreferred ) ) { + $update["title_pref"] = $enhancement->title->userPreferred; + } + + echo "Updating " . $anime->title_pref . " (" . $anime->mal_id . ")\n"; + DB::table('anime') + ->where('mal_id', $anime->mal_id) + ->update( $update ); + } + + public function saveEnhancementForAll() { + $anime_all = Anime::where('is_airing', true)->where('synopsis', '')->get(); + foreach( $anime_all as $anime ) { + $this->addEnhancementToAnime($anime); + sleep(1); + } + } } -- cgit v1.2.3