function testAddAndRemovePlaylist() { // Create a playlist $playlist = new Playlist(); $playlist->create("Scheduler Unit Test " . uniqid()); $result = $playlist->addAudioClip($this->storedFile->getId()); $result = $playlist->addAudioClip($this->storedFile2->getId()); $result = $playlist->addAudioClip($this->storedFile2->getId()); $i = new ScheduleGroup(); $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId()); if (PEAR::isError($this->groupIdCreated)) { $this->fail("Failed to create scheduled item: " . $this->groupIdCreated->getMessage()); } $group = new ScheduleGroup($this->groupIdCreated); if ($group->count() != 3) { $this->fail("Wrong number of items added."); } $items = $group->getItems(); if (!is_array($items) || $items[1]["starts"] != "2010-11-11 01:30:34.231") { $this->fail("Wrong start time for 2nd item."); } $result = $group->remove(); if ($result != 1) { $this->fail("Did not remove item."); } Playlist::Delete($playlist->getId()); }
function setup() { global $CC_CONFIG, $CC_DBC; // Clear the files table $sql = "DELETE FROM " . $CC_CONFIG["filesTable"]; $CC_DBC->query($sql); // Add a file $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3"); $this->storedFile = StoredFile::Insert($values, false); // Add a file $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3"); $this->storedFile2 = StoredFile::Insert($values, false); // Clear the schedule table $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"]; $CC_DBC->query($sql); // Create a playlist $playlist = new Playlist(); $playlist->create("Scheduler Unit Test"); $result = $playlist->addAudioClip($this->storedFile->getId()); $result = $playlist->addAudioClip($this->storedFile2->getId()); $result = $playlist->addAudioClip($this->storedFile2->getId()); // Schedule it $i = new ScheduleGroup(); $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId()); }
public function create($request) { if (Session::isActive()) { $req = $request->getParameters(); $resp = $this->index($request); if ($req['name'] != '' && $req['channel_id'] != '') { if (UserChannel::exists($req['channel_id'])) { if (UserChannel::find($req['channel_id'])->belongToUser(Session::get()->id)) { if (!Playlist::exists(array('conditions' => array('name = ? AND channel_id = ?', $req['name'], $req['channel_id'])))) { Playlist::create(array('name' => $req['name'], 'channel_id' => $req['channel_id'], 'videos_ids' => json_encode(array()), 'timestamp' => Utils::tps())); // Oui cette ligne est dupliquée mais ce n'est pas une erreur, ne pas supprimer SVP $resp = $this->index($request); $resp->addMessage(ViewMessage::success('Playlist ajoutée avec succès !')); } else { $resp->addMessage(ViewMessage::error('Une playlist du même nom existe déjà sur cette chaîne.')); } } else { $resp->addMessage(ViewMessage::error('Cette chaîne ne vous appartient pas.')); } } else { $resp->addMessage(ViewMessage::error('Cette chaîne n\'existe pas !')); } } else { $resp->addMessage(ViewMessage::error('Merci de remplir tous les champs')); } } return $resp; }
/** * Import SMIL file to storage * * @param GreenBox $gb * reference to GreenBox object * @param string $aPath * absolute path part of imported file (e.g. /home/user/airtime) * @param string $rPath * relative path/filename part of imported file * (e.g. playlists/playlist_1.smil) * @param array $gunids * hash relation from filenames to gunids * @param string $plid * playlist gunid * @param int $subjid * local subject (user) id (id of user doing the import) * @return Playlist */ public static function &import(&$gb, $aPath, $rPath, &$gunids, $plid, $subjid = NULL) { $parr = compact('subjid', 'aPath', 'plid', 'rPath'); $path = realpath("{$aPath}/{$rPath}"); if (FALSE === $path) { return PEAR::raiseError("SmilPlaylist::import: file doesn't exist ({$aPath}/{$rPath})"); } $lspl = SmilPlaylist::convert2lspl($gb, $path, $gunids, $parr); if (PEAR::isError($lspl)) { return $lspl; } require_once "Playlist.php"; $pl =& Playlist::create($gb, $plid, "imported_SMIL"); if (PEAR::isError($pl)) { return $pl; } $r = $pl->lock($gb, $subjid); if (PEAR::isError($r)) { return $r; } $r = $pl->setMetadata($lspl, 'string', 'playlist'); if (PEAR::isError($r)) { return $r; } $r = $pl->unlock($gb); if (PEAR::isError($r)) { return $r; } return $pl; }
public function newAction() { $pl_sess = $this->pl_sess; $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $pl = new Playlist(); $pl->create("Untitled Playlist"); $pl->setPLMetaData('dc:creator', $userInfo->login); $this->changePlaylist($pl->getId()); $form = new Application_Form_PlaylistMetadata(); $this->view->fieldset = $form; $this->view->form = $this->view->render('playlist/new.phtml'); }
/** * createPlaylist * Create (or updates) a playlist. * Takes playlist id in parameter if updating, name in parameter if creating and a list of song id for the playlist. */ public static function createplaylist($input) { self::check_version($input, "1.2.0"); $playlistId = $input['playlistId']; $name = $input['name']; $songId = $input['songId']; if ($playlistId) { self::_updatePlaylist($playlistId, $name, $songId); $r = Subsonic_XML_Data::createSuccessResponse(); } else { if (!empty($name)) { $playlistId = Playlist::create($name, 'private'); if (count($songId) > 0) { self::_updatePlaylist($playlistId, "", $songId); } $r = Subsonic_XML_Data::createSuccessResponse(); } else { $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_MISSINGPARAM); } } self::apiOutput($input, $r); }
public static function playlists($params) { $r = Plex_XML_Data::createContainer(); $n = count($params); $createMode = $_SERVER['REQUEST_METHOD'] == 'POST'; $editMode = $_SERVER['REQUEST_METHOD'] == 'PUT'; $delMode = $_SERVER['REQUEST_METHOD'] == 'DELETE'; if ($createMode || $editMode || $delMode) { self::check_access(50); } if ($n <= 1) { $plid = 0; if ($n == 0 && $createMode) { // Create a new playlist //$type = $_GET['type']; $title = $_GET['title']; //$smart = $_GET['smart']; //$summary = $_GET['summary']; $uri = $_GET['uri']; $plid = Playlist::create($title, 'public'); $playlist = new Playlist($plid); $key = Plex_XML_Data::getKeyFromFullUri($uri); $id = Plex_XML_Data::getKeyFromMetadataUri($key); if ($id) { $item = Plex_XML_Data::createLibraryItem($id); $medias = $item->get_medias(); $playlist->add_medias($medias); } $plid = Plex_XML_Data::getPlaylistId($plid); } else { if ($n == 1 && $params[0] != "all") { $plid = $params[0]; } } if ($plid) { if (Plex_XML_Data::isPlaylist($plid)) { $playlist = new Playlist(Plex_XML_Data::getAmpacheId($plid)); if ($playlist->id) { if ($delMode) { // Delete playlist $playlist->delete(); } else { // Display playlist information Plex_XML_Data::addPlaylist($r, $playlist); } } } } else { // List all playlists Plex_XML_Data::setPlaylists($r); } } elseif ($n >= 2) { $plid = $params[0]; if (Plex_XML_Data::isPlaylist($plid) && $params[1] == "items") { $playlist = new Playlist(Plex_XML_Data::getAmpacheId($plid)); if ($playlist->id) { if ($n == 2) { if ($editMode) { // Add a new item to playlist $uri = $_GET['uri']; $key = Plex_XML_Data::getKeyFromFullUri($uri); $id = Plex_XML_Data::getKeyFromMetadataUri($key); if ($id) { $item = Plex_XML_Data::createLibraryItem($id); $medias = $item->get_medias(); $playlist->add_medias($medias); Plex_XML_Data::addPlaylist($r, $playlist); } } else { Plex_XML_Data::setPlaylistItems($r, $playlist); } } elseif ($n == 3) { $index = intval($params[2]); if ($delMode) { $playlist->delete_track_number($index); $playlist->regenerate_track_numbers(); exit; } } } } } Plex_XML_Data::setContainerSize($r); self::apiOutputXml($r->asXML()); }
/** * playlist_import * Attempts to create a Public Playlist based on the playlist file */ public static function import_playlist($playlist) { $data = file_get_contents($playlist); if (substr($playlist, -3, 3) == 'm3u') { $files = self::parse_m3u($data); } elseif (substr($playlist, -3, 3) == 'pls') { $files = self::parse_pls($data); } elseif (substr($playlist, -3, 3) == 'asx') { $files = self::parse_asx($data); } elseif (substr($playlist, -4, 4) == 'xspf') { $files = self::parse_xspf($data); } $songs = array(); $pinfo = pathinfo($playlist); if (isset($files)) { foreach ($files as $file) { $file = trim($file); // Check to see if it's a url from this ampache instance if (substr($file, 0, strlen(AmpConfig::get('web_path'))) == AmpConfig::get('web_path')) { $data = Stream_URL::parse($file); $sql = 'SELECT COUNT(*) FROM `song` WHERE `id` = ?'; $db_results = Dba::read($sql, array($data['id'])); if (Dba::num_rows($db_results)) { $songs[] = $data['id']; } } else { // Remove file:// prefix if any if (strpos($file, "file://") !== false) { $file = urldecode(substr($file, 7)); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // Removing starting / on Windows OS. if (substr($file, 0, 1) == '/') { $file = substr($file, 1); } // Restore real directory separator $file = str_replace("/", DIRECTORY_SEPARATOR, $file); } } debug_event('catalog', 'Add file ' . $file . ' to playlist.', '5'); // First, try to found the file as absolute path $sql = "SELECT `id` FROM `song` WHERE `file` = ?"; $db_results = Dba::read($sql, array($file)); $results = Dba::fetch_assoc($db_results); if (isset($results['id'])) { $songs[] = $results['id']; } else { // Not found in absolute path, create it from relative path $file = $pinfo['dirname'] . DIRECTORY_SEPARATOR . $file; // Normalize the file path. realpath requires the files to exists. $file = realpath($file); if ($file) { $sql = "SELECT `id` FROM `song` WHERE `file` = ?"; $db_results = Dba::read($sql, array($file)); $results = Dba::fetch_assoc($db_results); if (isset($results['id'])) { $songs[] = $results['id']; } } } } // if it's a file } } debug_event('import_playlist', "Parsed " . $playlist . ", found " . count($songs) . " songs", 5); if (count($songs)) { $name = $pinfo['extension'] . " - " . $pinfo['filename']; $playlist_id = Playlist::create($name, 'public'); if (!$playlist_id) { return array('success' => false, 'error' => T_('Failed to create playlist.')); } /* Recreate the Playlist */ $playlist = new Playlist($playlist_id); $playlist->add_songs($songs, true); return array('success' => true, 'id' => $playlist_id, 'count' => count($songs)); } return array('success' => false, 'error' => T_('No valid songs found in playlist file.')); }
header('Location: ' . AmpConfig::get('web_path') . '/browse.php?action=playlist'); exit; } } UI::show_header(); /* Switch on the action passed in */ switch ($_REQUEST['action']) { case 'create_playlist': /* Check rights */ if (!Access::check('interface', 25)) { UI::access_denied(); break; } $playlist_name = scrub_in($_REQUEST['playlist_name']); $playlist_type = scrub_in($_REQUEST['type']); $playlist_id = Playlist::create($playlist_name, $playlist_type); $_SESSION['data']['playlist_id'] = $playlist_id; show_confirmation(T_('Playlist Created'), sprintf(T_('%1$s (%2$s) has been created'), $playlist_name, $playlist_type), 'playlist.php'); break; case 'delete_playlist': // If we made it here, we didn't have sufficient rights. UI::access_denied(); break; case 'show_playlist': $playlist = new Playlist($_REQUEST['playlist_id']); $playlist->format(); $object_ids = $playlist->get_items(); require_once AmpConfig::get('prefix') . UI::find_template('show_playlist.inc.php'); break; case 'show_import_playlist': require_once AmpConfig::get('prefix') . UI::find_template('show_import_playlist.inc.php');
/** * playlist_create * This create a new playlist and return it */ public static function playlist_create($input) { $name = $input['name']; $type = $input['type']; if ($type != 'private') { $type = 'public'; } $uid = Playlist::create($name, $type); echo XML_Data::playlists(array($uid)); }
/** * Creates a new playlist and redirects to edit it */ private function newPlaylist() { Base::requireLogged(); /** * Write table in database */ $playlist = Playlist::create(); $playlist->user_id = LOGGED; $playlist->cover = Base::createIdenticon(time(), 440); $playlist->date = time(); $playlist->save(); Base::redirect('/' . $playlist->id() . '/edit'); }
$browse->add_supplemental_object('playlist', $playlist->id); $browse->save_objects($object_ids); $browse->show_objects($object_ids); $browse->store(); $results[$browse->get_content_div()] = ob_get_clean(); break; case 'append_item': // Only song item are supported with playlists debug_event('playlist', 'Appending items to playlist {' . $_REQUEST['playlist_id'] . '}...', '5'); if (!isset($_REQUEST['playlist_id']) || empty($_REQUEST['playlist_id'])) { if (!Access::check('interface', '25')) { debug_event('DENIED', 'Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist', '1'); break; } $name = $GLOBALS['user']->username . ' - ' . date("Y-m-d H:i:s", time()); $playlist_id = Playlist::create($name, 'private'); if (!$playlist_id) { break; } $playlist = new Playlist($playlist_id); } else { $playlist = new Playlist($_REQUEST['playlist_id']); } if (!$playlist->has_access()) { break; } $songs = array(); $item_id = $_REQUEST['item_id']; switch ($_REQUEST['item_type']) { case 'smartplaylist': $smartplaylist = new Search($item_id, 'song');
echo " This script schedules a playlist to play {$secondsFromNow} minute(s) from now.\n"; echo " This is a utility to help you debug the scheduler.\n"; echo " ************************************************************** \n"; echo "\n"; echo "Deleting playlists with the name '{$playlistName}'..."; // Delete any old playlists $pl2 = Playlist::findPlaylistByName($playlistName); foreach ($pl2 as $playlist) { //var_dump($playlist); $playlist->delete(); } echo "done.\n"; // Create a new playlist echo "Creating new playlist '{$playlistName}'..."; $pl = new Playlist(); $pl->create($playlistName); $mediaFile = StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3"); if (is_null($mediaFile)) { echo "Adding test audio clip to the database.\n"; $v = array("filepath" => __DIR__ . "/../../../audio_samples/vorbis.com/Hydrate-Kenny_Beltrey.ogg"); $mediaFile = StoredFile::Insert($v); if (PEAR::isError($mediaFile)) { var_dump($mediaFile); exit; } } $pl->addAudioClip($mediaFile->getId()); echo "done.\n"; //$pl2 = Playlist::findPlaylistByName("pypo_playlist_test"); //var_dump($pl2); // Get current time
$browse->add_supplemental_object('playlist', $playlist->id); $browse->save_objects($object_ids); $browse->show_objects($object_ids); $browse->store(); $results['browse_content_playlist_song'] = ob_get_clean(); break; case 'append_item': // Only song item are supported with playlists debug_event('playlist', 'Appending items to playlist {' . $_REQUEST['playlist_id'] . '}...', '5'); if (!isset($_REQUEST['playlist_id']) || empty($_REQUEST['playlist_id'])) { if (!Access::check('interface', '25')) { debug_event('DENIED', 'Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist', '1'); break; } $name = $GLOBALS['user']->username . ' - ' . date("Y-m-d H:i:s", time()); $playlist_id = Playlist::create($name, 'public'); if (!$playlist_id) { break; } $playlist = new Playlist($playlist_id); } else { $playlist = new Playlist($_REQUEST['playlist_id']); } if (!$playlist->has_access()) { break; } $songs = array(); $item_id = $_REQUEST['item_id']; switch ($_REQUEST['item_type']) { case 'smartplaylist': $smartplaylist = new Search('song', $item_id);