public function DeleteLyrics3() { // Initialize GetId3 engine $getID3 = new GetId3_GetId3(); $ThisFileInfo = $getID3->analyze($this->filename); if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) { if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { flock($fp, LOCK_EX); $oldignoreuserabort = ignore_user_abort(true); fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end'], SEEK_SET); $DataAfterLyrics3 = ''; if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) { $DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']); } ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); if (!empty($DataAfterLyrics3)) { fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start'], SEEK_SET); fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3)); } flock($fp, LOCK_UN); fclose($fp); ignore_user_abort($oldignoreuserabort); return true; } else { $this->errors[] = 'Cannot fopen(' . $this->filename . ', "a+b")'; return false; } } // no Lyrics3 present return true; }
/** * * @return boolean */ public function setRealFileSize() { if (PHP_INT_MAX > 2147483647) { $this->filesize = filesize($this->filename); return true; } // 32-bit PHP will not return correct values for filesize() if file is >=2GB // but GetId3->analyze() has workarounds to get actual filesize $getID3 = new GetId3_GetId3(); $getID3->option_tag_id3v1 = false; $getID3->option_tag_id3v2 = false; $getID3->option_tag_apetag = false; $getID3->option_tags_html = false; $getID3->option_extra_info = false; $ThisFileInfo = $getID3->analyze($this->filename); $this->filesize = $ThisFileInfo['filesize']; return true; }
/** * * @return boolean */ public function RemoveReal() { // File MUST be writeable - CHMOD(646) at least if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { // Initialize GetId3 engine $getID3 = new GetId3_GetId3(); $OldThisFileInfo = $getID3->analyze($this->filename); if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { $this->errors[] = 'Cannot remove Real tags from old-style file format'; fclose($fp_source); return false; } if (empty($OldThisFileInfo['real']['chunks'])) { $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file'; fclose($fp_source); return false; } foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { $oldChunkInfo[$chunkarray['name']] = $chunkarray; } if (empty($oldChunkInfo['CONT'])) { // no existing CONT chunk fclose($fp_source); return true; } $BeforeOffset = $oldChunkInfo['CONT']['offset']; $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; if ($tempfilename = tempnam(GetId3_GetId3::getTempDir(), 'getID3')) { if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { rewind($fp_source); fwrite($fp_temp, fread($fp_source, $BeforeOffset)); fseek($fp_source, $AfterOffset, SEEK_SET); while ($buffer = fread($fp_source, $this->fread_buffer_size)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_temp); if (copy($tempfilename, $this->filename)) { unlink($tempfilename); fclose($fp_source); return true; } unlink($tempfilename); $this->errors[] = 'FAILED: copy(' . $tempfilename . ', ' . $this->filename . ')'; } else { $this->errors[] = 'Could not fopen("' . $tempfilename . '", "wb")'; } } fclose($fp_source); return false; } $this->errors[] = 'Could not fopen("' . $this->filename . '", "r+b")'; return false; }
/** * public: analyze file * * @param type $filename * @return type */ public function analyze($filename) { if (file_exists($filename)) { // Short-hands $filetime = filemtime($filename); $filesize = filesize($filename); // Lookup file $this->cursor = mysql_query("SELECT `value` FROM `" . mysql_real_escape_string($this->table) . "` WHERE (`filename` = '" . mysql_real_escape_string($filename) . "') AND (`filesize` = '" . mysql_real_escape_string($filesize) . "') AND (`filetime` = '" . mysql_real_escape_string($filetime) . "')", $this->connection); if (mysql_num_rows($this->cursor) > 0) { // Hit list($result) = mysql_fetch_array($this->cursor); return unserialize(base64_decode($result)); } } // Miss $analysis = parent::analyze($filename); // Save result if (file_exists($filename)) { $this->cursor = mysql_query("INSERT INTO `" . mysql_real_escape_string($this->table) . "` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('" . mysql_real_escape_string($filename) . "', '" . mysql_real_escape_string($filesize) . "', '" . mysql_real_escape_string($filetime) . "', '" . mysql_real_escape_string(time()) . "', '" . mysql_real_escape_string(base64_encode(serialize($analysis))) . "')", $this->connection); } return $analysis; }
/** * * @return boolean */ public function DeleteAPEtag() { $getID3 = new GetId3_GetId3(); $ThisFileInfo = $getID3->analyze($this->filename); if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['ape']['tag_offset_end'])) { if (is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { flock($fp, LOCK_EX); $oldignoreuserabort = ignore_user_abort(true); fseek($fp, $ThisFileInfo['ape']['tag_offset_end'], SEEK_SET); $DataAfterAPE = ''; if ($ThisFileInfo['filesize'] > $ThisFileInfo['ape']['tag_offset_end']) { $DataAfterAPE = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['ape']['tag_offset_end']); } ftruncate($fp, $ThisFileInfo['ape']['tag_offset_start']); fseek($fp, $ThisFileInfo['ape']['tag_offset_start'], SEEK_SET); if (!empty($DataAfterAPE)) { fwrite($fp, $DataAfterAPE, strlen($DataAfterAPE)); } flock($fp, LOCK_UN); fclose($fp); ignore_user_abort($oldignoreuserabort); return true; } return false; } return true; }
/** * analyze file * * @param type $filename * @return type */ public function analyze($filename) { if (file_exists($filename)) { // Calc key filename::mod_time::size - should be unique $key = $filename . '::' . filemtime($filename) . '::' . filesize($filename); // Loopup key $result = dba_fetch($key, $this->dba); // Hit if ($result !== false) { return unserialize($result); } } // Miss $result = parent::analyze($filename); // Save result if (file_exists($filename)) { dba_insert($key, serialize($result), $this->dba); } return $result; }
/** * analyze file and cache them, if cached pull from the db * @param type $filename * @return boolean */ public function analyze($filename) { if (!file_exists($filename)) { return false; } // items to track for caching $filetime = filemtime($filename); $filesize = filesize($filename); // this will be saved for a quick directory lookup of analized files // ... why do 50 seperate sql quries when you can do 1 for the same result $dirname = dirname($filename); // Lookup file $db = $this->db; $sql = $this->get_id3_data; $stmt = $db->prepare($sql); $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); $stmt->bindValue(':filesize', $filesize, SQLITE3_INTEGER); $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); $res = $stmt->execute(); list($result) = $res->fetchArray(); if (count($result) > 0) { return unserialize(base64_decode($result)); } // if it hasn't been analyzed before, then do it now $analysis = parent::analyze($filename); // Save result $sql = $this->cache_file; $stmt = $db->prepare($sql); $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); $stmt->bindValue(':dirname', $dirname, SQLITE3_TEXT); $stmt->bindValue(':filesize', $filesize, SQLITE3_INTEGER); $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); $stmt->bindValue(':atime', time(), SQLITE3_INTEGER); $stmt->bindValue(':val', base64_encode(serialize($analysis)), SQLITE3_TEXT); $res = $stmt->execute(); return $analysis; }