diff --git a/php/src/.gitignore b/php/src/.gitignore index 46340a6..ef1a7de 100644 --- a/php/src/.gitignore +++ b/php/src/.gitignore @@ -18,3 +18,4 @@ yarn-error.log /.fleet /.idea /.vscode +public/images/artist diff --git a/php/src/app/Http/Controllers/ApiController.php b/php/src/app/Http/Controllers/ApiController.php index ebecd0c..2da6038 100644 --- a/php/src/app/Http/Controllers/ApiController.php +++ b/php/src/app/Http/Controllers/ApiController.php @@ -22,10 +22,13 @@ class ApiController extends Controller 'thumbnail' => $artist->thumbnail, ]; } - - \Log::info('======================='); $response = json_encode( array('data' => $data)); - \Log::info($response); return $response; } + + public function queue_artist($id, ArtistQueue $artistQueue) + { + $artistQueue->enqueue($id); + } + } diff --git a/php/src/app/Http/Controllers/SearchController.php b/php/src/app/Http/Controllers/SearchController.php index 7181976..94fabd9 100644 --- a/php/src/app/Http/Controllers/SearchController.php +++ b/php/src/app/Http/Controllers/SearchController.php @@ -4,13 +4,15 @@ namespace App\Http\Controllers; use App\Models\Artist; use App\Models\WebDriver; +use App\Utils\ImageUrl; use Facebook\WebDriver\WebDriverExpectedCondition; use Illuminate\Http\Request; - use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\WebDriverBy; +use Illuminate\Support\Facades\App; +use Nette\Utils\Image; class SearchController extends Controller { @@ -36,10 +38,19 @@ class SearchController extends Controller $artistHref = $artistLink[0]->getAttribute('href'); $artistName = $artistLink[0]->getAttribute('title'); + // Resize image and save to file, provide path to data + $imageUrl = ImageUrl::modifyGoogleImageUrl($artistThumbnail); + $imageFileUrl = ImageUrl::save_img_url($imageUrl); + + \Log::info('============================'); + \Log::info($imageUrl); + \Log::info($imageFileUrl); + $data = [ 'name' => $artistName, 'thumbnail' => $artistThumbnail, 'url_remote' => $artistHref, + 'image' => $imageFileUrl, ]; $artist_id = Artist::findOrCreateByName($artistName, $data); return $artist_id->read(); @@ -81,11 +92,21 @@ class SearchController extends Controller $artistLink = $artist->findElements(WebDriverBy::cssSelector('a')); $artistHref = $artistLink[0]->getAttribute('href'); $artistName = $artistLink[0]->getAttribute('aria-label'); + + // Resize image and save to file, provide path to data + $imageUrl = ImageUrl::modifyGoogleImageUrl($artistThumbnail); + $imageFileUrl = ImageUrl::save_img_url($imageUrl); + + \Log::info('============================'); + \Log::info($imageUrl); + \Log::info($imageFileUrl); + // Create if we don't have it yet $data = [ 'name' => $artistName, 'thumbnail' => $artistThumbnail, 'url_remote' => $artistHref, + 'image' => $imageFileUrl, ]; $artist_id = Artist::findOrCreateByName($artistName, $data); $response[] = $artist_id->read(); diff --git a/php/src/app/Models/AlbumQueue.php b/php/src/app/Models/AlbumQueue.php new file mode 100644 index 0000000..ebc2920 --- /dev/null +++ b/php/src/app/Models/AlbumQueue.php @@ -0,0 +1,21 @@ +get(); } - public static function addArtist(string $name, string $thumbnail, string $url_remote) + public static function addArtist(string $name, string $thumbnail, string $url_remote, string $image) { $artist = new Artist(); $artist->name = $name; $artist->url_remote = $url_remote; $artist->thumbnail = $thumbnail; + $artist->image = $image; $artist->save(); return $artist; } @@ -28,7 +29,7 @@ class Artist extends Model { $artist = self::findByName($name)->first(); if (!$artist && $data) { - $artist = self::addArtist($data['name'], $data['thumbnail'], $data['url_remote']); + $artist = self::addArtist($data['name'], $data['thumbnail'], $data['url_remote'], $data['image']); } return $artist; } diff --git a/php/src/app/Models/ArtistQueue.php b/php/src/app/Models/ArtistQueue.php index f31943f..e4f83f9 100644 --- a/php/src/app/Models/ArtistQueue.php +++ b/php/src/app/Models/ArtistQueue.php @@ -8,4 +8,18 @@ use Illuminate\Database\Eloquent\Model; class ArtistQueue extends Model { use HasFactory; + + public function enqueue($artist_id) + { + $this->artist_id = $artist_id; + $this->save(); + } + + + public function process_queue() + { + // Scrape the artist page for image, and album data (image, url, name) + } + + } diff --git a/php/src/app/Utils/ImageUrl.php b/php/src/app/Utils/ImageUrl.php new file mode 100644 index 0000000..60e2224 --- /dev/null +++ b/php/src/app/Utils/ImageUrl.php @@ -0,0 +1,67 @@ +id(); + $table->timestamps(); + $table->foreignId('album_id')->nullable()->constrained('albums'); + $table->enum('state', [ + 'pending', + 'in_progress', + 'done', + ])->default('pending'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('album_queues'); + } +}; diff --git a/php/src/public/js/app.js b/php/src/public/js/app.js index 8dec7b1..22bd256 100644 --- a/php/src/public/js/app.js +++ b/php/src/public/js/app.js @@ -2,39 +2,66 @@ console.log('Version 1:20:2'); const appModal = $('#modalDownloadQueue'); const loader = $("#loader-wrapper"); -function construct_artist_result_html(artist_list) { - let html = '