diff options
Diffstat (limited to 'app/Libraries/Background.php')
| -rw-r--r-- | app/Libraries/Background.php | 44 |
1 files changed, 44 insertions, 0 deletions
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>', '%%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); + } + } } |
