Index: video.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/video/video.module,v
retrieving revision 1.16
diff -u -p -r1.16 video.module
--- video.module	19 Sep 2005 21:41:29 -0000	1.16
+++ video.module	28 Sep 2005 17:31:22 -0000
@@ -1242,3 +1242,54 @@ function _video_page_goto($id, $type = '
   }
   return false;
 }
+
+/**
+ * Implementation of hook_nodeapi().
+ * We use this to append <enclosure> tags to the RSS feeds Drupal generates.
+ */
+function video_nodeapi(&$node, $op, $arg) {
+  switch ($op) {
+    case 'rss item': 
+      if ($node->type == 'video') {
+        // TODO: Only use file_create_url() on local files!
+        $attributes = array('url' => file_create_url($node->vidfile),
+                            'length' => $node->size);
+        $mime_type = _video_get_mime_type($node);
+        if ($mime_type) {
+          $attributes['type'] = $mime_type;
+        }
+        return array(array('key' => 'enclosure', 'attributes' => $attributes));
+      }
+  }
+}
+
+/**
+ * Returns the correct mime-type for the video. Returns false if the
+ * mime-type cannot be detected.
+ */
+function _video_get_mime_type($node) {
+  switch (_video_get_filetype($node->vidfile)) {
+    case 'mov':
+      return 'video/quicktime';
+      break;
+    case 'rm':
+      return 'application/vnd.rn-realmedia';
+      break;
+    case 'flv':
+      // TODO: Is 'video/x-flv' the correct one?
+      return 'flv-application/octet-stream';
+      break;
+    case 'wmv':
+      return 'video/x-ms-wmv';
+      break;
+    case 'youtube':
+      // We can't support this properly, so return false.
+      return false;
+      break;
+    default:
+      // We couldn't detect the mime-type, so return false.
+      return false;
+      break;
+  }
+}
+
