/** * Returns the cache as an array formatted as specified in updateCache(). * If the cache does not exist, returns false. * * @access private * @author Ben Dodson * @version 5/10/04 * @since 5/10/04 */ function readCache($type = false) { global $backend; if ($type == "track" || $type == "leaf" || $type == "leaves") { $type = "tracks"; } else { if ($type == "node") { $type = "nodes"; } else { if ($type === false) { if ($this->isLeaf()) { $type = "tracks"; } else { $type = "nodes"; } } } } $type = strtolower($type); if ($this->getLevel() == 0) { $cachename = "jzroot"; } else { if ($this->isLeaf() && $type == "tracks") { $temp = $this->getPath(); array_pop($temp); $cachename = implode("---", $temp); } else { $cachename = implode("---", $this->getPath()); } } $be =& new jzBackend(); $datapath = $be->getDataDir(); if (!is_file($datapath . "/{$type}/" . $cachename)) { // Give an empty cache. // Note that there are different 'empty caches'. if ($type == "nodes") { return blankCache("node"); } else { if ($type == "tracks") { return blankCache("track"); } else { return array(); } } } if ($this->isLeaf() && $type == "tracks") { $temp = $this->getPath(); $name = $temp[sizeof($temp) - 1]; $temp = unserialize(file_get_contents($datapath . "/tracks/" . $cachename)); for ($i = 0; $i < sizeof($temp); $i++) { if (isset($this->playpath) && $this->playpath !== false && $this->playpath != "") { // the best key: if ($temp[$i][0] == $this->playpath) { return $temp[$i]; } // if we don't have that: } else { if ($temp[$i][2] == $name) { return $temp[$i]; } } } return blankCache("track"); } else { return unserialize(file_get_contents($datapath . "/{$type}/" . $cachename)); } }
function updateCacheHelper($recursive, $levelsLeft, $root, $showStatus, $readID3) { global $audio_types, $video_types, $ext_graphic, $default_art, $backend, $track_num_seperator, $hierarchy, $protocols; if ($root !== false) { $mediapath = $root; } else { $mediapath = $this->getFilePath(); } if ($mediapath == "-") { // let's find it.. $parent = $this->getParent(); $mediapath = $parent->getFilePath() . "/" . $this->getName(); } $nodepath = $this->getPath("String"); /* Echo out our current status, if they want it: */ if ($showStatus === true) { showStatus($mediapath); } else { if ($showStatus == "cli") { echo word("Scanning: ") . $mediapath . "\n"; } } // First add $this. // Was I already cached? $cache = $this->readCache(); if ($cache[0] == "-") { $cache[0] = $nodepath; } if ($cache[13] == "-") { $cache[13] = $mediapath; } if ($cache[6] == "-") { $cache[6] = jz_filemtime($mediapath); } if ($cache[15] == "-") { $ptype = findPType($this); $cache[15] = $ptype; } $blankfilecache = blankCache("track"); // Recurse and add $this's media files. if (!($handle = opendir($mediapath))) { die("Could not access directory {$mediapath}"); } // scan for info while going through directory: $trackcount = 0; $new_nodes = $cache[7]; $new_tracks = $cache[8]; $bestImage = ""; $bestDescription = ""; while ($file = readdir($handle)) { $childpath = $nodepath == "" ? $file : $nodepath . "/" . $file; $fullchildpath = $mediapath . "/" . $file; if ($file == "." || $file == "..") { continue; } else { if (is_dir($fullchildpath)) { if ($recursive) { $next =& new jzMediaNode($childpath); $next->updateCacheHelper(true, $levelsLeft, $fullchildpath, $showStatus, $readID3); } else { if ($levelsLeft === false && $this->getNaturalDepth() > 1) { $next =& new jzMediaNode($childpath); $next->updateCacheHelper(false, $this->getNaturalDepth() - 2, $fullchildpath, $showStatus, $readID3); } else { if ($levelsLeft > 0) { $next =& new jzMediaNode($childpath); $next->updateCacheHelper(false, $levelsLeft - 1, $fullchildpath, $showStatus, $readID3); } } } if ($new_nodes != array()) { $key = array_search($file, $new_nodes); if (false === $key) { $new_nodes[] = $file; $next =& new jzMediaNode($childpath); } } else { $new_nodes[] = $file; $next =& new jzMediaNode($childpath); } } else { if (preg_match("/\\.(txt)\$/i", $file)) { // TODO: GET THE CORRECT DESCRIPTION IN $bestDescription // $bestDescription = $fullchildpath; } else { if (preg_match("/\\.({$ext_graphic})\$/i", $file) && !stristr($file, ".thumb.")) { // An image if (@preg_match("/({$default_art})/i", $file)) { $bestImage = $fullchildpath; } else { if ($bestImage == "") { $bestImage = $fullchildpath; } } } else { if (preg_match("/\\.({$audio_types})\$/i", $file) || preg_match("/\\.({$video_types})\$/i", $file)) { //* * * A track * * * *// // Add it to the track list. if ($new_tracks != array()) { $key = array_search($file, $new_tracks); if (false === $key) { $new_tracks[] = $file; } } else { $new_tracks[] = $file; } // And at it's details.. $childnode =& new jzMediaTrack($childpath); if ($cache[2] == "-" || $cache[2] < date("U", jz_filemtime($fullchildpath)) || !$childnode->readCache()) { // Add as a new/updated track. $filecache[$trackcount] = $childnode->readCache(); if ($filecache[$trackcount][0] == "-") { $filecache[$trackcount][0] = $fullchildpath; $filecache[$trackcount][6] = jz_filemtime($fullchildpath); $filecache[$trackcount][2] = $file; } ////////// // META // ////////// $track =& new jzMediaTrack($childpath); $track->playpath = $fullchildpath; if ($readID3 === true) { $meta = $track->getMeta("file"); // read meta info from the file; } else { $meta = array(); } $filecache[$trackcount][7] = $meta['title']; $filecache[$trackcount][8] = $meta['frequency']; $filecache[$trackcount][9] = $meta['comment']; $filecache[$trackcount][11] = $meta['year']; $filecache[$trackcount][13] = $meta['size']; $filecache[$trackcount][14] = $meta['length']; $filecache[$trackcount][15] = $meta['genre']; $filecache[$trackcount][16] = $meta['artist']; $filecache[$trackcount][17] = $meta['album']; $filecache[$trackcount][18] = $meta['type']; $filecache[$trackcount][19] = $meta['lyrics']; $filecache[$trackcount][20] = $meta['bitrate']; $filecache[$trackcount][21] = $meta['number']; // Now let's see if there is a description file... $desc_file = str_replace("." . $meta['type'], "", $fullchildpath) . ".txt"; $long_description = ""; if (is_file($desc_file) and filesize($desc_file) != 0) { // Ok, let's read the description file $handle2 = fopen($desc_file, "rb"); $filecache[$trackcount][10] = fread($handle2, filesize($desc_file)); fclose($handle2); } else { $filecache[$trackcount][10] = ""; } // Now let's see if there is a thumbnail for this track $filecache[$trackcount][1] = searchThumbnail($fullchildpath); } else { // slow but necessary.. //$filecache[$trackcount] = $childnode->readCache(); } $trackcount++; // Let's track this writeLogData('importer', "Importing track: " . $fullchildpath); $_SESSION['jz_import_full_progress']++; } } } } } } if ($new_nodes != array()) { foreach ($new_nodes as $i => $my_path) { $me =& new jzMediaNode($nodepath . "/" . $my_path); if ($me->getFilePath() == "-") { $arr = explode("/", $my_path); $mfp = $this->getFilePath() . "/" . $arr[sizeof($arr) - 1]; } else { $mfp = $me->getFilePath(); } if (!is_dir($mfp)) { // TODO: The commented out part should check to see if there are 'permanent' subnodes. // It is possible a directory was created to house links (and does not have // any data on the filesystem) $remove_me = true; $list = $me->getSubNodes("tracks", -1); foreach ($list as $el) { if (stristr($el->getFilePath(), "://")) { $remove_me = false; break; } } if ($remove_me) { $me->deleteCache(); unset($new_nodes[$i]); } } } } if ($new_tracks != array()) { foreach ($new_nodes as $i => $my_path) { $me =& new jzMediaTrack($nodepath . "/" . $my_path); if (!is_file($fpath = $me->getFilePath())) { $valid = false; $parr = explode("|", $protocols); if (strlen($fpath) > 2) { foreach ($parr as $p) { if (stristr($fpath, $p) !== false) { $valid = true; } } } if (!$valid) { $me->deleteCache(); unset($new_tracks[$i]); } } } } // Update $this if ($bestImage != "") { $cache[1] = $bestImage; } if ($bestDescription != "") { $cache[10] = file_get_contents($bestDescription); } $cache[2] = date("U"); natcasesort($new_nodes); $cache[7] = array_values($new_nodes); natcasesort($new_tracks); $cache[8] = array_values($new_tracks); // * * * * * * * * // Write the cache. $this->writeCache($cache, "nodes"); if ($filecache != array()) { $this->writeCache($filecache, "tracks"); } }