Esempio n. 1
0
 /**
  * analyze MP3 file, and return MP3 tag info
  *
  * @param   [auto detect] a file path or a file object is acceptable
  * @return  null or an array of MP3 info
  */
 public function analyzeMp3($file_para = '')
 {
     // if no path specified, return 'null'
     if (empty($file_para)) {
         return null;
     }
     // we need file path for GetId3
     $filepath = is_object($file_para) ? $file_para->getRealPath() : realpath($file_para);
     // initialize Id3 helper, and then analyze
     $getId3 = new GetId3();
     $getId3->setOptionMD5Data(true)->setOptionMd5DataSource(true)->setEncoding('UTF-8');
     $raw_info = $getId3->analyze($filepath);
     // read other important info from mp3 tags, if possible
     if (isset($raw_info['tags']['id3v2'])) {
         $song_info = array('title' => isset($raw_info['tags']['id3v2']['title']) ? $raw_info['tags']['id3v2']['title'][0] : '', 'artist' => isset($raw_info['tags']['id3v2']['artist']) ? $raw_info['tags']['id3v2']['artist'][0] : '', 'album' => isset($raw_info['tags']['id3v2']['album']) ? $raw_info['tags']['id3v2']['album'][0] : '', 'genre' => isset($raw_info['tags']['id3v2']['genre']) ? $raw_info['tags']['id3v2']['genre'][0] : '', 'length' => strlen($raw_info['playtime_string']) < 6 ? '00:' . $raw_info['playtime_string'] : $raw_info['playtime_string']);
         // $song_info['length'] = new \DateTime($song_info['length']);
     } else {
         // no info, and set just a null
         $song_info = null;
     }
     return $song_info;
 }
 function getFileInfo($filePath)
 {
     $this->load->library('getid3/getid3');
     $getID3 = new GetId3();
     $ThisFileInfo = $getID3->analyze($filePath);
     return $ThisFileInfo;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * analyze file and cache them, if cached pull from the db
  *
  * @param  type    $filename
  *
  * @return bool
  */
 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;
 }