diff --git a/docker-compose.yml b/docker-compose.yml index 3882010..d9eb815 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -131,3 +131,57 @@ services: - "8025:8025" networks: - laravel + + chrome: + image: selenium/node-chrome:nightly + shm_size: 8gb + networks: + - laravel + depends_on: + - selenium-hub + environment: + - SE_EVENT_BUS_HOST=selenium-hub + - SE_EVENT_BUS_PUBLISH_PORT=4442 + - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + - SE_NODE_MAX_SESSIONS=5 + - SE_NODE_MAX_SESSION=5 + + edge: + image: selenium/node-edge:nightly + shm_size: 8gb + networks: + - laravel + depends_on: + - selenium-hub + environment: + - SE_EVENT_BUS_HOST=selenium-hub + - SE_EVENT_BUS_PUBLISH_PORT=4442 + - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + - SE_NODE_MAX_SESSIONS=5 + - SE_NODE_MAX_SESSION=5 + + firefox: + image: selenium/node-firefox:nightly + shm_size: 8gb + networks: + - laravel + depends_on: + - selenium-hub + environment: + - SE_EVENT_BUS_HOST=selenium-hub + - SE_EVENT_BUS_PUBLISH_PORT=4442 + - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + - SE_NODE_MAX_SESSIONS=5 + - SE_NODE_MAX_SESSION=5 + + selenium-hub: + image: selenium/hub:latest + networks: + - laravel + environment: + JAVA_OPTS: "-Xmx8g -Xms2g" + container_name: selenium-hub + ports: + - "4442:4442" + - "4443:4443" + - "4444:4444" diff --git a/php/src/app/Http/Controllers/SearchController.php b/php/src/app/Http/Controllers/SearchController.php new file mode 100644 index 0000000..32f530d --- /dev/null +++ b/php/src/app/Http/Controllers/SearchController.php @@ -0,0 +1,47 @@ +addArguments(['--no-sandbox', '--disable-dev-shm-usage']); + $capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions); + $driver = RemoteWebDriver::create($host, $capabilities); + $driver->manage()->window()->maximize(); + return $driver; + } + + public function search_artist(Request $request, string $artist) + { + \Log::info($artist); + \Log::info($request); + \Log::info('Getting Artist: ' . $artist); +// $url = 'https://example.com'; + $url = 'https://music.youtube.com/search?q=' . str_replace(' ', '+', $artist); + \Log::info('Search URL: ' . $url); + \Log::info('======================================='); + + // the URL to the local Selenium Server + $driver = $this->setUp(); + $driver->get($url); + $html = $driver->getPageSource(); + + \Log::info($html); + \Log::info('========================================='); + + $driver->quit(); + + } +} diff --git a/php/src/composer.json b/php/src/composer.json index 47213d3..75c3aec 100644 --- a/php/src/composer.json +++ b/php/src/composer.json @@ -8,7 +8,8 @@ "php": "^8.2", "laravel/dusk": "^8.2", "laravel/framework": "^11.9", - "laravel/tinker": "^2.9" + "laravel/tinker": "^2.9", + "php-webdriver/webdriver": "^1.15" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/php/src/composer.lock b/php/src/composer.lock index e36be83..0ab8f5b 100644 --- a/php/src/composer.lock +++ b/php/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "70513a468ff8b3a827290330aa43a225", + "content-hash": "4181bb8487bb70037bc7fa4670618f39", "packages": [ { "name": "brick/math", diff --git a/php/src/public/js/app.js b/php/src/public/js/app.js index be2d3ec..8d06134 100644 --- a/php/src/public/js/app.js +++ b/php/src/public/js/app.js @@ -1,3 +1,4 @@ +console.log('Version 1:20:2'); const appModal = $('#modalDownloadQueue'); const loader = $("#loader-wrapper"); @@ -18,6 +19,9 @@ $('#queue_btn').on('click', () => { }) $('#download_btn').on('click', () => { + console.log('Blocking UI'); + loader.fadeIn(300); + let artist = $('#search_bar').val(); // Prevent $('#search_bar').val(''); @@ -25,21 +29,35 @@ $('#download_btn').on('click', () => { let title = 'What the flip?!'; let text = 'You need to add an artist bro..'; - if (artist) { - $("#loader-wrapper").fadeIn(300); - $.ajax({ - url: `/api/v1/get/artist/${artist}`, - async: false, - }).done(function (res) { - text = res.message; - if (res.status === 200) { - icon = 'success'; - title = 'Shazam!'; - } - }); - } - loader().fadeOut(700); - proc_notification(icon, title, text); + 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'; + title = 'Shazam!'; + proc_notification(icon, title, text); + loader.fadeOut(700); + }, + error: (response) => { + console.log('Receiving response...'); + console.log(response); + console.log('==========='); + proc_notification(icon, title, response.statusText); + loader.fadeOut(700); + } + }); + + } else { + proc_notification(icon, title, text); + loader.fadeOut(700); + } + }, 100); + }) document.addEventListener('alpine:init', () => { diff --git a/php/src/routes/web.php b/php/src/routes/web.php index 2b39632..30aae15 100644 --- a/php/src/routes/web.php +++ b/php/src/routes/web.php @@ -1,7 +1,10 @@