MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Vosbox. If not, see <http://www.gnu.org/licenses/>. Vosbox copyright Callan Bryant 2011-2012 <*****@*****.**> http://callanbryant.co.uk/ */ require_once __DIR__ . '/../../VSE/indexer.class.php'; require_once __DIR__ . '/../../audioFile.class.php'; require_once __DIR__ . '/../../VSE/keyStore.class.php'; try { if (!extension_loaded('json')) { throw new Exception('json extension not loaded'); } $store = new keyStore('playlists'); $index = indexer::getInstance(); // save a playlist from serialised IDs if (@($idsCsv = $_REQUEST['save'])) { // convert to array of IDs $ids = explode(',', $idsCsv); // check each object exists and record it $objects = array(); foreach ($ids as $id) { if ($object = $index->getObject($id)) { $objects[] = $object; } else { throw new Exception('Invalid playlist items'); } } // save the playlist (list of ids), generating an ID 10 chars
Vosbox is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Vosbox is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Vosbox. If not, see <http://www.gnu.org/licenses/>. Vosbox copyright Callan Bryant 2011-2012 <*****@*****.**> http://callanbryant.co.uk/ */ // grabs albumn art given an ID require_once __DIR__ . '/../../VSE/keyStore.class.php'; require_once __DIR__ . '/../../httpResponse.class.php'; $id =& $_REQUEST['id']; $k = new keyStore('albumArt'); $albumArt = $k->get($id); $response = new httpResponse(); $response->load_string($albumArt); $response->mimetype = httpResponse::mimetype('jpg'); if (!$albumArt) { $response->status = 404; } $response->inline = true; // the client can cache this file forever! $response->persistent = true; $response->serve();
private function assignAlbumArt() { $k = new keyStore('albumArt'); // generate a potential ID corresponding to this album/artist combination $id = md5($this->album . $this->artist); // check for existing art from the same album // if there, then assign this song that albumn ID if ($k->get($id)) { return $this->albumArtId = $id; } // get an instance of the ImageMagick class to manipulate // the album art image $im = new Imagick(); $blob = null; // look in the ID3v2 tag if (isset($this->analysis['id3v2']['APIC'][0]['data'])) { $blob =& $this->analysis['id3v2']['APIC'][0]['data']; } elseif (isset($this->analysis['id3v2']['PIC'][0]['data'])) { $blob =& $this->analysis['id3v2']['PIC'][0]['data']; } elseif ($images = glob($this->dir . '*.{jpg,png}', GLOB_BRACE)) { // use file pointers instead of file_get_contents // to fix a memory leak due to failed re-use of allocated memory // when loading successivle bigger files @($h = fopen($images[0], 'rb')); $size = filesize($images[0]); if ($h === false) { throw new Exception("Could not open cover art: {$images['0']}"); } if (!$size) { // invalid or no image //throw new Exception("Could not open cover art: $images[0]"); // assign no art return; } $blob = fread($h, $size); fclose($h); } else { // no albumn art available, assign none return; } // TODO, if necessary: try amazon web services // standardise the album art to 128x128 jpg $im->readImageBlob($blob); $im->thumbnailImage(128, 128); $im->setImageFormat('jpeg'); $im->setImageCompressionQuality(90); $blob = $im->getImageBlob(); // save the album art under the generated ID $k->set($id, $blob); // assign this song that albumn art ID $this->albumArtId = $id; }