$artwork_list = $artwork_scanner->get_unscanned_artwork_list(); $current_album_id = 0; if (count($artwork_list) == 0) { echo "*** Songs have all been cross-checked with Amazon ***"; } foreach ($artwork_list as $key => $value) { //this album has copied art, skip to the next album if ($current_album_id == $value['album_id']) { continue; } $art_dir = dirname(__FILE__) . '/../../../data/album_art/' . md5($value['artist_name'] . $value['album_name']); echo 'Scanning: ' . $value['album_name'] . ' by: ' . $value['artist_name'] . "\r\n"; $opts = array('Artist' => $value['artist_name'], 'Creator' => $value['artist_name'], 'SearchIndex' => 'Music', 'ResponseGroup' => 'Medium'); //Sometimes Amazon returns malformed xml, so we need to catch exceptions. We'll try again on a later scan. try { $result = $associate_services->item_search($value['album_name'], $opts); } catch (Exception $e) { echo sprintf('Error: Amazon returned invalid response for %s by: %s', $value['album_name'], $value['artist_name']) . "\r\n"; continue; } //error codes - just show the error and skip if (isset($result->body->Error->Code) || !empty($result->body->Error->Code)) { //don't scan further files in this album $current_album_id = $value['album_id']; echo "Error: " . (string) $result->body->Error->Message . "\r\n"; continue; } //Mark failed search requests as skipped - product likely doesn't exist in amazon catalog if (@(string) $result->body->Items->Request->Errors->Error->Code == "AWS.ECommerceService.NoExactMatches") { //don't scan further files in this album $current_album_id = $value['album_id'];