parent
bab2a7bdcc
commit
9385a382ae
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AlbumQueue extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function enqueue()
|
||||
{
|
||||
// Add albums to queue for download
|
||||
}
|
||||
|
||||
public function process_queue()
|
||||
{
|
||||
// Either python pings to process the queue or laravel will send the data to python for processing
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
|
||||
class ImageUrl
|
||||
{
|
||||
|
||||
/**
|
||||
* Modify the width and height values in a Google Image URL.
|
||||
*
|
||||
* @param string $url The original URL.
|
||||
* @return string The modified URL with new width and height values.
|
||||
*/
|
||||
public static function modifyGoogleImageUrl(string $url, int $size = 1024): string
|
||||
{
|
||||
// Regular expression pattern to match width and height values in the URL
|
||||
$pattern = '/w(\\d+)-h(\\d+)/';
|
||||
|
||||
// Use preg_replace_callback() to replace the matched values with the provided integer
|
||||
return preg_replace_callback($pattern, function ($matches) use ($size) {
|
||||
return "w{$size}-h{$size}";
|
||||
}, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an image from a Google Image URL to the local filesystem.
|
||||
*
|
||||
* @param string $url The modified URL of the image to download.
|
||||
* @return string The path to the saved image file, or empty string if the file already exists.
|
||||
*/
|
||||
public static function save_img_url(string $url): string
|
||||
{
|
||||
// Get the filename from the URL
|
||||
$filename = basename($url);
|
||||
|
||||
// Create a directory for the images (if it doesn't exist)
|
||||
$imagesDir = public_path('images/artist');
|
||||
if (!is_dir($imagesDir)) {
|
||||
mkdir($imagesDir, 0777, true);
|
||||
}
|
||||
|
||||
// Check if the file already exists
|
||||
$imagePath = $imagesDir . '/' . $filename . '.jpg';
|
||||
if (file_exists($imagePath)) {
|
||||
return ''; // File already exists, don't save again
|
||||
}
|
||||
|
||||
// Download the image from the URL using curl
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($ch);
|
||||
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($statusCode !== 200) {
|
||||
// Handle HTTP error (e.g. file not found)
|
||||
return '';
|
||||
}
|
||||
|
||||
// Save the image to disk
|
||||
file_put_contents($imagePath, $response);
|
||||
|
||||
return $imagePath;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('album_queues', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
$table->foreignId('album_id')->nullable()->constrained('albums');
|
||||
$table->enum('state', [
|
||||
'pending',
|
||||
'in_progress',
|
||||
'done',
|
||||
])->default('pending');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('album_queues');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in new issue