[IMP] php: Command update for album covers

refactor_total
Brett Spaulding 1 year ago
parent 45abbc823f
commit 6af3f45af5

@ -0,0 +1,46 @@
<?php
namespace App\Console\Commands;
use App\Models\Album;
use App\Utils\ImageUrl;
use Illuminate\Console\Command;
use Symfony\Component\Console\Helper\ProgressBar;
class UpdateAlbumImages extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:update-album-images';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
$albums = Album::all();
$bar = new ProgressBar($this->output, count($albums));
$bar->start();
foreach ($albums as $album) {
$image_url = ImageUrl::modifyGoogleImageUrl($album->thumbnail);
$image_file = ImageUrl::save_img_url($image_url, 'album');
echo '-------------------';
echo $image_url . '\n';
echo $image_file . '\n';
echo '-------------------';
$album->image = $image_file;
$album->save();
$bar->advance();
}
}
}

@ -33,7 +33,7 @@ class UpdateArtistImages extends Command
$bar->start();
foreach ($artists as $artist) {
$image_url = ImageUrl::modifyGoogleImageUrl($artist->thumbnail);
$image_file = ImageUrl::save_img_url($image_url);
$image_file = ImageUrl::save_img_url($image_url, 'artist');
$artist->image = $image_file;
$artist->save();
$bar->advance();

@ -45,7 +45,7 @@ class Album extends Model
public static function findOrCreateByName($artist_id, string $name, array $data = [])
{
$album = self::findByArtistTitle($artist_id, $name);
if ($album->exists() && $data) {
if (is_null($album) && $data) {
$album = self::addAlbum($data['name'], $data['thumbnail'], $data['url_remote'], $data['image'], $data['artist_id']);
}
return $album;

@ -106,11 +106,12 @@ class WebScraper
*
* @return RemoteWebDriver
*/
public static function scrapeAlbums($driver, $artist_id): array
public static function scrapeAlbums($driver, $artist_id)
{
$url = 'https://music.youtube.com/' . $artist_id->url_remote;
$driver->get($url);
$response = 0;
try {
$albumBtn = $driver->findElement(WebDriverBy::xpath('//a[text()="Albums"]'));
if ($albumBtn) {
$albumBtn->click();
@ -145,6 +146,11 @@ class WebScraper
}
}
}
} catch (\Exception $e) {
\Log::warning('Failed to scrape albums: ---------');
\Log::warning($e->getMessage());
}
return $response;
}
}

@ -45,7 +45,7 @@ class ImageUrl
// Check if the file already exists
$imagePath = $imagesDir . '/' . $filename . '.jpg';
if (file_exists($imagePath)) {
return ''; // File already exists, don't save again
return $imagePath; // File already exists, don't save again
}
// Download the image from the URL using curl

@ -1,6 +1,7 @@
console.log('Version 1:20:2');
const appModal = $('#modalDownloadQueue');
const loader = $("#loader-wrapper");
let ArtistTable = {}; // Initialized for ajax reload
function template_artist_result(element) {
return `
@ -48,14 +49,13 @@ function proc_notification(icon, title, 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/queue/artist/${self.data('artist_id')}`,
success: () => {
proc_notification('success', 'Queued Download', `Artist ${artist_name} Queued for Download!`);
ArtistTable.ajax.reload();
},
error: (response) => {
console.log(response);
@ -95,6 +95,7 @@ function bind_action_buttons() {
icon = 'success';
let html = construct_artist_result_html(response);
proc_notification(icon, 'Shazam!', html);
ArtistTable.ajax.reload();
$('#search_bar').val('');
loader.fadeOut(700);
},
@ -133,11 +134,9 @@ document.addEventListener('alpine:init', () => {
});
$(document).ready(function () {
bind_action_buttons();
//Datatable for 'Catalog' menu
let ArtistTable = $('#artistsCatalogDatatable').DataTable({
ArtistTable = $('#artistsCatalogDatatable').DataTable({
ajax: '/api/artists',
type: 'get',
dataType: 'json',
@ -164,9 +163,4 @@ $(document).ready(function () {
}
],
});
// Polling for table update
const getArtistTableInterval = setInterval(function () {
ArtistTable.ajax.reload();
}, 5000);
});

Loading…
Cancel
Save