[WIP] php: webdriver working

refactor_total
Brett Spaulding 1 year ago
parent 641a2f7009
commit 564c841cb1

@ -131,3 +131,57 @@ services:
- "8025:8025" - "8025:8025"
networks: networks:
- laravel - 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"

@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\WebDriverBy;
class SearchController extends Controller
{
protected function setUp() {
$host = 'http://selenium-hub:4444';
$capabilities = DesiredCapabilities::chrome();
$chromeOptions = new ChromeOptions();
$chromeOptions->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();
}
}

@ -8,7 +8,8 @@
"php": "^8.2", "php": "^8.2",
"laravel/dusk": "^8.2", "laravel/dusk": "^8.2",
"laravel/framework": "^11.9", "laravel/framework": "^11.9",
"laravel/tinker": "^2.9" "laravel/tinker": "^2.9",
"php-webdriver/webdriver": "^1.15"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "70513a468ff8b3a827290330aa43a225", "content-hash": "4181bb8487bb70037bc7fa4670618f39",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",

@ -1,3 +1,4 @@
console.log('Version 1:20:2');
const appModal = $('#modalDownloadQueue'); const appModal = $('#modalDownloadQueue');
const loader = $("#loader-wrapper"); const loader = $("#loader-wrapper");
@ -18,6 +19,9 @@ $('#queue_btn').on('click', () => {
}) })
$('#download_btn').on('click', () => { $('#download_btn').on('click', () => {
console.log('Blocking UI');
loader.fadeIn(300);
let artist = $('#search_bar').val(); let artist = $('#search_bar').val();
// Prevent // Prevent
$('#search_bar').val(''); $('#search_bar').val('');
@ -25,21 +29,35 @@ $('#download_btn').on('click', () => {
let title = 'What the flip?!'; let title = 'What the flip?!';
let text = 'You need to add an artist bro..'; let text = 'You need to add an artist bro..';
if (artist) { setTimeout(() => {
$("#loader-wrapper").fadeIn(300); if (artist) {
$.ajax({ console.log('Sending search request...');
url: `/api/v1/get/artist/${artist}`, $.ajax({
async: false, url: `/artist/${artist}`,
}).done(function (res) { success: (response) => {
text = res.message; console.log('Receiving response...');
if (res.status === 200) { console.log(response);
icon = 'success'; console.log('===========');
title = 'Shazam!'; icon = 'success';
} title = 'Shazam!';
}); proc_notification(icon, title, text);
} loader.fadeOut(700);
loader().fadeOut(700); },
proc_notification(icon, title, text); 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', () => { document.addEventListener('alpine:init', () => {

@ -1,7 +1,10 @@
<?php <?php
use App\Http\Controllers\SearchController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/', function () { Route::get('/', function () {
return view('pages.main'); return view('pages.main');
}); });
Route::get('/artist/{artist}', [SearchController::class, 'search_artist']);

Loading…
Cancel
Save