Beispiel #1
0
 /**
  * gather_lastfm
  * This returns the art from lastfm. It doesn't currently require an
  * account but may in the future.
  * @param int $limit
  * @param array $data
  * @return array
  */
 public function gather_lastfm($limit = 5, $data = array())
 {
     if (!$limit) {
         $limit = 5;
     }
     $images = array();
     if ($this->type != 'album' || empty($data['artist']) || empty($data['album'])) {
         return $images;
     }
     try {
         $xmldata = Recommendation::album_search($data['artist'], $data['album']);
         if (!count($xmldata)) {
             return array();
         }
         $xalbum = $xmldata->album;
         if (!$xalbum) {
             return array();
         }
         $coverart = (array) $xalbum->image;
         if (!$coverart) {
             return array();
         }
         ksort($coverart);
         foreach ($coverart as $url) {
             // We need to check the URL for the /noimage/ stuff
             if (is_array($url) || strpos($url, '/noimage/') !== false) {
                 debug_event('LastFM', 'Detected as noimage, skipped ' . $url, 3);
                 continue;
             }
             // HACK: we shouldn't rely on the extension to determine file type
             $results = pathinfo($url);
             $mime = 'image/' . $results['extension'];
             $images[] = array('url' => $url, 'mime' => $mime, 'title' => 'LastFM');
             if ($limit && count($images) >= $limit) {
                 return $images;
             }
         }
         // end foreach
     } catch (Exception $e) {
         debug_event('art', 'LastFM error: ' . $e->getMessage(), 5);
     }
     return $images;
 }