Example #1
0
 /**
  * getAlbumList
  * Get a list of random, newest, highest rated etc. albums.
  * Takes the list type with optional size and offset in parameters.
  */
 public static function getalbumlist($input, $elementName = "albumList")
 {
     self::check_version($input, "1.2.0");
     $type = self::check_parameter($input, 'type');
     $size = $input['size'];
     $offset = $input['offset'];
     $musicFolderId = $input['musicFolderId'] ?: 0;
     // Get albums from all catalogs by default
     // Catalog filter is not supported for all request type for now.
     $catalogs = null;
     if ($musicFolderId > 0) {
         $catalogs = array();
         $catalogs[] = $musicFolderId;
     }
     $r = Subsonic_XML_Data::createSuccessResponse();
     $errorOccured = false;
     $albums = array();
     if ($type == "random") {
         $albums = Album::get_random($size);
     } else {
         if ($type == "newest") {
             $albums = Stats::get_newest("album", $size, $offset, $musicFolderId);
         } else {
             if ($type == "highest") {
                 $albums = Rating::get_highest("album", $size, $offset);
             } else {
                 if ($type == "frequent") {
                     $albums = Stats::get_top("album", $size, '', $offset);
                 } else {
                     if ($type == "recent") {
                         $albums = Stats::get_recent("album", $size, $offset);
                     } else {
                         if ($type == "starred") {
                             $albums = Userflag::get_latest('album');
                         } else {
                             if ($type == "alphabeticalByName") {
                                 $albums = Catalog::get_albums($size, $offset, $catalogs);
                             } else {
                                 if ($type == "alphabeticalByArtist") {
                                     $albums = Catalog::get_albums_by_artist($size, $offset, $catalogs);
                                 } else {
                                     if ($type == "byYear") {
                                         $fromYear = $input['fromYear'];
                                         $toYear = $input['toYear'];
                                         if ($fromYear || $toYear) {
                                             $search = array();
                                             $search['limit'] = $size;
                                             $search['offset'] = $offset;
                                             $search['type'] = "album";
                                             $i = 0;
                                             if ($fromYear) {
                                                 $search['rule_' . $i . '_input'] = $fromYear;
                                                 $search['rule_' . $i . '_operator'] = 0;
                                                 $search['rule_' . $i . ''] = "year";
                                                 ++$i;
                                             }
                                             if ($toYear) {
                                                 $search['rule_' . $i . '_input'] = $toYear;
                                                 $search['rule_' . $i . '_operator'] = 1;
                                                 $search['rule_' . $i . ''] = "year";
                                                 ++$i;
                                             }
                                             $query = new Search(null, 'album');
                                             $albums = $query->run($search);
                                         }
                                     } else {
                                         if ($type == "byGenre") {
                                             $genre = self::check_parameter($input, 'genre');
                                             $tag_id = Tag::tag_exists($genre);
                                             if ($tag_id) {
                                                 $albums = Tag::get_tag_objects('album', $tag_id, $size, $offset);
                                             }
                                         } else {
                                             $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_GENERIC, "Invalid list type: " . scrub_out($type));
                                             $errorOccured = true;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!$errorOccured) {
         Subsonic_XML_Data::addAlbumList($r, $albums, $elementName);
     }
     self::apiOutput($input, $r);
 }
Example #2
0
}
$results = array();
switch ($_REQUEST['action']) {
    case 'song':
        $songs = Random::get_default();
        if (!count($songs)) {
            $results['rfc3514'] = '0x1';
            break;
        }
        foreach ($songs as $song_id) {
            $GLOBALS['user']->playlist->add_object($song_id, 'song');
        }
        $results['rightbar'] = UI::ajax_include('rightbar.inc.php');
        break;
    case 'album':
        $album_id = Album::get_random();
        if (!$album_id) {
            $results['rfc3514'] = '0x1';
            break;
        }
        $album = new Album($album_id[0]);
        $songs = $album->get_songs();
        foreach ($songs as $song_id) {
            $GLOBALS['user']->playlist->add_object($song_id, 'song');
        }
        $results['rightbar'] = UI::ajax_include('rightbar.inc.php');
        break;
    case 'artist':
        $artist_id = Random::artist();
        if (!$artist_id) {
            $results['rfc3514'] = '0x1';
Example #3
0
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
/**
 * Sub-Ajax page, requires AJAX_INCLUDE
 */
if (!defined('AJAX_INCLUDE')) {
    exit;
}
$results = array();
switch ($_REQUEST['action']) {
    case 'random_albums':
        $albums = Album::get_random(6);
        if (count($albums) and is_array($albums)) {
            ob_start();
            require_once AmpConfig::get('prefix') . UI::find_template('show_random_albums.inc.php');
            $results['random_selection'] = ob_get_clean();
        } else {
            $results['random_selection'] = '<!-- None found -->';
            if (Access::check('interface', '100')) {
                $catalogs = Catalog::get_catalogs();
                if (count($catalogs) == 0) {
                    $results['random_selection'] = sprintf(T_('No catalog configured yet. To start streaming your media, you now need to %s add a catalog %s'), '<a href="' . AmpConfig::get('web_path') . '/admin/catalog.php?action=show_add_catalog">', '</a>.<br /><br />');
                }
            }
        }
        break;
    case 'random_videos':
Example #4
0
 public static function stats($input)
 {
     $type = $input['type'];
     $offset = $input['offset'];
     $limit = $input['limit'];
     if ($type == "newest") {
         $albums = Stats::get_newest("album", $limit, $offset);
     } else {
         if ($type == "highest") {
             $albums = Rating::get_highest("album", $limit, $offset);
         } else {
             if ($type == "frequent") {
                 $albums = Stats::get_top("album", $limit, '', $offset);
             } else {
                 if ($type == "recent") {
                     $albums = Stats::get_recent("album", $limit, $offset);
                 } else {
                     if ($type == "flagged") {
                         $albums = Userflag::get_latest('album');
                     } else {
                         if (!$limit) {
                             $limit = AmpConfig::get('popular_threshold');
                         }
                         $albums = Album::get_random($limit);
                     }
                 }
             }
         }
     }
     ob_end_clean();
     echo XML_Data::albums($albums);
 }
Example #5
0
 /**
  * getAlbumList
  * Get a list of random, newest, highest rated etc. albums.
  * Takes the list type with optional size and offset in parameters.
  */
 public static function getalbumlist($input, $elementName = "albumList")
 {
     self::check_version($input, "1.2.0");
     $type = self::check_parameter($input, 'type');
     $size = $input['size'];
     $offset = $input['offset'];
     $albums = array();
     if ($type == "random") {
         $albums = Album::get_random($size);
     } else {
         if ($type == "newest") {
             $albums = Stats::get_newest("album", $size, $offset);
         } else {
             if ($type == "highest") {
                 $albums = Rating::get_highest("album", $size, $offset);
             } else {
                 if ($type == "frequent") {
                     $albums = Stats::get_top("album", $size, '', $offset);
                 } else {
                     if ($type == "recent") {
                         $albums = Stats::get_recent("album", $size, $offset);
                     } else {
                         if ($type == "starred") {
                             $albums = Userflag::get_latest('album');
                         } else {
                             if ($type == "alphabeticalByName") {
                                 $albums = Catalog::get_albums($size, $offset);
                             } else {
                                 if ($type == "alphabeticalByArtist") {
                                     $albums = Catalog::get_albums_by_artist($size, $offset);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($albums)) {
         $r = Subsonic_XML_Data::createSuccessResponse();
         Subsonic_XML_Data::addAlbumList($r, $albums, $elementName);
     } else {
         $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
     }
     self::apiOutput($input, $r);
 }
Example #6
0
 /**
  * This get library stats.
  * @param array $input
  */
 public static function stats($input)
 {
     $type = $input['type'];
     $offset = $input['offset'];
     $limit = $input['limit'];
     $username = $input['username'];
     $albums = null;
     if ($type == "newest") {
         $albums = Stats::get_newest("album", $limit, $offset);
     } else {
         if ($type == "highest") {
             $albums = Rating::get_highest("album", $limit, $offset);
         } else {
             if ($type == "frequent") {
                 $albums = Stats::get_top("album", $limit, '', $offset);
             } else {
                 if ($type == "recent") {
                     if (!empty($username)) {
                         $user = User::get_from_username($username);
                         if ($user !== null) {
                             $albums = $user->get_recently_played($limit, 'album');
                         } else {
                             debug_event('api', 'User `' . $username . '` cannot be found.', 1);
                         }
                     } else {
                         $albums = Stats::get_recent("album", $limit, $offset);
                     }
                 } else {
                     if ($type == "flagged") {
                         $albums = Userflag::get_latest('album');
                     } else {
                         if (!$limit) {
                             $limit = AmpConfig::get('popular_threshold');
                         }
                         $albums = Album::get_random($limit);
                     }
                 }
             }
         }
     }
     if ($albums !== null) {
         ob_end_clean();
         echo XML_Data::albums($albums);
     }
 }
Example #7
0
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
/**
 * Sub-Ajax page, requires AJAX_INCLUDE
 */
if (!defined('AJAX_INCLUDE')) {
    exit;
}
$results = array();
switch ($_REQUEST['action']) {
    case 'random_albums':
        $albums = Album::get_random(6, true);
        if (count($albums) and is_array($albums)) {
            ob_start();
            require_once AmpConfig::get('prefix') . '/templates/show_random_albums.inc.php';
            $results['random_selection'] = ob_get_clean();
        } else {
            $results['random_selection'] = '<!-- None found -->';
        }
        break;
    case 'artist_info':
        if (AmpConfig::get('lastfm_api_key') && (isset($_REQUEST['artist']) || isset($_REQUEST['fullname']))) {
            if ($_REQUEST['artist']) {
                $artist = new Artist($_REQUEST['artist']);
                $artist->format();
                $biography = Recommendation::get_artist_info($artist->id);
            } else {