protected function analyzeDir($from_dir) { $newest_mtime = 0; $fps = array(); $di = new DirectoryIterator($from_dir); $dom = new SSLHistoryDom(); foreach ($di as $f) { if (!$f->isFile() || !substr($f->getFilename(), -8) == '.session') { continue; } $fps[] = $f->getPathname(); } natsort($fps); foreach ($fps as $fp) { $fn = basename($fp); echo "** Parsing {$fn}...\n"; try { $parser = new SSLParser($dom); $dom = $parser->parse($fp); } catch (Exception $e) { echo "-- ignoring {$fn}.\n"; } $parser->close(); } echo "++ Saw " . count($dom) . " chunks\n"; echo "** Extracting tracks...\n"; $tracks = $dom->getTracks(); echo "++ Saw " . count($tracks) . " tracks\n"; echo "** Importing to db"; foreach ($tracks as $track) { /* @var $track SSLTrack */ echo "."; $query = sprintf("INSERT INTO history (row, filename, title, artist, deck, starttime, endtime, played, updatedAt, playtime, length, album, fullpath)\n VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s', '%s', '%s')", $track->getRow(), sqlite_escape_string($track->getFilename()), sqlite_escape_string($track->getTitle()), sqlite_escape_string($track->getArtist()), $track->getDeck(), $track->getStartTime(), $track->getEndTime(), $track->getPlayed(), $track->getUpdatedAt(), $track->getPlayTime(), sqlite_escape_string($track->getLength()), sqlite_escape_string($track->getAlbum()), sqlite_escape_string($track->getFullpath())); if (!$this->dbo->exec($query)) { throw new Exception($error); } } echo "done\n"; }
/** * @return SSLHistoryDom */ protected function read($filename) { $parser = new SSLParser(new SSLHistoryDom()); $tree = $parser->parse($filename); $parser->close(); return $tree; }
public function close() { if (isset($this->tail_parser)) { $this->tail_parser->close(); } }