[IMP] Extra handling for missing link case

main
Brett Spaulding 1 year ago
parent ec39ea48be
commit dce3b47372

@ -28,10 +28,10 @@ class ProcessArtistQueue extends Command
public function handle() public function handle()
{ {
// This queue will prompt the scraping of all artist albums, mark done when complete // This queue will prompt the scraping of all artist albums, mark done when complete
$artists = ArtistQueue::where('state', 'pending')->get(); $artist_queue = ArtistQueue::where('state', 'pending')->get();
$bar = new ProgressBar($this->output, count($artists)); $bar = new ProgressBar($this->output, count($artist_queue));
$bar->start(); $bar->start();
foreach ($artists as $artist) { foreach ($artist_queue as $artist) {
$artist->state = 'in_progress'; $artist->state = 'in_progress';
$artist->save(); $artist->save();
$artist->process_artist(); $artist->process_artist();

@ -2,7 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\Artisan; use App\Jobs\RunArtistQueue;
use App\Models\AlbumQueue; use App\Models\AlbumQueue;
use App\Models\Artist; use App\Models\Artist;
use App\Models\WebDriver; use App\Models\WebDriver;
@ -38,14 +38,16 @@ class ApiController extends Controller
foreach ($album_queue as $queue) { foreach ($album_queue as $queue) {
$album = $queue->album; $album = $queue->album;
$artist = $album->artist; $artist = $album->artist;
$response[] = [ if ($album && $artist) {
'name' => $album->name, $response[] = [
'artist_id' => $artist->toArray(), 'name' => $album->name,
'url_remote' => $album->url_remote, 'artist_id' => $artist->toArray(),
'thumbnail' => $album->thumbnail, 'url_remote' => $album->url_remote,
'image' => $album->image, 'thumbnail' => $album->thumbnail,
'state' => $queue->state, 'image' => $album->image,
]; 'state' => $queue->state,
];
}
} }
return json_encode($response); return json_encode($response);
} }
@ -59,7 +61,7 @@ class ApiController extends Controller
{ {
\Log::info('==========================='); \Log::info('===========================');
\Log::info('Queue running for Artists..'); \Log::info('Queue running for Artists..');
Artisan::queue('app:process-artist-queue'); ArtistQueue::run_queue();
} }
public function search_artist(string $artist) public function search_artist(string $artist)

@ -9,18 +9,24 @@ class AlbumQueue extends Model
{ {
use HasFactory; use HasFactory;
public function enqueue($album_id): bool public function enqueue($album): bool
{ {
$result = false; $result = false;
$album_queued = AlbumQueue::where('album_id', $album_id->id)->first(); $album_queued = AlbumQueue::where('album_id', $album->id)->first();
if (is_null($album_queued) && $album_id->state === 'pending') { if (is_null($album_queued) && $album->state === 'pending') {
$this->album_id = $album_id->id; $this->album_id = $album->id;
$this->save(); $this->save();
$result = true; $result = true;
} }
return $result; return $result;
} }
public static function addQueue($album_id): bool
{
$queue = new AlbumQueue();
$queue->enqueue($album_id);
}
public function album() public function album()
{ {
return $this->belongsTo(Album::class); return $this->belongsTo(Album::class);

@ -51,5 +51,16 @@ class ArtistQueue extends Model
} }
} }
public static function run_queue()
{
// This queue will prompt the scraping of all artist albums, mark done when complete
$artist_queue = ArtistQueue::where('state', 'pending')->get();
foreach ($artist_queue as $queue) {
$queue->state = 'in_progress';
$queue->save();
$queue->process_artist();
$queue->state = 'done';
$queue->save();
}
}
} }

@ -5,6 +5,7 @@ namespace App\Models;
use App\Utils\ImageUrl; use App\Utils\ImageUrl;
use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverAction;
use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\WebDriverExpectedCondition;
class WebScraper class WebScraper
@ -120,8 +121,7 @@ class WebScraper
'image' => $imageFileUrl, 'image' => $imageFileUrl,
]; ];
$album_id = Album::findOrCreateByName($artist, $albumTitle, $data); $album_id = Album::findOrCreateByName($artist, $albumTitle, $data);
$album_queue = new AlbumQueue(); AlbumQueue::addQueue($album_id);
$album_queue->enqueue($album_id);
} }
/** /**
@ -153,13 +153,27 @@ class WebScraper
} }
} else { } else {
\Log::info('Could not locate Albums button'); \Log::info('Could not locate Albums button');
$ytRows = $driver->findElements(WebDriverBy::cssSelector('ytmusic-carousel-shelf-renderer')); $ytRows = $driver->findElements(WebDriverBy::cssSelector('ytmusic-carousel-shelf-renderer'));
foreach ($ytRows as $ytRow) { foreach ($ytRows as $ytRow) {
$contentGroup = $ytRow->findElements(WebDriverBy::cssSelector('#content-group')); $contentGroup = $ytRow->findElements(WebDriverBy::cssSelector('#content-group'));
foreach ($contentGroup as $group) { foreach ($contentGroup as $group) {
$groupName = $group->getText(); $groupName = $group->getText();
if ($groupName == 'Albums') { if ($groupName == 'Albums') {
// Sometimes we don't have the option to click the albums button to filter
// Yet, the albums are in a carousel and the images won't load unless they are in view
$caroselNextButton = $driver->findElements(WebDriverBy::cssSelector('#next-items-button'));
if ($caroselNextButton) {
// Youtube is smart enough to block this without an action
for ($i = 0; $i <= 3; $i++) {
if ($caroselNextButton[0]->isEnabled()) {
$action = $driver->action();
$action->moveToElement($caroselNextButton[0])->click()->perform();
sleep(1);
}
}
}
$itemsContainer = $ytRow->findElements(WebDriverBy::cssSelector('#items')); $itemsContainer = $ytRow->findElements(WebDriverBy::cssSelector('#items'));
foreach ($itemsContainer as $item) { foreach ($itemsContainer as $item) {
$albumContainers = $item->findElements(WebDriverBy::cssSelector('ytmusic-two-row-item-renderer')); $albumContainers = $item->findElements(WebDriverBy::cssSelector('ytmusic-two-row-item-renderer'));

@ -64,7 +64,7 @@ function artist_queue_toggle(element) {
url: `/api/queue/artist/${self.data('artist_id')}`, url: `/api/queue/artist/${self.data('artist_id')}`,
success: () => { success: () => {
proc_notification('success', 'Queued Download', `Artist ${artist_name} Queued for Download!`); proc_notification('success', 'Queued Download', `Artist ${artist_name} Queued for Download!`);
ArtistTable.ajax.reload(); // ArtistTable.ajax.reload();
}, },
error: (response) => { error: (response) => {
console.log(response); console.log(response);

@ -13,7 +13,7 @@
<div id="modal_content"> <div id="modal_content">
<div class="card"> <div class="card">
<table id="artistsCatalogDatatable"> <table id="artistsCatalogDatatable" class="stripe">
<thead> <thead>
<tr> <tr>
<th></th> <th></th>

Loading…
Cancel
Save