/** * Rotates an image * * @author Ross Carlson * @version 4/16/05 * @since 4/15/05 * @param $image string the FULL path to the image to rotate */ function SERVICE_ROTATE_IMAGE_gd2($image, $node) { global $allow_filesystem_modify, $include_path; // Let's make sure they have GD installed if (gd_version() < 2) { return false; } // Well since we can't rotate an ID3 image let's see if it's ID3 if (stristr($image, "ID3:")) { // Now let's make a file out of this data $jzSERVICES = new jzServices(); $jzSERVICES->loadStandardServices(); // Now let's fix the path $path = substr($image, 4); $meta = $jzSERVICES->getTagData($path); // Now let's create a file $file = $include_path . 'data/images/' . str_replace("/", "--", $path); $handle = fopen($file, "wb"); fwrite($handle, $meta['pic_data']); fclose($handle); // Now let's make this the image for the node $node->addMainArt($file); // Now let's update the name so we can rotate $image = $file; } // First we have to delete any resized versions of this $files = readDirInfo($include_path . 'data/images', "file"); foreach ($files as $file) { if (stristr($file, str_replace($include_path . 'data/images/', "", substr($image, 0, -4)))) { @unlink($file); } } // Now let's set our images $source = @imagecreatefromjpeg($image); $rotate = @imagerotate($source, 90, 0); @imagejpeg($rotate, $image); }
/** * Returns the track's metadata as an array with the following keys: * * title * bitrate * frequency * filename [excluding path] * size * year * comment * length * length_str * number * genre * artist * album * lyrics * type [extension] * * These are taken mostly from the ID3. * * @author Ben Dodson * @version 6/7/04 * @since 6/7/04 */ function getMeta($mode = "cache", $installer = false) { global $track_num_seperator, $root_dir, $web_root, $include_path, $jzSERVICES; $meta = array(); $cache = $this->readCache(); if ($mode == "cache" && $this->meta != array()) { return $this->meta; } if ($mode == "cache") { $meta['title'] = $cache[7]; $meta['bitrate'] = $cache[20]; $meta['frequency'] = $cache[8]; $meta['filename'] = $cache[2]; $meta['size'] = $cache[13]; $meta['year'] = $cache[11]; $meta['comment'] = $cache[9] == "-" ? "" : $cache[9]; $meta['length'] = $len = $cache[14]; $meta['number'] = $cache[21]; $meta['genre'] = $cache[15]; $meta['artist'] = $cache[16]; $meta['album'] = $cache[17]; $meta['lyrics'] = $cache[19] == "" || $cache[19] == "-" ? "" : $cache[19]; $meta['type'] = $cache[18]; if (isNothing($meta['type'])) { $meta = $this->getMeta("file"); $this->setMeta($meta, "cache"); } } else { // Get it from the file. // other backend functions use this to get the id3 before the file is cached. if ($mode == "direct") { $fname = $this->getPath("String"); } else { $fname = $this->getFileName("host"); } // Do our services exist? if (!$jzSERVICES) { include_once $include_path . 'services/class.php'; $jzSERVICES = new jzServices(); $jzSERVICES->loadStandardServices(); } // Let's setup our tagdata service and return the tag data $meta = $jzSERVICES->getTagData($fname, $installer); } return $meta; }
/** * The general resample/transcode function * * @author Ross Carlson, Ben Dodson * @version 05.25.05 * @since 05.25.05 * @param $file The file that we are resampling/transcoding * @param $name The name of the stream * @param $resample The rate to resample/transcode to */ function SERVICE_RESAMPLE($file, $name, $resample) { global $path_to_lame, $path_to_flac, $path_to_mpc, $path_to_wavunpack, $path_to_oggdec, $lame_cmd, $path_to_wmadec, $path_to_shn, $path_to_mplayer, $mplayer_opts, $path_to_faad, $path_to_macpipe, $path_to_ofr; $jzSERVICES = new jzServices(); $jzSERVICES->loadStandardServices(); // Now let's add the proper options to the lame command $lame_cmd .= $resample . ' -f -'; //Now let's figure out the file type $extArr = explode(".", $file); $ext = $extArr[count($extArr) - 1]; // Now if we're on Windows we need to change the slashes for the command line if (stristr($_ENV['OS'], "win")) { $file = str_replace("/", "\\", $file); } switch ($ext) { case "mp3": $meta = $jzSERVICES->getTagData($file); if ($meta['bitrate'] <= $resample) { header("Content-Type: audio/x-mp3"); streamFile($file, $meta['artist'] . $meta['title'], $resample); exit; } else { $command = $path_to_lame . " --mp3input -S --silent --quiet --lowpass 12.0 --resample 22.05 -m j -b " . $resample . ' - < "' . $file . '" -'; } break; case "flac": $command = $path_to_flac . ' -d -c --totally-silent "' . $file . '" | ' . $lame_cmd; break; case "mpc": $command = $path_to_mpc . ' --wav "' . $file . '" | ' . $lame_cmd; break; case "wv": $command = $path_to_wavunpack . ' -q "' . $file . '" - | ' . $lame_cmd; break; case "ogg": // Ok, are they using oggdec or ogg123? if (stristr($path_to_oggdec, "oggdec")) { //$command = $path_to_oggdec. ' --stdout "'. $file. '" | '. $lame_cmd; $command = $path_to_oggdec . ' -Q "' . $file . '" -o - | ' . $lame_cmd; } else { $command = $path_to_oggdec . ' --skip 1 -q -d wav -f - "' . $file . '" | ' . $lame_cmd; } break; case "wav": $command = $path_to_lame . " -S --silent --quiet --lowpass 12.0 --resample 22.05 -m j -b " . $resample . ' - < "' . $file . '" -'; break; case "shn": if (stristr($_ENV['OS'], "win")) { $command = $path_to_shn . ' -x "' . $file . '" - | ' . str_replace(" -S --silent", " -x -S --silent", $lame_cmd); } else { $command = $path_to_shn . ' -x "' . $file . '" - | ' . $lame_cmd; } break; case "wma": $command = $path_to_wmadec . ' -w "' . $file . '" | ' . $lame_cmd; break; case "ape": $command = $path_to_macpipe . ' "' . $file . '" - -d | ' . $lame_cmd; break; case "ofr": $command = $path_to_ofr . ' --decode --silent "' . $file . '" --output - | ' . str_replace(" -S --silent", " -x -S --silent", $lame_cmd); break; case "ra": case "ram": case "rm": case "m4a": if (stristr($_ENV['OS'], "win")) { $command = $path_to_faad . ' -w "' . $file . '" | ' . str_replace(" -S --silent", " -x -S --silent", $lame_cmd); } else { $command = $path_to_mplayer . ' ' . $mplayer_opts . ' "' . $file . '" | ' . $lame_cmd; } break; default: exit; break; } // Let's log the command we just passed writeLogData("resample-command", $command); // Now let's send the resampled data sendResampledFile($command, $name); exit; }
/** * Actually sends the data in the specified file. * * * @author Ben Dodson, PHP.net * @version 11/11/04 * @since 11/11/04 */ function streamFile($path, $name, $limit = false, $resample = "", $download = false, $contentTypeFor = false) { global $always_resample, $allow_resample, $always_resample_rate, $jzUSER; // Let's ignore if they abort, that way we'll know when the track stops... ignore_user_abort(TRUE); $jzSERVICES = new jzServices(); $jzSERVICES->loadStandardServices(); $status = false; if ($limit === false) { $speed_limit = 1 * 1024; } else { $speed_limit = $limit; } // limit is passed as a param because we may want to limit it for downloads // but not for streaming / image viewing. // Also, we may want to write a different function for resampling, // but I don't know yet. // IF NO SPEED LIMIT: // the 'speed_limit' from above is the amount // of buffer used while sending the file. // but with no speed limit, there is no 'sleep' issued. // this makes seeking in a file much faster. // Let's get the extension of the real file $extArr = explode(".", $path); $ext = $extArr[count($extArr) - 1]; if (!is_file($path) || connection_status() != 0) { return false; } $meta = $jzSERVICES->getTagData($path); $do_resample = false; if (!isNothing($resample)) { $do_resample = true; } if ($allow_resample == "true" && stristr($always_resample, $ext)) { $do_resample = true; } if ($meta['type'] == "mp3") { if (!isNothing($resample) && $resample >= $meta['bitrate']) { $do_resample = false; } } if ($download) { $do_resample = false; } // Are they resampling or transcoding? if ($do_resample) { // Ok, if resampling isn't set let's go with the default if ($resample == "") { $resample = $always_resample_rate; } // Now let's load up the resampling service $jzSERVICES = new jzServices(); $jzSERVICES->loadService("resample", "resample"); $jzSERVICES->resampleFile($path, $name, $resample); // Now let's unset what they are playing $be = new jzBackend(); $be->unsetPlaying($_GET['jz_user'], $_GET['sid']); return; } // Now we need to know if this is an ID3 image or not // First let's get their limit $limit = "7"; $size = filesize($path); $range = getContentRange($size); if ($range !== false) { $range_from = $range[0]; $range_to = $range[1]; } else { $range_from = 0; $range_to = $size - 1; } $ps3 = false; $allheaders = getallheaders(); if (isset($allheaders['User-Agent']) && $allheaders['User-Agent'] == "PLAYSTATION 3") { $ps3 = true; } if ($ps3) { // ps3 is picky and bizarre. if ($range_from > $size) { // This happens if the ps3 thinks the file // is larger than it is, and sending a // This is supposed to be a read of the id3v1 tag at // the end of a file (128 bytes), or the lyrics tag // (138 bytes) $requested = $range_to - $range_from + 1; $range_from = $size - $requested; $range_to = $size - 1; header("HTTP/1.1 206 Partial content"); } else { if ($range_from == 0 && $size == $range_to + 1) { header("HTTP/1.1 200 OK"); } else { header("HTTP/1.1 206 Partial content"); header("CONTENT-RANGE: bytes {$range_from}-{$range_to}/{$size}"); } } header("transferMode.dlna.org: Streaming"); header("contentFeatures.dlna.org: DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=017000 00000000000000000000000000"); header("Accept-Ranges: bytes"); header("Connection: keep-alive"); header("Content-Length: " . ($size - $range_from)); } else { if ($range === false) { // Content length has already been sent header("Content-Length: " . (string) $size); } else { header("HTTP/1.1 206 Partial Content"); header("Accept-Range: bytes"); header("Content-Length: " . ($size - $range_from)); header("Content-Range: bytes {$range_from}" . "-" . $range_to . "/{$size}"); } } if ($contentTypeFor !== false) { sendContentType($contentTypeFor); } if (!$ps3) { header("Content-Disposition: inline; filename=\"" . $name . "\""); header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($path)) . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); } if ($file = fopen($path, 'rb')) { @set_time_limit(0); fseek($file, $range_from); while (!feof($file) and connection_status() == 0 and ($cur_pos = ftell($file)) < $range_to + 1) { print fread($file, min(1024 * $speed_limit, $range_to + 1 - $cur_pos)); flush(); if ($limit !== false) { sleep(1); } } $status = connection_status() == 0; fclose($file); @set_time_limit(30); } // Now let's unset what they are playing $be = new jzBackend(); $be->unsetPlaying($_GET['jz_user'], $_GET['sid']); return $status; }
$media_dir = $_POST['media_dir']; $media_dir = str_replace("//", "/", str_replace("\\", "/", $media_dir)); // Now let's read each file under there echo "Reading all files in: " . $media_dir . ", please wait this might take quite a while...<br>"; $readCtr = 0; $retArray = readAllDirs($media_dir, &$readCtr, &$retArray, "false", "true"); echo "<br>" . count($retArray) . " files read, processing...<br>"; // Let's connect to the database mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); // Let's load up our services $jzSERVICES = new jzServices(); $jzSERVICES->loadStandardServices(); foreach ($retArray as $file) { // Let's read the meta data from the file $meta = $jzSERVICES->getTagData($file); // Let's insert into Genres $query = 'insert into jz_genres (Name) values ("' . $meta['genre'] . '")'; mysql_query($query); // Now let's get the ID for that genre $query = 'select ID from jz_genres where Name = "' . $meta['genre'] . '"'; $result = mysql_query($query); while (list($ID) = mysql_fetch_row($result)) { $genreID = $ID; } // Let's insert into artists $query = 'insert into jz_artists (Name) values ("' . $meta['artist'] . '")'; mysql_query($query); // Now let's get the ID for that artists $query = 'select ID from jz_artists where Name = "' . $meta['artist'] . '"'; $result = mysql_query($query);