diff --git a/docker-compose.yml b/docker-compose.yml index d9eb815..36110cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,6 @@ services: - "9000:9000" volumes: - ./php/src:/var/www/html:delegated - - ./shared:/var/ networks: - laravel @@ -49,9 +48,8 @@ services: ports: - "5000:5000" volumes: - - ./python:/code:Z + - ./python:/python:Z - ./php/src:/var/www/html:delegated - - ./shared:/var/ depends_on: - redis networks: @@ -143,36 +141,36 @@ services: - 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 + - SE_NODE_MAX_SESSIONS=15 + - SE_NODE_MAX_SESSION=15 - 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 +# 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 diff --git a/php/src/app/Http/Controllers/ApiController.php b/php/src/app/Http/Controllers/ApiController.php index 6d306fe..12e8088 100644 --- a/php/src/app/Http/Controllers/ApiController.php +++ b/php/src/app/Http/Controllers/ApiController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\AlbumQueue; use App\Models\Artist; use App\Models\WebDriver; use App\Models\WebScraper; @@ -29,11 +30,35 @@ class ApiController extends Controller return $response; } + public function get_album_queue() + { + $album_queue = AlbumQueue::where('state', '!=', 'done')->get(); + $response = array(); + foreach ($album_queue as $queue) { + $album = $queue->album; + $artist = $album->artist; + $response[] = [ + 'name' => $album->name, + 'artist_id' => $artist->toArray(), + 'url_remote' => $album->url_remote, + 'thumbnail' => $album->thumbnail, + 'image' => $album->image, + 'state' => $queue->state, + ]; + } + return json_encode($response); + } + public function queue_artist($id, ArtistQueue $artistQueue): bool { return $artistQueue->enqueue($id); } + public function queue_artist_run() + { + Artisan::queue('app:process-artist-queue'); + } + public function search_artist(string $artist) { $url = 'https://music.youtube.com/search?q=' . str_replace(' ', '+', $artist); @@ -52,4 +77,48 @@ class ApiController extends Controller return response()->json($response); } + public function queue_waiting() + { + $queue = AlbumQueue::where('state', 'pending')->first(); + $album = $queue->album; + $artist = $album->artist; + + \Log::info('======================'); + \Log::info('Queue running for album: ' . $album->name); + $queue->state = 'in_progress'; + $queue->save(); + $data = array('queue' => $queue->toArray(), 'album' => $album->toArray(), 'artist' => $artist->toArray()); + return json_encode($data); + } + + public function queue_update(Request $request, $id) + { + $queue = AlbumQueue::where('id', $id)->first(); + $album = $queue->album; + $artist = $album->artist; + + if ($queue->exists()) { + + if (isset($request['album']) || isset($request['artist'])) { + $album_local_url = $request['album']['url_local'] ?? ''; + $artist_local_url = $request['artist']['url_local'] ?? ''; + + if ($album_local_url || $artist_local_url) { + if ($artist_local_url && is_string($artist_local_url)) { + $artist->url_local = $artist_local_url; + $artist->save(); + } + if ($album_local_url && is_string($album_local_url)) { + $album->url_local = $album_local_url; + $album->save(); + } + $queue->state = 'done'; + $queue->save(); + } + + } + } + + } + } diff --git a/php/src/app/Models/Album.php b/php/src/app/Models/Album.php index d661afe..8591325 100644 --- a/php/src/app/Models/Album.php +++ b/php/src/app/Models/Album.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Mockery\Exception; class Album extends Model @@ -13,7 +14,7 @@ class Album extends Model public function change_state(string $state) { $available_states = array("pending", "in_progress", "done"); - if (!in_array($state, $available_states)){ + if (!in_array($state, $available_states)) { throw new Exception('Invalid state'); } $this->state = $state; @@ -51,4 +52,9 @@ class Album extends Model return $album; } + public function artist(): BelongsTo + { + return $this->belongsTo(Artist::class); + } + } diff --git a/php/src/app/Models/AlbumQueue.php b/php/src/app/Models/AlbumQueue.php index 0d69687..e972dc3 100644 --- a/php/src/app/Models/AlbumQueue.php +++ b/php/src/app/Models/AlbumQueue.php @@ -21,8 +21,9 @@ class AlbumQueue extends Model return $result; } - public function process_album() + public function album() { - // Either python pings to process the queue or laravel will send the data to python for processing + return $this->belongsTo(Album::class); } + } diff --git a/php/src/config/app.php b/php/src/config/app.php index f467267..072a8cb 100644 --- a/php/src/config/app.php +++ b/php/src/config/app.php @@ -39,7 +39,7 @@ return [ | */ - 'debug' => (bool) env('APP_DEBUG', false), + 'debug' => (bool)env('APP_DEBUG', false), /* |-------------------------------------------------------------------------- diff --git a/php/src/public/js/app.js b/php/src/public/js/app.js index 200ede9..094d6d2 100644 --- a/php/src/public/js/app.js +++ b/php/src/public/js/app.js @@ -3,6 +3,15 @@ const appModal = $('#modalDownloadQueue'); const loader = $("#loader-wrapper"); let ArtistTable = {}; // Initialized for ajax reload +function requestQueue() { + $.ajax({ + url: '/api/queue/albums', + success: (response) => { + Alpine.store('app').Queue = JSON.parse(response); + } + }) +} + function template_artist_result(element) { return `
@@ -120,15 +129,10 @@ function bind_action_buttons() { document.addEventListener('alpine:init', () => { console.log('Alpine:init'); Alpine.store('app', { - init() { - // TODO: Poll for artists and queue - this.Queue = []; - }, - Queue: [], // Rendered in the 'Queue' modal - }); - + requestQueue(); + setInterval(requestQueue, 5000); $("#loader-wrapper").fadeOut(900); }); diff --git a/php/src/resources/views/components/download-queue.blade.php b/php/src/resources/views/components/download-queue.blade.php index d7512da..fa9fadc 100644 --- a/php/src/resources/views/components/download-queue.blade.php +++ b/php/src/resources/views/components/download-queue.blade.php @@ -11,13 +11,13 @@
-