diff --git a/php/src/app/Models/ArtistQueue.php b/php/src/app/Models/ArtistQueue.php index d18f690..0a152e8 100644 --- a/php/src/app/Models/ArtistQueue.php +++ b/php/src/app/Models/ArtistQueue.php @@ -32,7 +32,9 @@ class ArtistQueue extends Model $artist_id = Artist::where('id', $this->artist_id)->get()->first(); if ($artist_id->count() > 0) { try { - WebScraper::scrapeAlbums($driver, $artist_id); + $album_count = WebScraper::scrapeAlbums($driver, $artist_id); + $artist_id->album_count = $album_count; + $artist_id->save(); } catch (Exception $e) { \Log::warning('Failed to scrape albums: ' . $e->getMessage()); } finally { diff --git a/php/src/app/Models/WebScraper.php b/php/src/app/Models/WebScraper.php index 1776476..66aaab2 100644 --- a/php/src/app/Models/WebScraper.php +++ b/php/src/app/Models/WebScraper.php @@ -110,7 +110,7 @@ class WebScraper { $url = 'https://music.youtube.com/' . $artist_id->url_remote; $driver->get($url); - $response = []; + $response = 0; $albumBtn = $driver->findElement(WebDriverBy::xpath('//a[text()="Albums"]')); if ($albumBtn) { $albumBtn->click(); @@ -120,6 +120,7 @@ class WebScraper $albumContainers = $item->findElements(WebDriverBy::cssSelector('.ytmusic-grid-renderer')); if ($albumContainers) { foreach ($albumContainers as $albumContainer) { + $response += 1; $albumLink = $albumContainer->findElement(WebDriverBy::cssSelector('a')); $albumHref = $albumLink->getAttribute('href'); $albumTitle = $albumLink->getAttribute('title'); diff --git a/php/src/database/migrations/2024_08_11_200512_imp_artists__field__album_count.php b/php/src/database/migrations/2024_08_11_200512_imp_artists__field__album_count.php new file mode 100644 index 0000000..d5d3a28 --- /dev/null +++ b/php/src/database/migrations/2024_08_11_200512_imp_artists__field__album_count.php @@ -0,0 +1,28 @@ +integer('album_count')->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('artists', function (Blueprint $table) { + // + }); + } +}; diff --git a/php/src/database/migrations/2024_08_11_201212_imp_artists__field__album_done.php b/php/src/database/migrations/2024_08_11_201212_imp_artists__field__album_done.php new file mode 100644 index 0000000..a99c67c --- /dev/null +++ b/php/src/database/migrations/2024_08_11_201212_imp_artists__field__album_done.php @@ -0,0 +1,28 @@ +integer('album_done')->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('artists', function (Blueprint $table) { + // + }); + } +};