} $artist = new Artist($artist_id); $songs = $artist->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 'playlist': $playlist_id = Random::playlist(); if (!$playlist_id) { $results['rfc3514'] = '0x1'; break; } $playlist = new Playlist($playlist_id); $items = $playlist->get_items(); foreach ($items as $item) { $GLOBALS['user']->playlist->add_object($item['object_id'], $item['object_type']); } $results['rightbar'] = UI::ajax_include('rightbar.inc.php'); break; case 'advanced_random': $object_ids = Random::advanced('song', $_POST); // First add them to the active playlist if (is_array($object_ids)) { foreach ($object_ids as $object_id) { $GLOBALS['user']->playlist->add_object($object_id, 'song'); } } $results['rightbar'] = UI::ajax_include('rightbar.inc.php'); // Now setup the browse and show them below!
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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/>. * */ define('AJAX_INCLUDE', '1'); require_once '../lib/init.php'; debug_event('refresh_reordered.server.php', 'Called for action: {' . $_REQUEST['action'] . '}', '5'); /* Switch on the action passed in */ switch ($_REQUEST['action']) { case 'refresh_playlist_medias': $playlist = new Playlist($_REQUEST['id']); $playlist->format(); $object_ids = $playlist->get_items(); $browse = new Browse(); $browse->set_type('playlist_media'); $browse->add_supplemental_object('playlist', $playlist->id); $browse->set_static_content(true); $browse->show_objects($object_ids); $browse->store(); break; case 'refresh_album_songs': $browse = new Browse(); $browse->set_show_header(true); $browse->set_type('song'); $browse->set_simple_browse(true); $browse->set_filter('album', $_REQUEST['id']); $browse->set_sort('track', 'ASC'); $browse->get_objects();
/** * playlist_songs * This returns the songs for a playlist */ public static function playlist_songs($input) { $playlist = new Playlist($input['filter']); $items = $playlist->get_items(); $songs = array(); foreach ($items as $object) { if ($object['object_type'] == 'song') { $songs[] = $object['object_id']; } } // end foreach XML_Data::set_offset($input['offset']); XML_Data::set_limit($input['limit']); ob_end_clean(); echo XML_Data::songs($songs); }
public static function setPlayQueue(SimpleXMLElement $xml, $type, $playlistID, $uri, $key, $shuffle) { $GLOBALS['user']->playlist->clear(); $id = 0; if (!empty($key)) { $id = self::getKeyFromMetadataUri($key); } elseif (!empty($uri)) { $key = self::getKeyFromFullUri($uri); $id = self::getKeyFromMetadataUri($key); } $plmedias = array(); if ($id) { if ($type == 'audio' || $type == 'video') { $item = self::createLibraryItem($id); if ($item != null) { $plmedias = $item->get_medias(); } } } else { // Add complete playlist if (self::isPlaylist($playlistID)) { $playlist = new Playlist(self::getAmpacheId($playlistID)); if ($shuffle) { $plmedias = $playlist->get_random_items(); } else { $plmedias = $playlist->get_items(); } } } $GLOBALS['user']->playlist->add_medias($plmedias); self::setTmpPlayQueue($xml, 1); }
/** * databases */ public static function databases($input) { // $revision = $_GET['revision-number']; $o = ''; // Database list if (count($input) == 0) { self::check_session('daap.serverdatabases'); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $o .= self::tlv('dmap.specifiedtotalcount', 1); $o .= self::tlv('dmap.returnedcount', 1); $r = self::tlv('dmap.itemid', 1); $r .= self::tlv('dmap.persistentid', 1); $r .= self::tlv('dmap.itemname', 'Ampache'); $counts = Catalog::count_medias(); $r .= self::tlv('dmap.itemcount', $counts['songs']); $r .= self::tlv('dmap.containercount', count(Playlist::get_playlists())); $r = self::tlv('dmap.listingitem', $r); $o .= self::tlv('dmap.listing', $r); $o = self::tlv('daap.serverdatabases', $o); } elseif (count($input) == 2) { if ($input[1] == 'items') { // Songs list self::check_session('daap.databasesongs'); $o = self::catalog_songs(); $o = self::tlv('daap.databasesongs', $o); } elseif ($input[1] == 'containers') { // Playlist list self::check_session('daap.databaseplaylists'); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $playlists = Playlist::get_playlists(); $searches = Search::get_searches(); $o .= self::tlv('dmap.specifiedtotalcount', count($playlists) + count($searches) + 1); $o .= self::tlv('dmap.returnedcount', count($playlists) + count($searches) + 1); $l = self::base_library(); foreach ($playlists as $playlist_id) { $playlist = new Playlist($playlist_id); $playlist->format(); $l .= self::tlv_playlist($playlist); } foreach ($searches as $search_id) { $playlist = new Search($search_id, 'song'); $playlist->format(); $l .= self::tlv_playlist($playlist); } $o .= self::tlv('dmap.listing', $l); $o = self::tlv('daap.databaseplaylists', $o); } } elseif (count($input) == 3) { // Stream if ($input[1] == 'items') { $finfo = explode('.', $input[2]); if (count($finfo) == 2) { $id = intval($finfo[0]); $type = $finfo[1]; $params = ''; $headers = apache_request_headers(); $client = $headers['User-Agent']; if (!empty($client)) { $params .= '&client=' . $client; } $params .= '&transcode_to=' . $type; $url = Song::play_url($id, $params, 'api', true); self::follow_stream($url); exit; } } } elseif (count($input) == 4) { // Playlist if ($input[1] == 'containers' && $input[3] == 'items') { $id = intval($input[2]); self::check_session('daap.playlistsongs'); if ($id == Daap_Api::BASE_LIBRARY) { $o = self::catalog_songs(); $o = self::tlv('daap.playlistsongs', $o); } else { if ($id > Daap_Api::AMPACHEID_SMARTPL) { $id -= Daap_Api::AMPACHEID_SMARTPL; $playlist = new Search($id, 'song'); } else { $playlist = new Playlist($id); } if ($playlist->id) { $meta = explode(',', strtolower($_GET['meta'])); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.updatetype', 0); $items = $playlist->get_items(); $song_ids = array(); foreach ($items as $item) { if ($item['object_type'] == 'song') { $song_ids[] = $item['object_id']; } } if (AmpConfig::get('memory_cache')) { Song::build_cache($song_ids); } $songs = array(); foreach ($song_ids as $song_id) { $songs[] = new Song($song_id); } $o .= self::tlv('dmap.specifiedtotalcount', count($songs)); $o .= self::tlv('dmap.returnedcount', count($songs)); $o .= self::tlv('dmap.listing', self::tlv_songs($songs, $meta)); $o = self::tlv('daap.playlistsongs', $o); } else { self::createApiError('daap.playlistsongs', 500, 'Invalid playlist id: ' . $id); } } } } self::apiOutput($o); }
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); }