From 5213a46fbd956a11648ec5b978680ab74c1663fa Mon Sep 17 00:00:00 2001
From: Andrew Berry <deviantintegral@gmail.com>
Date: Fri, 16 Sep 2011 15:53:40 -0400
Subject: [PATCH 1/3] Issue #1281556: Fix saving NULL video lengths for videos
 being processed.

---
 ooyala.module |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/ooyala.module b/ooyala.module
index caac74c..08b1ac3 100755
--- a/ooyala.module
+++ b/ooyala.module
@@ -343,7 +343,16 @@ function ooyala_field_sanitize($entity_type, $entity, $field, $instance, $langco
   module_load_include('inc', 'ooyala', 'includes/ooyala.api');
 
   foreach ($items as $delta => $item) {
-    $items[$delta]['length'] = empty($items[$delta]['length']) ? ooyala_api_video_property($item['value'], 'length') : $items[$delta]['length'];
+    // We might not have a length yet from Ooyala depending on the processing
+    // of the content. If Ooyala doesn't have a length, unset the value so
+    // Field API will save NULL to the database.
+    if (empty($items[$delta]['length'])) {
+      $length = ooyala_api_video_property($item['value'], 'length');
+      if ($length === FALSE) {
+        unset($items[$delta]['length']);
+      }
+    }
+
     $items[$delta]['status'] = empty($items[$delta]['status']) ? ooyala_api_video_property($item['value'], 'status') : $items[$delta]['status'];
 
     if (isset($item['thumbnail_list'])) {
-- 
1.7.6.1


From f258c117a3f6a18dfe157fcb4b7fa60bad610d99 Mon Sep 17 00:00:00 2001
From: Andrew Berry <deviantintegral@gmail.com>
Date: Mon, 19 Sep 2011 12:20:49 -0400
Subject: [PATCH 2/3] Issue #1281556: Set the video length if Ooyala has
 determined it.

---
 ooyala.module |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/ooyala.module b/ooyala.module
index 08b1ac3..4b2ab8e 100755
--- a/ooyala.module
+++ b/ooyala.module
@@ -351,6 +351,9 @@ function ooyala_field_sanitize($entity_type, $entity, $field, $instance, $langco
       if ($length === FALSE) {
         unset($items[$delta]['length']);
       }
+      else {
+        $items[$delta]['length'] = $length;
+      }
     }
 
     $items[$delta]['status'] = empty($items[$delta]['status']) ? ooyala_api_video_property($item['value'], 'status') : $items[$delta]['status'];
-- 
1.7.6.1


From 9bb2a1660c89709fcf1117473cb5b716ae8a4315 Mon Sep 17 00:00:00 2001
From: Andrew Berry <deviantintegral@gmail.com>
Date: Thu, 22 Sep 2011 14:44:52 -0400
Subject: [PATCH 3/3] Issue #1281556: Handle thumbnails not being processed by
 Ooyala properly.

---
 includes/ooyala.api.inc |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/includes/ooyala.api.inc b/includes/ooyala.api.inc
index 3350981..2eb2b70 100644
--- a/includes/ooyala.api.inc
+++ b/includes/ooyala.api.inc
@@ -578,6 +578,10 @@ function ooyala_api_fetch_image($embedcode) {
       $thumb_path = FALSE;
     }
   }
+  elseif ($response->data == 'not ready yet') {
+    // The thumbnail isn't ready yet to be displayed.
+    return FALSE;
+  }
   // Check if this isn't actually a video at all, but a channel. In which case
   // start over and try to retreive the thumbnail of the first video.
   elseif ($channel = ooyala_api_channel_load($embedcode)) {
-- 
1.7.6.1

