/** * 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); }
public static function setSectionAll_Albums(SimpleXMLElement $xml, Catalog $catalog) { self::setSectionAllAttributes($xml, $catalog, 'All Albums', 'album'); $albums_ids = Catalog::get_albums(0, 0, array($catalog->id)); foreach ($albums_ids as $album_id) { $album = new Album($album_id); $album->format(); self::addAlbum($xml, $album); } }
/** * 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); }
public static function _musicChilds($prmPath, $prmQuery, $start, $count) { $mediaItems = array(); $maxCount = 0; $queryData = array(); parse_str($prmQuery, $queryData); $parent = 'amp://music' . $prmPath; $pathreq = explode('/', $prmPath); if ($pathreq[0] == '' && count($pathreq) > 0) { array_shift($pathreq); } switch ($pathreq[0]) { case 'artists': switch (count($pathreq)) { case 1: // Get artists list //$artists = Catalog::get_artists(); //list($maxCount, $artists) = self::_slice($artists, $start, $count); $artists = Catalog::get_artists(null, $count, $start); list($maxCount, $artists) = array(999999, $artists); foreach ($artists as $artist) { $artist->format(); $mediaItems[] = self::_itemArtist($artist, $parent); } break; case 2: // Get artist's albums list $artist = new Artist($pathreq[1]); if ($artist->id) { $album_ids = $artist->get_albums(); list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count); foreach ($album_ids as $album_id) { $album = new Album($album_id); $album->format(); $mediaItems[] = self::_itemAlbum($album, $parent); } } break; } break; case 'albums': switch (count($pathreq)) { case 1: // Get albums list //!!$album_ids = Catalog::get_albums(); //!!list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count); $album_ids = Catalog::get_albums($count, $start); list($maxCount, $album_ids) = array(999999, $album_ids); foreach ($album_ids as $album_id) { $album = new Album($album_id); $album->format(); $mediaItems[] = self::_itemAlbum($album, $parent); } break; case 2: // Get album's songs list $album = new Album($pathreq[1]); if ($album->id) { $song_ids = $album->get_songs(); list($maxCount, $song_ids) = self::_slice($song_ids, $start, $count); foreach ($song_ids as $song_id) { $song = new Song($song_id); $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } break; } break; case 'songs': switch (count($pathreq)) { case 1: // Get songs list $catalogs = Catalog::get_catalogs(); foreach ($catalogs as $catalog_id) { $catalog = Catalog::create_from_id($catalog_id); $songs = $catalog->get_songs(); list($maxCount, $songs) = self::_slice($songs, $start, $count); foreach ($songs as $song) { $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } break; } break; case 'playlists': switch (count($pathreq)) { case 1: // Get playlists list $pl_ids = Playlist::get_playlists(); list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count); foreach ($pl_ids as $pl_id) { $playlist = new Playlist($pl_id); $playlist->format(); $mediaItems[] = self::_itemPlaylist($playlist, $parent); } break; case 2: // Get playlist's songs list $playlist = new Playlist($pathreq[1]); if ($playlist->id) { $items = $playlist->get_items(); list($maxCount, $items) = self::_slice($items, $start, $count); foreach ($items as $item) { if ($item['object_type'] == 'song') { $song = new Song($item['object_id']); $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } } break; } break; case 'smartplaylists': switch (count($pathreq)) { case 1: // Get playlists list $pl_ids = Search::get_searches(); list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count); foreach ($pl_ids as $pl_id) { $playlist = new Search($pl_id, 'song'); $playlist->format(); $mediaItems[] = self::_itemPlaylist($playlist, $parent); } break; case 2: // Get playlist's songs list $playlist = new Search($pathreq[1], 'song'); if ($playlist->id) { $items = $playlist->get_items(); list($maxCount, $items) = self::_slice($items, $start, $count); foreach ($items as $item) { if ($item['object_type'] == 'song') { $song = new Song($item['object_id']); $song->format(); $mediaItems[] = self::_itemSong($song, $parent); } } } break; } break; default: $mediaItems[] = self::_musicMetadata('artists'); $mediaItems[] = self::_musicMetadata('albums'); $mediaItems[] = self::_musicMetadata('songs'); $mediaItems[] = self::_musicMetadata('playlists'); $mediaItems[] = self::_musicMetadata('smartplaylists'); break; } if ($maxCount == 0) { $maxCount = count($mediaItems); } return array($maxCount, $mediaItems); }