ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Extension\Cache\Sqlite3 Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Inheritance diagram for GetId3\Extension\Cache\Sqlite3:
+ Collaboration diagram for GetId3\Extension\Cache\Sqlite3:

Public Member Functions

 __construct ($table='getid3_cache', $hide=false)
 __construct() More...
 
 __destruct ()
 close the database connection More...
 
 analyze ($filename)
 analyze file and cache them, if cached pull from the db More...
 
 get_cached_dir ($dir)
 get cached directory More...
 
 __get ($name)
 use the magical __get() for sql queries More...
 
- Public Member Functions inherited from GetId3\GetId3Core
 __construct ()
 public: constructor More...
 
 version ()
 
 fread_buffer_size ()
 
 setOption ($optArray)
 public: setOption More...
 
 openfile ($filename)
 
 analyze ($filename)
 public: analyze file More...
 
 GetFileFormatArray ()
 array $format_info More...
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 array $tags More...
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 GetId3_tempnam ()
 

Private Member Functions

 clear_cache ()
 clear the cache private More...
 
 create_table ()
 create data base table this is almost the same as MySQL, with the exception of the dirname being added More...
 

Private Attributes

 $db
 
 $table
 table to use for caching More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GetId3\GetId3Core
static getHelperAppsDir ()
 
static getTempDir ()
 
static environmentIsWindows ()
 
static getIncludePath ()
 
- Data Fields inherited from GetId3\GetId3Core
 $encoding = 'UTF-8'
 
 $encoding_id3v1 = 'ISO-8859-1'
 
 $option_tag_id3v1 = true
 
 $option_tag_id3v2 = true
 
 $option_tag_lyrics3 = true
 
 $option_tag_apetag = true
 
 $option_tags_process = true
 
 $option_tags_html = true
 
 $option_extra_info = true
 
 $option_save_attachments = true
 
 $option_md5_data = false
 
 $option_md5_data_source = false
 
 $option_sha1_data = false
 
 $option_max_2gb_check = null
 
 $option_fread_buffer_size = 32768
 
 $filename
 
 $fp
 
 $info
 
 $tempdir
 
const VERSION = '1.9.4-20120530'
 
const FREAD_BUFFER_SIZE = 32768
 
const ATTACHMENTS_NONE = false
 
const ATTACHMENTS_INLINE = true
 
- Protected Member Functions inherited from GetId3\GetId3Core
 setHelperAppsDir ()
 
- Protected Attributes inherited from GetId3\GetId3Core
 $startup_error = ''
 
 $startup_warning = ''
 
 $memory_limit = 0
 
- Static Protected Attributes inherited from GetId3\GetId3Core
static $TempDir
 
static $IncludePath
 
static $EnvironmentIsWindows
 
static $HelperAppsDir
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

// // This is a caching extension for GetId3(). It works the exact same way as the GetId3 class, but return cached information much faster

Normal GetId3 usage (example):

require_once 'getid3/getid3.php'; $getID3 = new GetId3; $getID3->encoding = 'UTF-8'; $info1 = $getID3->analyze('file1.flac'); $info2 = $getID3->analyze('file2.wv');

GetId3_cached usage:

require_once 'getid3/getid3.php'; require_once 'getid3/extension.cache.sqlite3.php'; // all parameters are optional, defaults are: $getID3 = new GetId3_cached_sqlite3($table='getid3_cache', $hide=FALSE); $getID3->encoding = 'UTF-8'; $info1 = $getID3->analyze('file1.flac'); $info2 = $getID3->analyze('file2.wv');

Supported Cache Types (this extension)

SQL Databases:

cache_type cache_options

mysql host, database, username, password

sqlite3 table='getid3_cache', hide=false (PHP5)

** database file will be stored in the same directory as this script, ** webserver must have write access to that directory! ** set $hide to TRUE to prefix db file with .ht to pervent access from web client ** this is a default setting in the Apache configuration:

The following lines prevent .htaccess and .htpasswd files from being viewed by Web clients.

<Files ~ "^\.ht"> Order allow,deny Deny from all Satisfy all </Files>



DBM-Style Databases: (use extension.cache.dbm)

cache_type cache_options

gdbm dbm_filename, lock_filename ndbm dbm_filename, lock_filename db2 dbm_filename, lock_filename db3 dbm_filename, lock_filename db4 dbm_filename, lock_filename (PHP5 required)

PHP must have write access to both dbm_filename and lock_filename.

Recommended Cache Types

Infrequent updates, many reads any DBM Frequent updates mysql


IMHO this is still a bit slow, I'm using this with MP4/MOV/ M4v files there is a plan to add directory scanning and analyzing to make things work much faster

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g
Allan Hansen <ahØartemis*dk>
Carlo Capocasa <calroØcarlocapocasa*com>
Karl G. Holz <newaeonØmac*com> http://www.getid3.org

Definition at line 106 of file Sqlite3.php.

Constructor & Destructor Documentation

◆ __construct()

GetId3\Extension\Cache\Sqlite3::__construct (   $table = 'getid3_cache',
  $hide = false 
)

__construct()

Parameters
string$tableholds name of sqlite table
Returns
type

Definition at line 125 of file Sqlite3.php.

References GetId3\Extension\Cache\Sqlite3\$db, $file, $result, GetId3\Extension\Cache\Sqlite3\$table, $version, GetId3\Extension\Cache\Sqlite3\clear_cache(), GetId3\Extension\Cache\Sqlite3\create_table(), and GetId3\GetId3Core\VERSION.

126  {
127  $this->table = $table; // Set table
128  $file = dirname(__FILE__) . '/' . basename(__FILE__, 'php') . 'sqlite';
129  if ($hide) {
130  $file = dirname(__FILE__) . '/.ht.' . basename(__FILE__, 'php') . 'sqlite';
131  }
132  $this->db = new SQLite3($file);
133  $db = $this->db;
134  $this->create_table(); // Create cache table if not exists
135  $version = '';
136  $sql = $this->version_check;
137  $stmt = $db->prepare($sql);
138  $stmt->bindValue(':filename', GetId3Core::VERSION, SQLITE3_TEXT);
139  $result = $stmt->execute();
140  list($version) = $result->fetchArray();
141  if ($version != GetId3Core::VERSION) { // Check version number and clear cache if changed
142  $this->clear_cache();
143  }
144 
145  return parent::__construct();
146  }
$result
clear_cache()
clear the cache private
Definition: Sqlite3.php:162
create_table()
create data base table this is almost the same as MySQL, with the exception of the dirname being adde...
Definition: Sqlite3.php:226
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
$table
table to use for caching
Definition: Sqlite3.php:118
+ Here is the call graph for this function:

◆ __destruct()

GetId3\Extension\Cache\Sqlite3::__destruct ( )

close the database connection

Definition at line 151 of file Sqlite3.php.

References GetId3\Extension\Cache\Sqlite3\$db.

152  {
153  $db = $this->db;
154  $db->close();
155  }

Member Function Documentation

◆ __get()

GetId3\Extension\Cache\Sqlite3::__get (   $name)

use the magical __get() for sql queries

access as easy as $this->{case name}, returns NULL if query is not found

Definition at line 264 of file Sqlite3.php.

265  {
266  switch ($name) {
267  case 'version_check':
268  return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = '-1' AND filetime = '-1' AND analyzetime = '-1'";
269  break;
270  case 'delete_cache':
271  return "DELETE FROM $this->table";
272  break;
273  case 'set_version':
274  return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, -1, -1, -1, :val)";
275  break;
276  case 'get_id3_data':
277  return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = :filesize AND filetime = :filetime";
278  break;
279  case 'cache_file':
280  return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, :filesize, :filetime, :atime, :val)";
281  break;
282  case 'make_table':
283  return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) NOT NULL DEFAULT '', dirname VARCHAR(255) NOT NULL DEFAULT '', filesize INT(11) NOT NULL DEFAULT '0', filetime INT(11) NOT NULL DEFAULT '0', analyzetime INT(11) NOT NULL DEFAULT '0', val text not null, PRIMARY KEY (filename, filesize, filetime))";
284  break;
285  case 'get_cached_dir':
286  return "SELECT val FROM $this->table WHERE dirname = :dirname";
287  break;
288  }
289  }

◆ analyze()

GetId3\Extension\Cache\Sqlite3::analyze (   $filename)

analyze file and cache them, if cached pull from the db

Parameters
type$filename
Returns
boolean

Definition at line 181 of file Sqlite3.php.

References GetId3\Extension\Cache\Sqlite3\$db, GetId3\GetId3Core\$filename, $res, $result, and time.

182  {
183  if (!file_exists($filename)) {
184  return false;
185  }
186  // items to track for caching
187  $filetime = filemtime($filename);
188  $filesize = filesize($filename);
189  // this will be saved for a quick directory lookup of analized files
190  // ... why do 50 seperate sql quries when you can do 1 for the same result
191  $dirname = dirname($filename);
192  // Lookup file
193  $db = $this->db;
194  $sql = $this->get_id3_data;
195  $stmt = $db->prepare($sql);
196  $stmt->bindValue(':filename', $filename, SQLITE3_TEXT);
197  $stmt->bindValue(':filesize', $filesize, SQLITE3_INTEGER);
198  $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER);
199  $res = $stmt->execute();
200  list($result) = $res->fetchArray();
201  if (count($result) > 0) {
202  return unserialize(base64_decode($result));
203  }
204  // if it hasn't been analyzed before, then do it now
205  $analysis = parent::analyze($filename);
206  // Save result
207  $sql = $this->cache_file;
208  $stmt = $db->prepare($sql);
209  $stmt->bindValue(':filename', $filename, SQLITE3_TEXT);
210  $stmt->bindValue(':dirname', $dirname, SQLITE3_TEXT);
211  $stmt->bindValue(':filesize', $filesize, SQLITE3_INTEGER);
212  $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER);
213  $stmt->bindValue(':atime', time(), SQLITE3_INTEGER);
214  $stmt->bindValue(':val', base64_encode(serialize($analysis)),
215  SQLITE3_TEXT);
216  $res = $stmt->execute();
217 
218  return $analysis;
219  }
$result
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ clear_cache()

GetId3\Extension\Cache\Sqlite3::clear_cache ( )
private

clear the cache private

Returns
type

Definition at line 162 of file Sqlite3.php.

References GetId3\Extension\Cache\Sqlite3\$db, and GetId3\GetId3Core\VERSION.

Referenced by GetId3\Extension\Cache\Sqlite3\__construct().

163  {
164  $db = $this->db;
165  $sql = $this->delete_cache;
166  $db->exec($sql);
167  $sql = $this->set_version;
168  $stmt = $db->prepare($sql);
169  $stmt->bindValue(':filename', GetId3Core::VERSION, SQLITE3_TEXT);
170  $stmt->bindValue(':dirname', GetId3Core::VERSION, SQLITE3_TEXT);
171  $stmt->bindValue(':val', GetId3Core::VERSION, SQLITE3_TEXT);
172 
173  return $stmt->execute();
174  }
+ Here is the caller graph for this function:

◆ create_table()

GetId3\Extension\Cache\Sqlite3::create_table ( )
private

create data base table this is almost the same as MySQL, with the exception of the dirname being added

Returns
type

Definition at line 226 of file Sqlite3.php.

References GetId3\Extension\Cache\Sqlite3\$db.

Referenced by GetId3\Extension\Cache\Sqlite3\__construct().

227  {
228  $db = $this->db;
229  $sql = $this->make_table;
230 
231  return $db->exec($sql);
232  }
+ Here is the caller graph for this function:

◆ get_cached_dir()

GetId3\Extension\Cache\Sqlite3::get_cached_dir (   $dir)

get cached directory

This function is not in the MySQL extention, it's ment to speed up requesting multiple files which is ideal for podcasting, playlists, etc.

public

Parameters
string$dirdirectory to search the cache database for
Returns
array return an array of matching id3 data

Definition at line 244 of file Sqlite3.php.

References GetId3\Extension\Cache\Sqlite3\$db, $res, $row, and array.

245  {
246  $db = $this->db;
247  $rows = array();
248  $sql = $this->get_cached_dir;
249  $stmt = $db->prepare($sql);
250  $stmt->bindValue(':dirname', $dir, SQLITE3_TEXT);
251  $res = $stmt->execute();
252  while ($row = $res->fetchArray()) {
253  $rows[] = unserialize(base64_decode($row));
254  }
255 
256  return $rows;
257  }
Create styles array
The data for the language used.

Field Documentation

◆ $db

◆ $table

string GetId3\Extension\Cache\Sqlite3::$table
private

table to use for caching

Definition at line 118 of file Sqlite3.php.

Referenced by GetId3\Extension\Cache\Sqlite3\__construct().


The documentation for this class was generated from the following file: