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 = '

Found Artist!

'; - let index = 0; - artist_list.forEach((element) => { - index += 1; - html += ` -
-
-
-
- -
-
-

${element.name}

-
+function template_artist_result(element) { + return ` +
+
+
+
+ +
+
+

${element.name}

- ` - if (index === 1 && artist_list.length > 1) { - html += '
'; - html += '
Suggested Artists
' - html += '
'; - } - }) +
+ ` +} + +function construct_artist_result_html(artist_list) { + let html = '

Found Artist!

'; + let index = 0; + if (artist_list.length > 1) { + artist_list.forEach((element) => { + index += 1; + html += template_artist_result(element); + if (index === 1 && artist_list.length > 1) { + html += '
'; + html += '
Suggested Artists
' + html += '
'; + } + }) + } else { + html += template_artist_result(artist_list); + } return html } -function proc_notification(icon, html, text) { +function proc_notification(icon, title, html) { Swal.fire({ - html: html, icon: icon, - text: text + title: title, + html: html + }) +} + +function artist_queue_toggle(element) { + let self = $(element); + console.log(self); + console.log(self.data('artist_id')); + let artist_name = self.data('artist_name'); + self.prop('disabled', true) + $.ajax({ + url: `/api/artist/queue/${self.data('artist_id')}`, + success: () => { + proc_notification('success', 'Queued Download', `Artist ${artist_name} Queued for Download!`); + }, + error: (response) => { + console.log(response); + proc_notification('error', 'What the flip?!', `Failed to queue artist ${artist_name}

${response.status}: ${response.statusText}`); + self.prop('disabled', false); + } }) } @@ -68,8 +95,8 @@ $('#download_btn').on('click', () => { console.log(response); console.log('==========='); icon = 'success'; - title = construct_artist_result_html(response); - proc_notification(icon, title, 'Artist found'); + let html = construct_artist_result_html(response); + proc_notification(icon, title, html); $('#search_bar').val(''); loader.fadeOut(700); }, @@ -95,13 +122,13 @@ document.addEventListener('alpine:init', () => { Alpine.store('app', { init() { // TODO: Poll for artists and queue - this.Artists = []; + // this.Artists = []; this.Queue = []; - this.ArtistResults = []; + // this.ArtistResults = []; }, - Artists: [], // Rendered in the 'Artists' modal - ArtistResults: [], // Rendered in the SWAL popup + // Artists: [], // Rendered in the 'Artists' modal + // ArtistResults: [], // Rendered in the SWAL popup Queue: [], // Rendered in the 'Queue' modal }); @@ -116,14 +143,25 @@ $(document).ready(function () { type: 'get', dataType: 'json', columns: [ - {data: 'thumbnail', render: (data) => { return ``}}, + { + data: 'thumbnail', orderable: false, render: (data) => { + return `` + } + }, {data: 'name'}, - {title: 'Channel', data: 'url_remote', render: (data) => {return ``}}, + { + title: 'Channel', data: 'url_remote', render: (data) => { + return `` + } + }, {data: 'state'}, - {data: 'id', render: (data, row) => { - let stateDiable = row.state === 'in_progress' ? 'disabled': ''; - let stateClass = row.state === 'in_progress' ? '': 'btn-primary'; - return ``} + { + data: 'id', orderable: false, render: (data, type, row) => { + let stateDiable = row.state === 'in_progress' ? 'disabled' : ''; + let stateClass = row.state === 'in_progress' ? '' : 'btn-primary'; + let artist_name = row.name; + return `` + } } ], }); diff --git a/php/src/resources/views/pages/main.blade.php b/php/src/resources/views/pages/main.blade.php index 2b05690..fbbb0c0 100644 --- a/php/src/resources/views/pages/main.blade.php +++ b/php/src/resources/views/pages/main.blade.php @@ -30,8 +30,8 @@ - - Download +{{-- --}} + Search
diff --git a/php/src/routes/web.php b/php/src/routes/web.php index 9e75bca..38cf179 100644 --- a/php/src/routes/web.php +++ b/php/src/routes/web.php @@ -11,3 +11,4 @@ Route::get('/', function () { Route::get('/artist/{artist}', [SearchController::class, 'search_artist'])->name('api.search.artist'); Route::get('api/artists/', [ApiController::class, 'get_artists'])->name('api.artist'); +Route::get('api/artists/queue/{id}', [ApiController::class, 'queue_artist'])->name('api.artist.queue');