/** * Sets the track's meta information. * $meta is an array of meta fields to set. * $mode specifies where to update the meta, * false means do it in the cache and in the id3. * * @author Ben Dodson * @version 10/13/04 * @since 10/13/04 */ function setMeta($meta, $mode = false, $displayOutput = false) { global $jzSERVICES, $allow_id3_modify, $backend, $hierarchy; if (is_array($hierarchy)) { $hstring = implode("/", $hierarchy); } else { $hstring = $hierarchy; } if ($mode == false) { // TODO: add variable to see if user allows ID3 updating. $this->setMeta($meta, "file"); $this->setMeta($meta, "cache"); } if ($mode == "cache") { $filecache = $this->readCache(); if (isset($meta['title'])) { $filecache[7] = $meta['title']; } if (isset($meta['frequency'])) { $filecache[8] = $meta['frequency']; } if (isset($meta['comment'])) { $filecache[9] = $meta['comment']; } if (isset($meta['year'])) { $filecache[11] = $meta['year']; } if (isset($meta['size'])) { $filecache[13] = $meta['size']; } if (isset($meta['length'])) { $filecache[14] = $meta['length']; } if (isset($meta['genre'])) { $filecache[15] = $meta['genre']; } if (isset($meta['artist'])) { $filecache[16] = $meta['artist']; } if (isset($meta['album'])) { $filecache[17] = $meta['album']; } if (isset($meta['type'])) { $filecache[18] = $meta['type']; } if (isset($meta['lyrics'])) { $filecache[19] = $meta['lyrics']; } if (isset($meta['bitrate'])) { $filecache[20] = $meta['bitrate']; } if (isset($meta['number'])) { $filecache[21] = $meta['number']; } $this->writeCache($filecache); return true; } else { if ($mode == "direct") { $fname = $this->getPath("String"); } else { $fname = $this->getFileName("host"); } if ($backend == "id3-database" || $backend == "id3-cache") { $oldmeta = $this->getMeta("file"); } // Ok, now we need to write the data to this file IF it's an MP3 if ($allow_id3_modify == "true") { $status = $jzSERVICES->setTagData($fname, $meta); } else { $status = true; } if (!isset($meta['genre'])) { $meta['genre'] = $oldmeta['genre']; } if (!isset($meta['artist'])) { $meta['artist'] = $oldmeta['artist']; } if (!isset($meta['album'])) { $meta['album'] = $oldmeta['album']; } if (!isset($meta['filename'])) { $meta['filename'] = $oldmeta['filename']; } if ($backend == "id3-database" || $backend == "id3-cache") { if ($oldmeta['genre'] != $meta['genre'] && stristr($hstring, "genre") !== false || $oldmeta['artist'] != $meta['artist'] && stristr($hstring, "artist") !== false || $oldmeta['album'] != $meta['album'] && stristr($hstring, "album") !== false || $oldmeta['filename'] != $meta['filename']) { // The media needs to be moved. $arr = buildPath($meta); $newpath = implode("/", $arr); $root = new jzMediaNode(); $root->moveMedia($this, $newpath); $this->reconstruct($newpath); } } return $status; } }
function SERVICE_IMPORTMEDIA_id3tags($node, $root_path = false, $flags = array()) { global $ext_graphic, $default_art, $audio_types, $video_types; $be = new jzBackend(); $root = new jzMediaNode(); if (isset($flags['recursive']) && $flags['recursive'] === false || $root_path === false) { /* if ($node === false) { $node = new jzMediaNode(); } $tracks = $node->getSubNodes("tracks"); foreach ($tracks as $track) { $fname = $track->getFileName("host"); $entry = $be->lookupFile($fname); if (!is_array($entry)) { echo "Error in SERVICE_IMPORTMEDIA_id3tags. File added but does not exist in registry."; return; } if ($entry['fs_sync'] && !file_exists($fname)) { $be->unregisterFile($fname); $root->removeMedia($track); } // TODO: CHECK THE ABOVE!!! CHECK UNREGISTERFILE! // TODO: check modified time and move file if needed. } */ return false; } $directory_list = array(); $directory_list[] = $root_path; if (isset($flags['showstatus']) && $flags['showstatus'] && !(is_string($flags['showstatus']) && $flags['showstatus'] == "cli")) { $_SESSION['jz_import_full_progress'] = 0; } while (sizeof($directory_list) > 0) { $cur_dir = array_shift($directory_list); if (isset($flags['showstatus']) && is_string($flags['showstatus']) && $flags['showstatus'] == "cli") { echo word("Scanning: %s", $cur_dir) . "\n"; } $bestImage = ""; $albums = array(); $track_paths = array(); $track_filenames = array(); $track_metas = array(); if (!($handle = opendir($cur_dir))) { continue; } //die("Could not access directory $dir"); while ($file = readdir($handle)) { if ($file == "." || $file == "..") { continue; } $fullpath = $cur_dir . "/" . $file; if (is_dir($fullpath)) { $directory_list[] = $fullpath; } else { if (preg_match("/\\.({$ext_graphic})\$/i", $file) && !stristr($file, ".thumb.")) { // An image if (@preg_match("/({$default_art})/i", $file)) { $bestImage = $fullpath; } else { if ($bestImage == "") { $bestImage = $fullpath; } } } else { if (preg_match("/\\.({$audio_types})\$/i", $file) || preg_match("/\\.({$video_types})\$/i", $file)) { $entry = $be->lookupFile($fullpath); if (isset($flags['showstatus']) && $flags['showstatus'] && !(is_string($flags['showstatus']) && $flags['showstatus'] == "cli")) { if ($_SESSION['jz_import_full_progress'] % 50 == 0 or $_SESSION['jz_import_full_progress'] == 0 or $_SESSION['jz_import_full_progress'] == 1) { showStatus(); } $_SESSION['jz_import_full_progress']++; } if (is_array($entry) && $entry['added'] < filemtime($fullpath)) { // moved file $track =& new jzMediaTrack($fullpath); $track->playpath = $fullpath; $meta = $track->getMeta("file"); $arr = array(); if (isset($meta['genre'])) { $arr['genre'] = $meta['genre']; } if (isset($meta['subgenre'])) { $arr['subgenre'] = $meta['subgenre']; } if (isset($meta['artist'])) { $arr['artist'] = $meta['artist']; } if (isset($meta['album'])) { $arr['album'] = $meta['album']; } if (isset($meta['disk'])) { $arr['disk'] = $meta['disk']; } if (isset($meta['filename'])) { $arr['track'] = $meta['filename']; } $old = new jzMediaTrack($entry['path']); $child = $root->moveMedia($old, $arr); if ($child !== false) { $album = $child->getAncestor("album"); if ($album !== false) { $albums[$album->getPath("String")] = true; } } } else { if ($entry === false || isset($flags['force']) && $flags['force'] === true) { // Set path so when getFileName is called and the filepath was not found, // we get the correct path. $track =& new jzMediaTrack($fullpath); $track->playpath = $fullpath; $meta = $track->getMeta("file"); $arr = array(); if (isset($meta['genre'])) { $arr['genre'] = $meta['genre']; } if (isset($meta['subgenre'])) { $arr['subgenre'] = $meta['subgenre']; } if (isset($meta['artist'])) { $arr['artist'] = $meta['artist']; } if (isset($meta['album'])) { $arr['album'] = $meta['album']; } if (isset($meta['disk'])) { $arr['disk'] = $meta['disk']; } if (isset($meta['filename'])) { $arr['track'] = $meta['filename']; } $track_paths[] = $arr; $track_filenames[] = $fullpath; $track_metas[] = $meta; } } } } } } // while reading dir $art_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR; if (sizeof($track_paths) > 0) { $results = $root->bulkInject($track_paths, $track_filenames, $track_metas); for ($i = 0; $i < sizeof($results); $i++) { if ($results[$i] !== false) { $album = $results[$i]->getAncestor("album"); if ($album !== false) { $albums[$album->getPath("String")] = true; $newalbum = new jzMediaNode($album->getPath("String")); // If we have album art in the tag, add it. if ($track_metas[$i]['pic_data'] != "") { $artloc = realpath($art_dir) . DIRECTORY_SEPARATOR . "art_" . $newalbum->getID() . ".jpg"; if ($artloc !== false) { $filehandle = fopen($artloc, "wb"); fwrite($filehandle, $track_metas[$i]['pic_data']); fclose($filehandle); $newalbum->addMainArt("data" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "art_" . $newalbum->getID() . ".jpg"); } } } } } } } if (isset($flags['showstatus']) && is_string($flags['showstatus']) && $flags['showstatus'] == "cli") { echo word("Scanning for removed media.") . "\n"; } $be->removeDeadFiles(); }