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
 /**
  * createShare
  * Create a public url that can be used by anyone to stream media.
  * Takes the file id with optional description and expires parameters.
  */
 public static function createshare($input)
 {
     self::check_version($input, "1.6.0");
     $id = self::check_parameter($input, 'id');
     $description = $input['description'];
     $expires = $input['expires'];
     if (AmpConfig::get('share')) {
         if ($expires) {
             $expire_days = round(($expires / 1000 - time()) / 86400, 0, PHP_ROUND_HALF_EVEN);
         } else {
             $expire_days = AmpConfig::get('share_expire');
         }
         $object_id = Subsonic_XML_Data::getAmpacheId($id);
         if (Subsonic_XML_Data::isAlbum($id)) {
             $object_type = 'album';
         } else {
             if (Subsonic_XML_Data::isSong($id)) {
                 $object_type = 'song';
             }
         }
         if (!empty($object_type)) {
             $r = Subsonic_XML_Data::createSuccessResponse();
             $shares = array();
             $shares[] = Share::create_share($object_type, $object_id, true, Access::check_function('download'), $expire_days, Share::generate_secret(), 0, $description);
             Subsonic_XML_Data::addShares($r, $shares);
         } else {
             $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
         }
     } else {
         $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_UNAUTHORIZED);
     }
     self::apiOutput($input, $r);
 }