function getid3_analyze_file in getID3() 7.2
Same name and namespace in other branches
- 7 getid3.module \getid3_analyze_file()
Takes a file entity object and returns ID3 data.
Parameters
$file:
Return value
null|array
1 call to getid3_analyze_file()
- getid3_file_presave in ./
getid3.module - Implements hook_file_presave().
File
- ./
getid3.module, line 115
Code
function getid3_analyze_file($file) {
// Initialize
$getID3 = getid3_instance();
$file_realpath = drupal_realpath($file->uri);
// Verify file exists, as external files are saved as managed files
// Ex: this prevents errors on media_youtube or media_vimeo entries.
if (file_exists($file_realpath)) {
// Analyze.
return $getID3
->analyze($file_realpath);
}
// If the file path isn't local
if ($file_realpath === FALSE) {
$file_urlpath = file_create_url($file->uri);
$tmp = file_directory_temp() . '/' . $file->filename;
if (file_put_contents($tmp, file_get_contents($file_urlpath, false, null, 0, 10))) {
$tagLen = getid3_calc(substr($tmp, 6, 4));
unlink($tmp);
file_put_contents($tmp, file_get_contents($file_urlpath, false, null, 0, $tagLen));
return $getID3
->analyze($tmp);
}
}
return NULL;
}