[FIX] php: Another edge case for album info

main
Brett Spaulding 1 year ago
parent 1eba36d32b
commit 5de3803c55

@ -59,8 +59,6 @@ class ApiController extends Controller
public function queue_artist_run() public function queue_artist_run()
{ {
\Log::info('===========================');
\Log::info('Queue running for Artists..');
ArtistQueue::run_queue(); ArtistQueue::run_queue();
} }
@ -84,8 +82,6 @@ class ApiController extends Controller
public function queue_waiting() public function queue_waiting()
{ {
\Log::info('===========================');
\Log::info('Queue running for Albums..');
$data = array('queue' => false); $data = array('queue' => false);
$queue = AlbumQueue::where('state', 'pending')->first(); $queue = AlbumQueue::where('state', 'pending')->first();
if (!is_null($queue)) { if (!is_null($queue)) {

@ -135,11 +135,10 @@ class WebScraper
$url = 'https://music.youtube.com/' . $artist_id->url_remote; $url = 'https://music.youtube.com/' . $artist_id->url_remote;
$driver->get($url); $driver->get($url);
$response = 0; $response = 0;
sleep(3);
try { try {
\Log::info('Looking for Albums button..');
$albumBtn = $driver->findElements(WebDriverBy::xpath('//a[text()="Albums"]')); $albumBtn = $driver->findElements(WebDriverBy::xpath('//a[text()="Albums"]'));
if ($albumBtn) { if ($albumBtn) {
\Log::info('Clicking on located Albums button..');
$albumBtn[0]->click(); $albumBtn[0]->click();
sleep(5); sleep(5);
$itemsContainer = $driver->findElements(WebDriverBy::cssSelector('#items')); $itemsContainer = $driver->findElements(WebDriverBy::cssSelector('#items'));
@ -153,26 +152,31 @@ class WebScraper
} }
} }
} else { } else {
\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 // 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 // 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')); $caroselNextButton = $driver->findElements(WebDriverBy::cssSelector('#next-items-button'));
if ($caroselNextButton) { try {
// Youtube is smart enough to block this without an action if ($caroselNextButton) {
for ($i = 0; $i <= 3; $i++) { // Youtube is smart enough to block this without an action
if ($caroselNextButton[0]->isEnabled()) { for ($i = 0; $i <= 3; $i++) {
$action = $driver->action(); if ($caroselNextButton[0]->isEnabled()) {
$action->moveToElement($caroselNextButton[0])->click()->perform(); $action = $driver->action();
sleep(5); $script = "arguments[0].scrollIntoView();";
$driver->executeScript($script, $caroselNextButton);
$action->moveToElement($caroselNextButton[0])->click()->perform();
sleep(5);
}
sleep(2);
} }
} }
} catch (\Exception $e) {
\Log::info($e);
} }
$itemsContainer = $ytRow->findElements(WebDriverBy::cssSelector('#items')); $itemsContainer = $ytRow->findElements(WebDriverBy::cssSelector('#items'));
@ -186,9 +190,7 @@ class WebScraper
} }
} }
} }
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
\Log::warning('Failed to scrape albums: ---------'); \Log::warning('Failed to scrape albums: ---------');

Loading…
Cancel
Save