--- mm_flvtool2.module.orig	2008-03-10 22:10:47.000000000 +0000
+++ mm_flvtool2.module	2008-12-22 12:11:30.000000000 +0000
@@ -53,10 +53,9 @@ function mm_flvtool2_meta_add(&$file, $c
     // set status to 0 so we know the file is bad
     $file['status'] = 0;
   }
-  
+
   // only run this on flv files  
   if (strtolower($path_parts['extension']) == 'flv') {
-    require_once(drupal_get_path('module', 'mm_flvtool2') .'/mm_flvtool2.inc');
     $tags = mm_flvtool2_write_tags($file['harvest_file']);      
     // add the meta data to the file object
     if(is_array($tags)) {      
@@ -65,7 +64,7 @@ function mm_flvtool2_meta_add(&$file, $c
     }    
 
     $file['process_file'] = $file['harvest_file'];
-    $file['status'] = 1;
+    $file['status'] = 4;
 
   }    
   else {
@@ -79,7 +78,7 @@ function mm_flvtool2_meta_add(&$file, $c
   $file['process_action'] = 1;
   $file['process_module'] = 'mm_flvtool2';
 
-  return $file;
+  return $file['process_file'];
 }
 
 
@@ -104,4 +103,78 @@ function mm_flvtool2_admin() {
     '#description' => 'Enter the absolute path to the FLVTool2 executable.'
   );
   return $form;
+}
+
+// Integrated working functions from include
+/**
+ * writes meta tags to an flv file
+ * @param $file_path is the path to the file
+ * @return is the parsed xml from the command, false if there is an error
+ */
+function mm_flvtool2_write_tags($file_path) {
+  $output = mm_flvtool2_run_command($file_path, 'UPx');
+
+  if ($output) {
+    $tags = mm_flvtool2_parse_output($output);
+    return $tags;
+  }
+  return false;
+}
+
+
+/**
+ * takes the XML output from flvtool2 and returns
+ * a structured array of index and values to the xml
+ * @param $output is the output from the flvtool2 command, assumes xml
+ * @return array of the xml index and the xml values
+ */
+function mm_flvtool2_parse_output($output) {
+  $output = implode("\n", $output);
+  $parse = xml_parser_create();
+  xml_parse_into_struct($parse, $output, $values, $index);
+  xml_parser_free($parse);
+
+  // returning one array of indexes => values
+  foreach($index as $attribute => $keys) {
+        foreach($keys as $i => $key) {
+      $combined[strtolower($attribute)][$i] = $values[$key];
+    }
+  }
+  return $combined;
+}
+
+/**
+ * this executes the flvtool command
+ * @param $file_path is the file to perform the operation on
+ * @param $options are the optioons executed with
+ * @return output from the command
+ */
+function mm_flvtool2_run_command($file_path, $options) {
+  $output = array();
+  $return_var = 0;
+
+  // get paths
+  $command[] = variable_get('mm_flvtool2_ruby_path', '/usr/bin/ruby');
+  $command[] = variable_get('mm_flvtool2_path', '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/flvtool2');
+  // options
+  $command[] = '-'. $options;
+  // file
+  $command[] = '"'. $file_path .'"';
+  // output
+  $command[] = "2>&1";
+
+  // run the command
+  exec(implode(' ', $command), $output, $return_var);
+
+  if ($return_var) {
+    $message = t("Trouble running command: %cmd.  Output was %output.  Return_var was %return for file %file.",
+      array('%cmd' => $command,
+        '%output' => implode(', ', $output),
+        '%return' => $return_var,
+        '%file' => $file_path));
+    watchdog('mm_flvtool2', $message);
+  }
+  else {
+    return $output;
+  }
 }
\ No newline at end of file
