diff --git a/plugin/BulkEmbed/search.json.php b/plugin/BulkEmbed/search.json.php index 146b6610dc24..ef1120bec3bd 100644 --- a/plugin/BulkEmbed/search.json.php +++ b/plugin/BulkEmbed/search.json.php @@ -3,14 +3,14 @@ header('Content-Type: application/json'); if (!User::isLogged()) { - die(json_encode(['error' => 'You must be logged in to search'])); + die(json_encode(['error' => true, 'msg'=>'You must be logged in to search'])); } $query = $_POST['query'] ?? ''; $pageToken = $_POST['pageToken'] ?? ''; if (empty($query)) { - die(json_encode(['error' => 'Search query cannot be empty'])); + die(json_encode(['error' => true, 'msg'=>'Search query cannot be empty'])); } $obj = AVideoPlugin::getObjectData("BulkEmbed"); @@ -23,11 +23,17 @@ $youtubeApiUrl .= "&pageToken=" . $pageToken; } -$response = file_get_contents($youtubeApiUrl); +$response = url_get_contents($youtubeApiUrl); $responseData = json_decode($response, true); if (empty($responseData) || !isset($responseData['items'])) { - die(json_encode(['error' => 'Failed to retrieve data from YouTube', $responseData])); + _error_log('Failed to retrieve data from YouTube ' . $youtubeApiUrl); + $msg = 'Failed to retrieve data from YouTube'; + if(!empty($responseData['error']) && !empty($responseData['error']['message'])){ + $msg .= '
'.$responseData['error']['message']; + } + + die(json_encode(['error' => true, 'msg'=>$msg])); } // Prepare the result array to include the embedding status diff --git a/plugin/BulkEmbed/search.php b/plugin/BulkEmbed/search.php index a06e02680feb..7c4f9209c60c 100644 --- a/plugin/BulkEmbed/search.php +++ b/plugin/BulkEmbed/search.php @@ -199,7 +199,7 @@ function search(pageToken = '') { }, success: function(response) { if (response.error) { - avideoAlertError(response.error); + avideoAlertError(response.msg); } else { processData(response.data); // Store search results globally