function filefield_meta in FileField 6.3
Same name and namespace in other branches
- 5.2 filefield_meta/filefield_meta.module \filefield_meta()
- 6.2 filefield_meta/filefield_meta.module \filefield_meta()
Adds the width, height and duration to the file's data property.
1 call to filefield_meta()
- filefield_meta_file_insert in filefield_meta/
filefield_meta.module - Implementation of FileField's hook_file_insert().
10 string references to 'filefield_meta'
- FileFieldTestCase::setUp in tests/
filefield.test - Implementation of setUp().
- FileFieldValidateTestCase::setUp in tests/
filefield.test - Implementation of setUp().
- filefield_meta_file_insert in filefield_meta/
filefield_meta.module - Implementation of FileField's hook_file_insert().
- filefield_meta_init in filefield_meta/
filefield_meta.module - Implementation of hook_init().
- filefield_meta_install in filefield_meta/
filefield_meta.install - Implementation of hook_install().
File
- filefield_meta/
filefield_meta.module, line 103 - FileField Meta: Add Video Support to File Field.
Code
function filefield_meta(&$file) {
$file->data = !empty($file->data) ? $file->data : array();
// Skip any attempts at adding information if the file is not actually
// located on this server.
if (!file_exists($file->filepath)) {
return;
}
$info = getid3_analyze($file->filepath);
$file->data['width'] = $file->data['height'] = $file->data['duration'] = 0;
if (isset($info['video']['resolution_x'])) {
$file->data['width'] = $info['video']['resolution_x'];
$file->data['height'] = $info['video']['resolution_y'];
}
elseif (isset($info['video']['streams'])) {
foreach ($info['video']['streams'] as $stream) {
$file->data['width'] = max($file->data['width'], $stream['resolution_x']);
$file->data['height'] = max($file->data['height'], $stream['resolution_y']);
}
}
if (isset($info['playtime_seconds'])) {
$file->data['duration'] = $info['playtime_seconds'];
}
// Initialize fields.
$file->data['audio_format'] = $file->data['audio_channel_mode'] = $file->data['audio_bitrate_mode'] = '';
$file->data['audio_sample_rate'] = $file->data['audio_bitrate'] = 0;
if (isset($info['audio'])) {
$file->data['audio_format'] = $info['audio']['dataformat'];
//e.g. mp3
$file->data['audio_sample_rate'] = $info['audio']['sample_rate'];
//e.g. 44100
$file->data['audio_channel_mode'] = $info['audio']['channelmode'];
// e.g. mono
$file->data['audio_bitrate'] = isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : NULL;
//e.g. 64000
$file->data['audio_bitrate_mode'] = isset($info['audio']['bitrate_mode']) ? $info['audio']['bitrate_mode'] : NULL;
//e.g. cbr
}
// Add in arbitrary ID3 tags.
if (isset($info['tags_html'])) {
// We use tags_html instead of tags because it is the most reliable data
// source for pulling in non-UTF-8 characters according to getID3 docs.
foreach ($info['tags_html'] as $type => $values) {
// Typically $type may be IDv2 (for MP3s) or quicktime (for AAC).
foreach ($values as $key => $value) {
$value = isset($value[0]) ? (string) $value[0] : (string) $value;
if (!empty($value) && $key != 'coverart' && $key != 'music_cd_identifier') {
$file->data['tags'][$key] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
}
}
}
}
}