? .DS_Store
? 453458.patch
? providers/.DS_Store
Index: video_upload.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/video_upload/video_upload.admin.inc,v
retrieving revision 1.13.2.8.2.10
diff -u -p -r1.13.2.8.2.10 video_upload.admin.inc
--- video_upload.admin.inc	3 Oct 2010 16:48:57 -0000	1.13.2.8.2.10
+++ video_upload.admin.inc	3 Oct 2010 17:05:19 -0000
@@ -52,6 +52,19 @@ function _video_upload_admin_settings_fo
     '#default_value' => variable_get('video_upload_youtube_password', FALSE),
     '#required' => TRUE,
   );
+  $form['youtube']['video_upload_upload_published_only'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Only upload videos from published nodes'),
+    '#default_value' => variable_get('video_upload_upload_published_only', FALSE),
+    '#description' => t('If checked, videos for a node will not be uploaded to YouTube until the node is published.'),
+  );
+  $form['youtube']['video_upload_sync_status'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Synchronize the node published and YouTube private flags'),
+    '#default_value' => variable_get('video_upload_sync_status', FALSE),
+    '#description' => t("If checked, once a video has been uploaded to YouTube, the node's published setting will be synchronized with You Tube's private setting so that when a node is unpublished the video will be marked private and vice-versa."),
+  );
+
   return system_settings_form($form);
 }
 
@@ -300,8 +313,9 @@ function video_upload_admin_video_form()
  */
 function _video_upload_upload_all($fields) {
   $uploaded = 0;
+  $published_only = variable_get('video_upload_upload_published_only', FALSE);
   foreach ($fields as $field => $config) {
-    $result = _video_upload_query_videos($config, VIDEO_UPLOAD_STATUS_UPLOAD_PENDING);
+    $result = _video_upload_query_videos($config, VIDEO_UPLOAD_STATUS_UPLOAD_PENDING, $published_only);
     while ($video = db_fetch_object($result)) {
       $video->field = $config;
       if (video_upload_upload($config, $video)) {
@@ -484,7 +498,7 @@ function _video_upload_delete_rejected_v
  * @param string $video_status
  *   Video status
  */
-function _video_upload_query_videos($config, $status) {
+function _video_upload_query_videos($config, $status, $published_only = FALSE) {
   $db_info = $config['database_information'];
   $params[':video_id'] = $db_info['columns']['video_id']['column'];
   $params[':filefield'] = $db_info['columns']['fid']['column'];
@@ -492,6 +506,7 @@ function _video_upload_query_videos($con
   $params[':video_status_field_2'] = $db_info['columns']['video_status']['column'];
   $params[':video_status'] = $status;
   $multiple = $config['multiple'] ? ', t.delta' : '';
+  $published = $published_only ? ' AND n.status = 1 ' : '';
 
-  return db_query("SELECT t.%s AS video_id, t.nid, t.%s AS fid, t.%s AS video_status" . $multiple . " FROM {" . $db_info['table'] . "} t INNER JOIN {node} n ON t.vid = n.vid WHERE t.%s = '%s' AND t.%s IS NOT NULL", $params);
+  return db_query("SELECT t.%s AS video_id, t.nid, t.%s AS fid, t.%s AS video_status" . $multiple . " FROM {" . $db_info['table'] . "} t INNER JOIN {node} n ON t.vid = n.vid WHERE t.%s = '%s' AND t.%s IS NOT NULL" . $published, $params);
 }
Index: video_upload.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/video_upload/video_upload.module,v
retrieving revision 1.23.2.7.2.12
diff -u -p -r1.23.2.7.2.12 video_upload.module
--- video_upload.module	3 Oct 2010 15:30:25 -0000	1.23.2.7.2.12
+++ video_upload.module	3 Oct 2010 17:05:20 -0000
@@ -409,11 +409,24 @@ function video_upload_field($op, $node, 
         return;
       }
 
-      // Delete items from original node.
-      $orig = node_load($node->nid);
-      // If there are, figure out which ones must go.
-      if (!empty($orig->$field['field_name'])) {
-        foreach ($orig->$field['field_name'] as $oitem) {
+      $original_node = node_load($node->nid);
+
+      // If the node values that sync with the external video have changed, update the
+      // video status so that next time cron runs the updates are picked up.
+      $sync_status = variable_get('video_upload_sync_status', FALSE);
+      $changed = ($node->title != $original_node->title || $node->body != $original_node->body || ($sync_status && $node->status != $original_node->status));
+      if ($op == 'update' && $changed) {
+        foreach ($items as $key => $item) {
+          // We should only be updating videos that are synced or we could cause trouble
+          if ($items[$key]['video_status'] == VIDEO_UPLOAD_STATUS_OK_SYNCED) {
+            $items[$key]['video_status'] = VIDEO_UPLOAD_STATUS_OK;
+          }
+        }
+      }
+
+      // Delete items from original node if any. Figure out which ones must go
+      if (!empty($original_node->$field['field_name'])) {
+        foreach ($original_node->$field['field_name'] as $oitem) {
           if (isset($oitem['fid']) && !in_array($oitem['fid'], $curfids)) {
             // For hook_file_references, remember that this is being deleted.
             $oitem['field_name'] = $field['field_name'];
Index: providers/youtube/youtube.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/video_upload/providers/youtube/youtube.inc,v
retrieving revision 1.10.2.3.2.3
diff -u -p -r1.10.2.3.2.3 youtube.inc
--- providers/youtube/youtube.inc	14 May 2010 14:19:03 -0000	1.10.2.3.2.3
+++ providers/youtube/youtube.inc	3 Oct 2010 17:05:23 -0000
@@ -66,7 +66,7 @@ function video_upload_link_youtube($id) 
 }
 
 /**
- * Verify that an uploaded video 
+ * Verify that an uploaded video
  *   zend_gdata.inc
  */
 function video_upload_validate_youtube($id) {
@@ -245,6 +245,22 @@ function _video_upload_update_video_remo
     $update = TRUE;
   }
 
+  // If the video_upload_sync_status option has been chosen and the
+  // node's published status has changed then change the video's private flag.
+  // When private isVideoPrivate() = TRUE and node->status = FALSE
+  // So we need to update when they are equal, not different.
+  if (variable_get('video_upload_sync_status', FALSE)) {
+    if ($video->isVideoPrivate() == $node->status) {
+      if (!$node->status) {
+        $video->setVideoPrivate();
+      }
+      else {
+        $video->setVideoPublic();
+      }
+      $update = TRUE;
+    }
+  }
+
   if ($update) {
     // The video has been updated, send changes to YouTube.
     if (_video_upload_gdata_update_video($yt, $video)) {
