Example #1
0
 /**
  * getSimilarSongs
  * Returns a random collection of songs from the given artist and similar artists, using data from last.fm. Typically used for artist radio features.
  * Takes song/album/artist id in parameter with optional similar songs count.
  */
 public static function getsimilarsongs($input)
 {
     $id = self::check_parameter($input, 'id');
     $count = $input['count'] ?: 50;
     $songs = null;
     if (Subsonic_XML_Data::isArtist($id)) {
         // TODO: support similar songs for artists
     } elseif (Subsonic_XML_Data::isAlbum($id)) {
         // TODO: support similar songs for albums
     } elseif (Subsonic_XML_Data::isSong($id)) {
         if (AmpConfig::get('show_similar')) {
             $songs = Recommendation::get_songs_like(Subsonic_XML_Data::getAmpacheId($id));
         }
     }
     if ($songs === null) {
         $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
     } else {
         $r = Subsonic_XML_Data::createSuccessResponse();
         Subsonic_XML_Data::addSimilarSongs($r, $songs);
     }
     self::apiOutput($input, $r);
 }
Example #2
0
 private static function _setStar($input, $star)
 {
     $id = $input['id'];
     $albumId = $input['albumId'];
     $artistId = $input['artistId'];
     // Normalize all in one array
     $ids = array();
     $r = Subsonic_XML_Data::createSuccessResponse();
     if ($id) {
         if (!is_array($id)) {
             $id = array($id);
         }
         foreach ($id as $i) {
             $aid = Subsonic_XML_Data::getAmpacheId($i);
             if (Subsonic_XML_Data::isArtist($i)) {
                 $type = 'artist';
             } else {
                 if (Subsonic_XML_Data::isAlbum($i)) {
                     $type = 'album';
                 } else {
                     if (Subsonic_XML_Data::isSong($i)) {
                         $type = 'song';
                     } else {
                         $type = "";
                     }
                 }
             }
             $ids[] = array('id' => $aid, 'type' => $type);
         }
     } else {
         if ($albumId) {
             if (!is_array($albumId)) {
                 $albumId = array($albumId);
             }
             foreach ($albumId as $i) {
                 $aid = Subsonic_XML_Data::getAmpacheId($i);
                 $ids[] = array('id' => $aid, 'album');
             }
         } else {
             if ($artistId) {
                 if (!is_array($artistId)) {
                     $artistId = array($artistId);
                 }
                 foreach ($artistId as $i) {
                     $aid = Subsonic_XML_Data::getAmpacheId($i);
                     $ids[] = array('id' => $aid, 'artist');
                 }
             } else {
                 $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_MISSINGPARAM);
             }
         }
     }
     foreach ($ids as $i) {
         $flag = new Userflag($i['id'], $i['type']);
         $flag->set_flag($star);
     }
     self::apiOutput($input, $r);
 }