From 3c11270d4e4749d39e79c1bbe88e95eaf22a75ca Mon Sep 17 00:00:00 2001 From: Brett Spaulding Date: Wed, 4 Sep 2024 11:52:07 -0400 Subject: [PATCH] [FIX] php: YT CDN to local files Very shotty chance at getting the images from the cdn for some reason. --- docker-compose.yml | 4 +- .../app/Http/Controllers/ApiController.php | 6 +-- php/src/app/Models/Album.php | 5 ++ php/src/app/Models/Artist.php | 5 ++ php/src/app/Models/WebScraper.php | 4 +- php/src/public/js/app.js | 53 +++++++++---------- .../views/components/download-queue.blade.php | 2 +- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 27ba439..27fddf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -141,8 +141,8 @@ services: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 - - SE_NODE_MAX_SESSIONS=1 - - SE_NODE_MAX_SESSION=1 + - SE_NODE_MAX_SESSIONS=2 + - SE_NODE_MAX_SESSION=2 # edge: # image: selenium/node-edge:nightly diff --git a/php/src/app/Http/Controllers/ApiController.php b/php/src/app/Http/Controllers/ApiController.php index f32304d..1e66c4a 100644 --- a/php/src/app/Http/Controllers/ApiController.php +++ b/php/src/app/Http/Controllers/ApiController.php @@ -24,7 +24,7 @@ class ApiController extends Controller 'name' => $artist->name, 'url_remote' => $artist->url_remote, 'state' => $artist->state, - 'thumbnail' => $artist->thumbnail, + 'thumbnail' => str_replace('/var/www/html/public', '', $artist->image), ]; } $response = json_encode(array('data' => $data)); @@ -43,8 +43,8 @@ class ApiController extends Controller 'name' => $album->name, 'artist_id' => $artist->toArray(), 'url_remote' => $album->url_remote, - 'thumbnail' => $album->thumbnail, - 'image' => $album->image, + 'thumbnail' => str_replace('/var/www/html/public', '', $album->image), + 'image' => str_replace('/var/www/html/public', '', $album->image), 'state' => $queue->state, ]; } diff --git a/php/src/app/Models/Album.php b/php/src/app/Models/Album.php index 89dfc62..4d31f83 100644 --- a/php/src/app/Models/Album.php +++ b/php/src/app/Models/Album.php @@ -21,6 +21,11 @@ class Album extends Model $this->save(); } + public function getAlbumImageLocation() + { + return str_replace('/var/www/html', '', $this->image); + } + public static function findByArtistTitle(Artist $artist, string $name) { return self::where('name', '=', $name)->where('artist_id', '=', $artist->id)->first(); diff --git a/php/src/app/Models/Artist.php b/php/src/app/Models/Artist.php index 329f408..b3b9cd7 100644 --- a/php/src/app/Models/Artist.php +++ b/php/src/app/Models/Artist.php @@ -30,6 +30,11 @@ class Artist extends Model return self::where('id', '=', $id)->get(); } + public function getArtistImageLocation() + { + return str_replace('/var/www/html', '', $this->image); + } + public static function addArtist(string $name, string $thumbnail, string $url_remote, string $image) { $artist = new Artist(); diff --git a/php/src/app/Models/WebScraper.php b/php/src/app/Models/WebScraper.php index 481a8ff..9e79045 100644 --- a/php/src/app/Models/WebScraper.php +++ b/php/src/app/Models/WebScraper.php @@ -117,7 +117,7 @@ class WebScraper 'name' => $albumTitle, 'artist_id' => $artist->id, 'thumbnail' => $albumThumbnail, - 'url_remote' => $albumHref, + 'url_remote' => $albumHref, // TODO: Check here if the image is a 'gif' and not a URL 'image' => $imageFileUrl, ]; $album_id = Album::findOrCreateByName($artist, $albumTitle, $data); @@ -167,8 +167,6 @@ class WebScraper for ($i = 0; $i <= 3; $i++) { if ($caroselNextButton[0]->isEnabled()) { $action = $driver->action(); - $script = "arguments[0].scrollIntoView();"; - $driver->executeScript($script, $caroselNextButton); $action->moveToElement($caroselNextButton[0])->click()->perform(); sleep(5); } diff --git a/php/src/public/js/app.js b/php/src/public/js/app.js index 30e0663..bcdab7a 100644 --- a/php/src/public/js/app.js +++ b/php/src/public/js/app.js @@ -13,12 +13,14 @@ function requestQueue() { } function template_artist_result(element) { + let image_src = element.image.replace('/var/www/html/public', ''); + console.log(image_src); return `
- +

${element.name}

@@ -88,39 +90,32 @@ function bind_action_buttons() { }); $('#download_btn').on('click', () => { - loader.fadeIn(300); let artist = $('#search_bar').val(); // Send request to server setTimeout(() => { - if (artist) { - console.log('Sending search request...'); - $.ajax({ - url: `/artist/${artist}`, - success: (response) => { - console.log('Receiving response...'); - console.log(response); - console.log('==========='); - icon = 'success'; - let html = construct_artist_result_html(response); - proc_notification(icon, 'Shazam!', html); - ArtistTable.ajax.reload(); - $('#search_bar').val(''); - loader.fadeOut(700); - }, - error: (response) => { - console.log('Receiving response...'); - console.log(response); - console.log('==========='); - proc_notification(icon, 'What the flip?!', response.statusText); - loader.fadeOut(700); - } - }); - - } else { - proc_notification(icon, 'Whoopsie!', 'You need to add an artist, c\'mon man!'); - loader.fadeOut(700); + + if (artist == '') { + return proc_notification('error', 'Whoopsie!', 'You need to add an artist, c\'mon man!');; } + + loader.fadeIn(300); + + $.ajax({ + url: `/artist/${artist}`, + success: (response) => { + let html = construct_artist_result_html(response); + proc_notification('success', 'Shazam!', html); + ArtistTable.ajax.reload(); + $('#search_bar').val(''); + loader.fadeOut(700); + }, + error: (response) => { + proc_notification('error', 'What the flip?!', response.statusText); + loader.fadeOut(700); + } + }); + }, 10); }); diff --git a/php/src/resources/views/components/download-queue.blade.php b/php/src/resources/views/components/download-queue.blade.php index fa9fadc..dfb7a79 100644 --- a/php/src/resources/views/components/download-queue.blade.php +++ b/php/src/resources/views/components/download-queue.blade.php @@ -17,7 +17,7 @@
-