summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filefield_meta/filefield_meta.info5
-rw-r--r--filefield_meta/filefield_meta.install21
-rw-r--r--filefield_meta/filefield_meta.module75
3 files changed, 101 insertions, 0 deletions
diff --git a/filefield_meta/filefield_meta.info b/filefield_meta/filefield_meta.info
new file mode 100644
index 0000000..bb223d9
--- /dev/null
+++ b/filefield_meta/filefield_meta.info
@@ -0,0 +1,5 @@
+; $Id$
+name = FileField - Meta
+description = Add metadata gathering and storage to filefield.
+dependencies = content filefield getid3
+package = CCK
diff --git a/filefield_meta/filefield_meta.install b/filefield_meta/filefield_meta.install
new file mode 100644
index 0000000..8d45e77
--- /dev/null
+++ b/filefield_meta/filefield_meta.install
@@ -0,0 +1,21 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function filefield_meta_install() {
+ db_query('CREATE TABLE {filefield_meta} (
+ fid INT UNSIGNED NOT NULL,
+ width INT UNSIGNED NOT NULL,
+ height INT unsigned NOT NULL,
+ duration FLOAT(53),
+ PRIMARY KEY (fid)
+ )
+ ');
+}
+
+function filefield_meta_uninstall() {
+ db_query('DROP TABLE IF EXISTS {filefield_meta_backup}');
+ db_query('ALTER TABLE {filefield_meta} RENAME TO {filefield_meta_bak}');
+}
diff --git a/filefield_meta/filefield_meta.module b/filefield_meta/filefield_meta.module
new file mode 100644
index 0000000..5ac88c0
--- /dev/null
+++ b/filefield_meta/filefield_meta.module
@@ -0,0 +1,75 @@
+<?php // $Id$
+
+/**
+ * Add Video Support to File Field.
+ */
+
+/**
+ * Implementation of hook_filefield
+ *
+ * @param op
+ * - file_save
+ * - file_delete
+ * - file_prepare
+ * - file_validate
+ * - file_load
+ * - file_form
+ * - delete
+ *
+ * @param node
+ * @param field
+ * @param file
+ * @param form
+ */
+
+function filefield_meta_filefield($op, &$node, $field, &$file, &$form = NULL) {
+ $args = func_get_args();
+
+
+ switch($op) {
+ case 'file_form':
+ $form['file_preview']['#value'] = '';
+ $form['url']['#value'] .= '<br />width: '. $file['width'] .'; height: '. $file['height'] .'; duration: '. $file['duration'];
+ $form['width'] = array('#type' => 'hidden', '#value' => $file['width']);
+ $form['height'] = array('#type' => 'hidden', '#value' => $file['height']);
+ $form['duration'] = array('#type' => 'hidden', '#value' => $file['duration']);
+ break;
+
+ case 'file_prepare':
+ filefield_meta($file);
+ return $file;
+ break;
+
+ case 'file_save':
+ db_query('INSERT INTO {filefield_meta} (fid, width, height, duration) VALUES (%d, %d, %d, %d)', $file['fid'], $file['width'], $file['height'], $file['duration']);
+ break;
+
+ case 'file_delete':
+ db_query('DELETE FROM {filefield_meta} WHERE fid = %d', $file['fid']);
+ break;
+
+ case 'file_load':
+ $meta = db_fetch_array(db_query('SELECT * FROM {filefield_meta} WHERE fid = %d', $file['fid']));
+ if ($meta) {
+ return $meta;
+ }
+ break;
+ }
+}
+
+function filefield_meta(&$file) {
+ $info = getid3_analyze($file['filepath']);
+ $file['width'] = $file['height'] = $file['duration'] = 0;
+ if (isset($info['video']['resolution_x'])) {
+ $file['width'] = $info['video']['resolution_x'];
+ $file['height'] = $info['video']['resolution_y'];
+ }
+ else if (isset($info['video']['streams'])) {
+ foreach($info['video']['streams'] as $stream) {
+ $file['width'] = max($file['width'], $stream['resolution_x']);
+ $file['height'] = max($file['height'], $stream['resolution_y']);
+ }
+ }
+ $file['duration'] = $info['playtime_seconds'];
+};
+