ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getID3_cached_sqlite3 Class Reference

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

+ Inheritance diagram for getID3_cached_sqlite3:
+ Collaboration diagram for getID3_cached_sqlite3:

Public Member Functions

 __construct ($table='getid3_cache', $hide=false)
 __construct() More...
 
 __destruct ()
 close the database connection More...
 
 analyze ($filename, $filesize=null, $original_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
 getID3 ()
 
 setOption ($optArray)
 
 analyze ($filename)
 
 error ($message)
 
 warning ($message)
 
 CleanUp ()
 
 GetFileFormatArray ()
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 getid3_tempnam ()
 
 __construct ()
 
 version ()
 
 fread_buffer_size ()
 
 setOption ($optArray)
 
 openfile ($filename, $filesize=null)
 
 analyze ($filename, $filesize=null, $original_filename='')
 
 error ($message)
 
 warning ($message)
 
 GetFileFormatArray ()
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 getid3_tempnam ()
 
 include_module ($name)
 

Private Member Functions

 clear_cache ()
 clear the cache @access 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

- Data Fields inherited from getID3
 $encoding = 'ISO-8859-1'
 
 $encoding_id3v1 = 'ISO-8859-1'
 
 $tempdir = '*'
 
 $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_md5_data = false
 
 $option_md5_data_source = false
 
 $option_sha1_data = false
 
 $option_max_2gb_check = true
 
 $filename
 
 $option_save_attachments = true
 
 $option_fread_buffer_size = 32768
 
 $fp
 
 $info
 
 $memory_limit = 0
 
const VERSION = '1.9.10-20150914'
 
const FREAD_BUFFER_SIZE = 32768
 
const ATTACHMENTS_NONE = false
 
const ATTACHMENTS_INLINE = true
 
- Protected Attributes inherited from getID3
 $startup_error = ''
 
 $startup_warning = ''
 

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

Definition at line 92 of file extension.cache.sqlite3.php.

Constructor & Destructor Documentation

◆ __construct()

getID3_cached_sqlite3::__construct (   $table = 'getid3_cache',
  $hide = false 
)

__construct()

Parameters
string$tableholds name of sqlite table
Returns
type

Definition at line 99 of file extension.cache.sqlite3.php.

99 {
100 $this->table = $table; // Set table
101 $file = dirname(__FILE__).'/'.basename(__FILE__, 'php').'sqlite';
102 if ($hide) {
103 $file = dirname(__FILE__).'/.ht.'.basename(__FILE__, 'php').'sqlite';
104 }
105 $this->db = new SQLite3($file);
106 $db = $this->db;
107 $this->create_table(); // Create cache table if not exists
108 $version = '';
109 $sql = $this->version_check;
110 $stmt = $db->prepare($sql);
111 $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT);
112 $result = $stmt->execute();
113 list($version) = $result->fetchArray();
114 if ($version != getID3::VERSION) { // Check version number and clear cache if changed
115 $this->clear_cache();
116 }
117 return parent::__construct();
118 }
$result
print $file
$table
table to use for caching
clear_cache()
clear the cache @access private
create_table()
create data base table this is almost the same as MySQL, with the exception of the dirname being adde...
const VERSION
Definition: getid3.php:112

References $db, $file, $result, $table, clear_cache(), create_table(), and getID3\VERSION.

+ Here is the call graph for this function:

◆ __destruct()

getID3_cached_sqlite3::__destruct ( )

close the database connection

Definition at line 123 of file extension.cache.sqlite3.php.

123 {
125 $db->close();
126 }

References $db.

Member Function Documentation

◆ __get()

getID3_cached_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 238 of file extension.cache.sqlite3.php.

238 {
239 switch($name) {
240 case 'version_check':
241 return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = '-1' AND filetime = '-1' AND analyzetime = '-1'";
242 break;
243 case 'delete_cache':
244 return "DELETE FROM $this->table";
245 break;
246 case 'set_version':
247 return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, -1, -1, -1, :val)";
248 break;
249 case 'get_id3_data':
250 return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = :filesize AND filetime = :filetime";
251 break;
252 case 'cache_file':
253 return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, :filesize, :filetime, :atime, :val)";
254 break;
255 case 'make_table':
256 //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))";
257 return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) DEFAULT '', dirname VARCHAR(255) DEFAULT '', filesize INT(11) DEFAULT '0', filetime INT(11) DEFAULT '0', analyzetime INT(11) DEFAULT '0', val text, PRIMARY KEY (filename, filesize, filetime))";
258 break;
259 case 'get_cached_dir':
260 return "SELECT val FROM $this->table WHERE dirname = :dirname";
261 break;
262 }
263 return null;
264 }

◆ analyze()

getID3_cached_sqlite3::analyze (   $filename,
  $filesize = null,
  $original_filename = '' 
)

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

Parameters
type$filename
Returns
boolean

Reimplemented from getID3.

Definition at line 162 of file extension.cache.sqlite3.php.

162 {
163 if (!file_exists($filename)) {
164 return false;
165 }
166 // items to track for caching
167 $filetime = filemtime($filename);
168 $filesize = filesize($filename);
169 // this will be saved for a quick directory lookup of analized files
170 // ... why do 50 seperate sql quries when you can do 1 for the same result
171 $dirname = dirname($filename);
172 // Lookup file
173 $db = $this->db;
174 $sql = $this->get_id3_data;
175 $stmt = $db->prepare($sql);
176 $stmt->bindValue(':filename', $filename, SQLITE3_TEXT);
177 $stmt->bindValue(':filesize', $filesize, SQLITE3_INTEGER);
178 $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER);
179 $res = $stmt->execute();
180 list($result) = $res->fetchArray();
181 if (count($result) > 0 ) {
182 return unserialize(base64_decode($result));
183 }
184 // if it hasn't been analyzed before, then do it now
185 $analysis = parent::analyze($filename, $filesize=null, $original_filename='');
186 // Save result
187 $sql = $this->cache_file;
188 $stmt = $db->prepare($sql);
189 $stmt->bindValue(':filename', $filename, SQLITE3_TEXT);
190 $stmt->bindValue(':dirname', $dirname, SQLITE3_TEXT);
191 $stmt->bindValue(':filesize', $filesize, SQLITE3_INTEGER);
192 $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER);
193 $stmt->bindValue(':atime', time(), SQLITE3_INTEGER);
194 $stmt->bindValue(':val', base64_encode(serialize($analysis)), SQLITE3_TEXT);
195 $res = $stmt->execute();
196 return $analysis;
197 }
$filename
Definition: getid3.php:46

References $db, getID3\$filename, $res, and $result.

◆ clear_cache()

getID3_cached_sqlite3::clear_cache ( )
private

clear the cache @access private

Returns
type

Definition at line 145 of file extension.cache.sqlite3.php.

145 {
146 $db = $this->db;
147 $sql = $this->delete_cache;
148 $db->exec($sql);
149 $sql = $this->set_version;
150 $stmt = $db->prepare($sql);
151 $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT);
152 $stmt->bindValue(':dirname', getID3::VERSION, SQLITE3_TEXT);
153 $stmt->bindValue(':val', getID3::VERSION, SQLITE3_TEXT);
154 return $stmt->execute();
155 }

References $db, and getID3\VERSION.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ create_table()

getID3_cached_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 204 of file extension.cache.sqlite3.php.

204 {
205 $db = $this->db;
206 $sql = $this->make_table;
207 return $db->exec($sql);
208 }

References $db.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ get_cached_dir()

getID3_cached_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.

@access public

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

Definition at line 220 of file extension.cache.sqlite3.php.

220 {
221 $db = $this->db;
222 $rows = array();
223 $sql = $this->get_cached_dir;
224 $stmt = $db->prepare($sql);
225 $stmt->bindValue(':dirname', $dir, SQLITE3_TEXT);
226 $res = $stmt->execute();
227 while ($row=$res->fetchArray()) {
228 $rows[] = unserialize(base64_decode($row));
229 }
230 return $rows;
231 }

References $db, $res, and $row.

Field Documentation

◆ $db

getID3_cached_sqlite3::$db
private

◆ $table

string getID3_cached_sqlite3::$table
private

table to use for caching

Definition at line 138 of file extension.cache.sqlite3.php.

Referenced by __construct().


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