/** * constructor */ public function __construct($id = null, $searchtype = 'song') { $this->searchtype = $searchtype; if ($id) { $info = $this->get_info($id); foreach ($info as $key => $value) { $this->{$key} = $value; } $this->rules = unserialize($this->rules); } // Define our basetypes $this->basetypes['numeric'][] = array('name' => 'gte', 'description' => T_('is greater than or equal to'), 'sql' => '>='); $this->basetypes['numeric'][] = array('name' => 'lte', 'description' => T_('is less than or equal to'), 'sql' => '<='); $this->basetypes['numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>'); $this->basetypes['numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>'); $this->basetypes['numeric'][] = array('name' => 'gt', 'description' => T_('is greater than'), 'sql' => '>'); $this->basetypes['numeric'][] = array('name' => 'lt', 'description' => T_('is less than'), 'sql' => '<'); $this->basetypes['boolean'][] = array('name' => 'true', 'description' => T_('is true')); $this->basetypes['boolean'][] = array('name' => 'false', 'description' => T_('is false')); $this->basetypes['text'][] = array('name' => 'contain', 'description' => T_('contains'), 'sql' => 'LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%')); $this->basetypes['text'][] = array('name' => 'notcontain', 'description' => T_('does not contain'), 'sql' => 'NOT LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%')); $this->basetypes['text'][] = array('name' => 'start', 'description' => T_('starts with'), 'sql' => 'LIKE', 'preg_match' => '/$/', 'preg_replace' => '%'); $this->basetypes['text'][] = array('name' => 'end', 'description' => T_('ends with'), 'sql' => 'LIKE', 'preg_match' => '/^/', 'preg_replace' => '%'); $this->basetypes['text'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '='); $this->basetypes['text'][] = array('name' => 'sounds', 'description' => T_('sounds like'), 'sql' => 'SOUNDS LIKE'); $this->basetypes['text'][] = array('name' => 'notsounds', 'description' => T_('does not sound like'), 'sql' => 'NOT SOUNDS LIKE'); $this->basetypes['boolean_numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>'); $this->basetypes['boolean_numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>'); $this->basetypes['boolean_subsearch'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => ''); $this->basetypes['boolean_subsearch'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => 'NOT'); $this->basetypes['date'][] = array('name' => 'lt', 'description' => T_('before'), 'sql' => '<'); $this->basetypes['date'][] = array('name' => 'gt', 'description' => T_('after'), 'sql' => '>'); $this->basetypes['multiple'] = array_merge($this->basetypes['text'], $this->basetypes['numeric']); switch ($searchtype) { case 'song': $this->types[] = array('name' => 'anywhere', 'label' => T_('Any searchable text'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'album', 'label' => T_('Album'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'composer', 'label' => T_('Composer'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'comment', 'label' => T_('Comment'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'label', 'label' => T_('Label'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'album_tag', 'label' => T_('Album tag'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'file', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'time', 'label' => T_('Length (in minutes)'), 'type' => 'numeric', 'widget' => array('input', 'text')); if (AmpConfig::get('ratings')) { $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars'))); } if (AmpConfig::get('show_played_times')) { $this->types[] = array('name' => 'played_times', 'label' => T_('# Played'), 'type' => 'numeric', 'widget' => array('input', 'text')); } $this->types[] = array('name' => 'bitrate', 'label' => T_('Bitrate'), 'type' => 'numeric', 'widget' => array('select', array('32', '40', '48', '56', '64', '80', '96', '112', '128', '160', '192', '224', '256', '320'))); $this->types[] = array('name' => 'played', 'label' => T_('Played'), 'type' => 'boolean', 'widget' => array('input', 'hidden')); $this->types[] = array('name' => 'added', 'label' => T_('Added'), 'type' => 'date', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'updated', 'label' => T_('Updated'), 'type' => 'date', 'widget' => array('input', 'text')); $catalogs = array(); foreach (Catalog::get_catalogs() as $catid) { $catalog = Catalog::create_from_id($catid); $catalog->format(); $catalogs[$catid] = $catalog->f_name; } $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs)); $playlists = array(); foreach (Playlist::get_playlists() as $playlistid) { $playlist = new Playlist($playlistid); $playlist->format(); $playlists[$playlistid] = $playlist->f_name; } $this->types[] = array('name' => 'playlist', 'label' => T_('Playlist'), 'type' => 'boolean_numeric', 'widget' => array('select', $playlists)); $this->types[] = array('name' => 'playlist_name', 'label' => T_('Playlist Name'), 'type' => 'text', 'widget' => array('input', 'text')); $playlists = array(); foreach (Search::get_searches() as $playlistid) { // Slightly different from the above so we don't instigate // a vicious loop. $playlists[$playlistid] = Search::get_name_byid($playlistid); } $this->types[] = array('name' => 'smartplaylist', 'label' => T_('Smart Playlist'), 'type' => 'boolean_subsearch', 'widget' => array('select', $playlists)); $metadataFields = array(); $metadataFieldRepository = new \Lib\Metadata\Repository\MetadataField(); foreach ($metadataFieldRepository->findAll() as $metadata) { $metadataFields[$metadata->getId()] = $metadata->getName(); } $this->types[] = array('name' => 'metadata', 'label' => T_('Metadata'), 'type' => 'multiple', 'subtypes' => $metadataFields, 'widget' => array('subtypes', array('input', 'text'))); $licenses = array(); foreach (License::get_licenses() as $license_id) { $license = new License($license_id); $licenses[$license_id] = $license->name; } if (AmpConfig::get('licensing')) { $this->types[] = array('name' => 'license', 'label' => T_('Music License'), 'type' => 'boolean_numeric', 'widget' => array('select', $licenses)); } break; case 'album': $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'image width', 'label' => T_('Image Width'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'image height', 'label' => T_('Image Height'), 'type' => 'numeric', 'widget' => array('input', 'text')); if (AmpConfig::get('ratings')) { $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars'))); } $catalogs = array(); foreach (Catalog::get_catalogs() as $catid) { $catalog = Catalog::create_from_id($catid); $catalog->format(); $catalogs[$catid] = $catalog->f_name; } $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs)); $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'video': $this->types[] = array('name' => 'filename', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'artist': $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'yearformed', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'placeformed', 'label' => T_('Place'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'playlist': $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'label': $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text')); $this->types[] = array('name' => 'category', 'label' => T_('Category'), 'type' => 'text', 'widget' => array('input', 'text')); break; case 'user': $this->types[] = array('name' => 'username', 'label' => T_('Username'), 'type' => 'text', 'widget' => array('input', 'text')); break; } // end switch on searchtype }
public static function library_metadata($params) { $r = Plex_XML_Data::createLibContainer(); $n = count($params); $litem = null; $createMode = $_SERVER['REQUEST_METHOD'] == 'POST'; $editMode = $_SERVER['REQUEST_METHOD'] == 'PUT'; if ($n > 0) { $key = $params[0]; $id = Plex_XML_Data::getAmpacheId($key); if ($editMode) { self::check_access(50); } if ($n == 1) { // Should we check that files still exists here? $checkFiles = $_REQUEST['checkFiles']; $extra = $_REQUEST['includeExtra']; if (Plex_XML_Data::isArtist($key)) { $litem = new Artist($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name', 'summary' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addArtist($r, $litem); } elseif (Plex_XML_Data::isAlbum($key)) { $litem = new Album($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name', 'year' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addAlbum($r, $litem); } elseif (Plex_XML_Data::isTrack($key)) { $litem = new Song($id); $litem->format(); if ($editMode) { $dmap = array('title' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addSong($r, $litem); } elseif (Plex_XML_Data::isTVShow($key)) { $litem = new TVShow($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name', 'year' => null, 'summary' => null); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addTVShow($r, $litem); } elseif (Plex_XML_Data::isTVShowSeason($key)) { $litem = new TVShow_Season($id); $litem->format(); Plex_XML_Data::addTVShowSeason($r, $litem); } elseif (Plex_XML_Data::isVideo($key)) { $litem = Video::create_from_id($id); if ($editMode) { $dmap = array('title' => null, 'year' => null, 'originallyAvailableAt' => 'release_date', 'originalTitle' => 'original_name', 'summary' => null); $litem->update(self::get_data_from_map($dmap)); } $litem->format(); $subtype = strtolower(get_class($litem)); if ($subtype == 'tvshow_episode') { Plex_XML_Data::addEpisode($r, $litem, true); } elseif ($subtype == 'movie') { Plex_XML_Data::addMovie($r, $litem, true); } } elseif (Plex_XML_Data::isPlaylist($key)) { $litem = new Playlist($id); $litem->format(); if ($editMode) { $dmap = array('title' => 'name'); $litem->update(self::get_data_from_map($dmap)); } Plex_XML_Data::addPlaylist($r, $litem); } } else { $subact = $params[1]; if ($subact == "children") { if (Plex_XML_Data::isArtist($key)) { $litem = new Artist($id); $litem->format(); Plex_XML_Data::setArtistRoot($r, $litem); } else { if (Plex_XML_Data::isAlbum($key)) { $litem = new Album($id); $litem->format(); Plex_XML_Data::setAlbumRoot($r, $litem); } else { if (Plex_XML_Data::isTVShow($key)) { $litem = new TVShow($id); $litem->format(); Plex_XML_Data::setTVShowRoot($r, $litem); } else { if (Plex_XML_Data::isTVShowSeason($key)) { $litem = new TVShow_Season($id); $litem->format(); Plex_XML_Data::setTVShowSeasonRoot($r, $litem); } } } } } elseif ($subact == "thumbs" || $subact == "posters" || $subact == "arts" || $subact == 'backgrounds') { $kind = Plex_XML_Data::getPhotoKind($subact); if ($createMode) { // Upload art $litem = Plex_XML_Data::createLibraryItem($key); if ($litem != null) { $uri = Plex_XML_Data::getMetadataUri($key) . '/' . Plex_XML_Data::getPhotoPlexKind($kind) . '/' . $key; if (is_a($litem, 'video')) { $type = 'video'; } else { $type = get_class($litem); } $art = new Art($litem->id, $type, $kind); $raw = file_get_contents("php://input"); $art->insert($raw); header('Content-Type: text/html'); echo $uri; exit; } } Plex_XML_Data::addPhotos($r, $key, $kind); } elseif ($subact == "thumb" || $subact == "poster" || $subact == "art" || $subact == "background") { if ($n == 3) { $kind = Plex_XML_Data::getPhotoKind($subact); // Ignore art id as we can only have 1 thumb $art = null; if (Plex_XML_Data::isArtist($key)) { $art = new Art($id, "artist", $kind); } else { if (Plex_XML_Data::isAlbum($key)) { $art = new Art($id, "album", $kind); } else { if (Plex_XML_Data::isTrack($key)) { $art = new Art($id, "song", $kind); } else { if (Plex_XML_Data::isTVShow($key)) { $art = new Art($id, "tvshow", $kind); } else { if (Plex_XML_Data::isTVShowSeason($key)) { $art = new Art($id, "tvshow_season", $kind); } else { if (Plex_XML_Data::isVideo($key)) { $art = new Art($id, "video", $kind); } } } } } } if ($art != null) { $art->get_db(); ob_clean(); if (!isset($size)) { self::setHeader($art->raw_mime); echo $art->raw; } else { $dim = array(); $dim['width'] = $size; $dim['height'] = $size; $thumb = $art->get_thumb($dim); self::setHeader($art->thumb_mime); echo $thumb['thumb']; } exit; } } } } } if ($litem != null) { $catalog_ids = $litem->get_catalogs(); if (count($catalog_ids) > 0) { $catalog = Catalog::create_from_id($catalog_ids[0]); Plex_XML_Data::addCatalogIdentity($r, $catalog); } } Plex_XML_Data::setContainerSize($r); self::apiOutputXml($r->asXML()); }
<form method="post" id="edit_channel_<?php echo $libitem->id; ?> " class="edit_dialog_content"> <table class="tabledata" cellspacing="0" cellpadding="0"> <tr> <td class="edit_dialog_content_header"><?php echo T_('Stream Source'); ?> </td> <td><select name="object_id" autofocus> <?php $playlists = Playlist::get_playlists(); foreach ($playlists as $playlist_id) { $playlist = new Playlist($playlist_id); $playlist->format(); echo "<option value='" . $playlist->id . "'"; if ($playlist->id == $libitem->object_id) { echo " selected"; } echo ">" . $playlist->f_name . "</option>"; } ?> </select></td> </tr> <tr> <td class="edit_dialog_content_header"><?php echo T_('Name'); ?> </td> <td><input type="text" name="name" value="<?php
} ?> <?php } ?> <th class="cel_action essential"><?php echo T_('Actions'); ?> </th> </tr> </thead> <tbody> <?php foreach ($object_ids as $playlist_id) { $libitem = new Playlist($playlist_id); $libitem->format(); ?> <tr class="<?php echo UI::flip_class(); ?> " id="playlist_row_<?php echo $libitem->id; ?> "> <?php require AmpConfig::get('prefix') . '/templates/show_playlist_row.inc.php'; ?> </tr> <?php } // end foreach ($playlists as $playlist)
$song->format(false); $results[] = array('type' => T_('Songs'), 'link' => $song->link, 'label' => $song->f_title_full, 'value' => $song->f_title_full, 'rels' => $song->f_artist_full, 'image' => Art::url($song->album, 'album', null, 10)); } } if ($target == 'anywhere' || $target == 'playlist_name') { $searchreq = array('limit' => $limit, 'type' => 'playlist', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'name'); $sres = Search::run($searchreq); // Litmit not reach, new search with another operator if (count($sres) < $limit) { $searchreq['limit'] = $limit - count($sres); $searchreq['rule_1_operator'] = '0'; $sres = array_unique(array_merge($sres, Search::run($searchreq))); } foreach ($sres as $id) { $playlist = new Playlist($id); $playlist->format(false); $results[] = array('type' => T_('Playlists'), 'link' => $playlist->link, 'label' => $playlist->name, 'value' => $playlist->name, 'rels' => '', 'image' => ''); } } if (($target == 'anywhere' || $target == 'label') && AmpConfig::get('label')) { $searchreq = array('limit' => $limit, 'type' => 'label', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'name'); $sres = Search::run($searchreq); // Litmit not reach, new search with another operator if (count($sres) < $limit) { $searchreq['limit'] = $limit - count($sres); $searchreq['rule_1_operator'] = '0'; $sres = array_unique(array_merge($sres, Search::run($searchreq))); } foreach ($sres as $id) { $label = new Label($id); $label->format(false);
public function get_target_object() { $object = null; if ($this->object_type == 'playlist') { $object = new Playlist($this->object_id); $object->format(); } return $object; }
public static function setPlaylists(SimpleXMLElement $xml) { $playlists = Playlist::get_playlists(); foreach ($playlists as $playlist_id) { $playlist = new Playlist($playlist_id); $playlist->format(); self::addPlaylist($xml, $playlist); } }
/** * 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); }
/** * playlists * * This takes an array of playlist ids and then returns a nice pretty XML document * * @param array $playlists (description here...) * @return string return xml */ public static function playlists($playlists) { if (count($playlists) > self::$limit or self::$offset > 0) { $playlists = array_slice($playlists, self::$offset, self::$limit); } $string = ''; // Foreach the playlist ids foreach ($playlists as $playlist_id) { $playlist = new Playlist($playlist_id); $playlist->format(); $item_total = $playlist->get_song_count(); // Build this element $string .= "<playlist id=\"{$playlist->id}\">\n" . "\t<name><![CDATA[{$playlist->name}]]></name>\n" . "\t<owner><![CDATA[{$playlist->f_user}]]></owner>\n" . "\t<items>{$item_total}</items>\n" . "\t<type>{$playlist->type}</type>\n" . "</playlist>\n"; } // end foreach // Build the final and then send her off $final = self::_header() . $string . self::_footer(); return $final; }