<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -15,3 +15,4 @@ config/panda_init_*.rb
 panda_all_staging_nginx.conf
 public/images/tmp/*jpg
 public/store
+public/tmp</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,7 @@ class Thumbnail &lt; Application
     @video.save
     
     @video.successful_encodings.each do | video |
-      video.upload_thumbnail_to_s3
+      video.clipping.upload_to_store
     end
     
     redirect url(:video, @video.key)</diff>
      <filename>app/controllers/thumbnail.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,10 @@ class Video &lt; SimpleDB::Base
     'videos'
   end
   
+  def clipping
+    Clipping.new(self)
+  end
+  
   # Classification
   # ==============
   
@@ -90,7 +94,7 @@ class Video &lt; SimpleDB::Base
 
   # Location to store video file fetched from S3 for encoding
   def tmp_filepath
-    Panda::Config[:tmp_video_dir] / self.filename
+    Panda::Config[:private_tmp_path] / self.filename
   end
   
   # Has the actual video file been uploaded for encoding?
@@ -123,22 +127,6 @@ class Video &lt; SimpleDB::Base
     self.audio_bitrate.to_i * 1024
   end
   
-  def screenshot
-    self.filename + &quot;.jpg&quot;
-  end
-  
-  def thumbnail
-    self.filename + &quot;_thumb.jpg&quot;
-  end
-  
-  def screenshot_url
-    Store.url(self.screenshot)
-  end
-  
-  def thumbnail_url
-    Store.url(self.thumbnail)
-  end
-  
   # Encding attr helpers
   # ====================
   
@@ -148,7 +136,7 @@ class Video &lt; SimpleDB::Base
   
   def embed_html
     return nil unless self.encoding?
-    %(&lt;embed src=&quot;#{Store.url('flvplayer.swf')}&quot; width=&quot;#{self.width}&quot; height=&quot;#{self.height}&quot; allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; flashvars=&quot;&amp;displayheight=#{self.height}&amp;file=#{self.url}&amp;width=#{self.width}&amp;height=#{self.height}&amp;image=#{self.screenshot_url}&quot; /&gt;)
+    %(&lt;embed src=&quot;#{Store.url('flvplayer.swf')}&quot; width=&quot;#{self.width}&quot; height=&quot;#{self.height}&quot; allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; flashvars=&quot;&amp;displayheight=#{self.height}&amp;file=#{self.url}&amp;width=#{self.width}&amp;height=#{self.height}&amp;image=#{self.clipping.url(:screenshot)}&quot; /&gt;)
   end
   
   def embed_js
@@ -159,7 +147,7 @@ class Video &lt; SimpleDB::Base
       var flashvars = {};
       
       flashvars.file = &quot;#{self.url}&quot;;
-      flashvars.image = &quot;#{self.screenshot_url}&quot;;
+      flashvars.image = &quot;#{self.clipping.url(:screenshot)}&quot;;
       flashvars.width = &quot;#{self.width}&quot;;
       flashvars.height = &quot;#{self.height}&quot;;
       flashvars.fullscreen = &quot;true&quot;;
@@ -191,62 +179,22 @@ class Video &lt; SimpleDB::Base
     false
   end
   
-  def upload_thumbnail_to_s3
-    percentage = (self.parent_video.thumbnail_position || self.default_thumbnail_position)
-    Store.set(self.screenshot, self.screenshot_tmp_filepath(percentage))
-    Store.set(self.thumbnail, self.thumbnail_tmp_filepath(percentage))
-  end
-  
-  def capture_and_resize_thumbnail(percentage)
-    raise RuntimeError, &quot;You may not call capture_and_resize_thumbnail unless the video is available locally&quot; unless File.exists?(self.tmp_filepath)
-    
-    t = RVideo::Inspector.new(:file =&gt; self.tmp_filepath)
-    t.capture_frame(&quot;#{percentage}%&quot;, screenshot_tmp_filepath(percentage))
+  def thumbnail_percentages
+    choose_thumbnail = Panda::Config[:choose_thumbnail]
     
-    constrain_to_height = Panda::Config[:thumbnail_height_constrain].to_f
-    width = (self.width.to_f/(self.height.to_f/constrain_to_height)).to_i
-    height = constrain_to_height.to_i
+    return [self.default_thumbnail_position] if choose_thumbnail == false
     
-    GDResize.new.resize(self.screenshot_tmp_filepath(percentage), self.thumbnail_tmp_filepath(percentage), [width,height])
-  end
-  
-  def screenshot_tmp_filepath(percentage)
-    &quot;public&quot; + tmp_images_dir / &quot;#{self.filename}_#{percentage}.jpg&quot;
-  end
-  
-  def thumbnail_tmp_filepath(percentage)
-    &quot;public&quot; + tmp_images_dir / &quot;#{self.filename}_#{percentage}_thumb.jpg&quot;
-  end
-  
-  def thumbnail_tmp_url(percentage)
-    tmp_images_dir / &quot;#{self.filename}_#{percentage}_thumb.jpg&quot;
-  end
-  
-  def tmp_images_dir
-    &quot;/images/tmp&quot;
-  end
-  
-  def default_thumbnail_position
-    50.0
-  end
-  
-  def thumbnail_percentages
-    return [self.default_thumbnail_position] if Panda::Config[:choose_thumbnail] == false
-    divider = 100.0 / (Panda::Config[:choose_thumbnail] + 2).to_f
-    percentages = (1..Panda::Config[:choose_thumbnail]).map {|i| i * divider }
+    divider = 100.0 / (choose_thumbnail + 2).to_f
+    percentages = (1..choose_thumbnail).map {|i| i * divider }
   end
   
   def generate_thumbnail_selection
     self.thumbnail_percentages.each do |percentage|
-      capture_and_resize_thumbnail(percentage)
+      self.clipping.capture(percentage)
+      self.clipping.resize(percentage)
     end
   end
   
-  # def cleanup_thumbnail_selection
-  #   FileUtils.rm  Dir.glob(&quot;public/images/tmp/#{self.filename}*.jpg&quot;)
-  # end
-    
-  
   # Uploads
   # =======
 
@@ -594,8 +542,8 @@ RESPONSE
       end
       
       self.upload_to_s3
-      self.generate_thumbnail_selection # Generate thumbnails for all percentage options
-      self.upload_thumbnail_to_s3
+      self.generate_thumbnail_selection
+      self.clipping.upload_to_store
       
       self.notification = 0
       self.status = &quot;success&quot;</diff>
      <filename>app/models/video.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@
 	&lt;/tr&gt;
 &lt;% encodings.each do |v| %&gt;
 	&lt;tr&gt;
-	  &lt;td&gt;&lt;div class=&quot;thumb&quot;&gt;&lt;a href=&quot;/videos/&lt;%= v.key %&gt;&quot;&gt;&lt;img src=&quot;&lt;%= v.thumbnail_url %&gt;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;
+	  &lt;td&gt;&lt;div class=&quot;thumb&quot;&gt;&lt;a href=&quot;/videos/&lt;%= v.key %&gt;&quot;&gt;&lt;img src=&quot;&lt;%= v.clipping.url(:thumbnail) %&gt;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;
 		&lt;td&gt;
 			&lt;a href=&quot;/videos/&lt;%= v.key %&gt;&quot; class=&quot;filename&quot;&gt;&lt;%= v.original_filename || &quot;No filename&quot; %&gt;&lt;/a&gt;
 			&lt;span&gt;&lt;%= v.duration_str %&gt;&lt;/span&gt;</diff>
      <filename>app/views/encodings/_recently_encoded_list.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,6 @@
 
 &lt;ul id=&quot;screenshots&quot;&gt;
   &lt;% @percentages.each do | percentage |%&gt;
-    &lt;li&gt;&lt;%= link_to image_tag(@video.thumbnail_tmp_url(percentage)), &quot;/videos/#{@video.key}/thumbnail/update?percentage=#{percentage}&amp;iframe=#{params[:iframe]}&quot; %&gt;&lt;/li&gt;
+    &lt;li&gt;&lt;%= link_to image_tag(@video.clipping.tmp_url(:thumbnail)), &quot;/videos/#{@video.key}/thumbnail/update?percentage=#{percentage}&amp;iframe=#{params[:iframe]}&quot; %&gt;&lt;/li&gt;
   &lt;% end %&gt;
 &lt;/ul&gt;
\ No newline at end of file</diff>
      <filename>app/views/thumbnail/edit.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,6 @@
 
 &lt;ul id=&quot;screenshots&quot;&gt;
   &lt;% @percentages.each do | percentage |%&gt;
-    &lt;li&gt;&lt;%= link_to image_tag(@video.thumbnail_tmp_url(percentage)), &quot;/videos/#{@video.key}/thumbnail/create?percentage=#{percentage}&amp;iframe=#{params[:iframe]}&quot; %&gt;&lt;/li&gt;
+    &lt;li&gt;&lt;%= link_to image_tag(@video.clipping.tmp_url(:thumbnail, percentage)), &quot;/videos/#{@video.key}/thumbnail/create?percentage=#{percentage}&amp;iframe=#{params[:iframe]}&quot; %&gt;&lt;/li&gt;
   &lt;% end %&gt;
 &lt;/ul&gt;
\ No newline at end of file</diff>
      <filename>app/views/thumbnail/new.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,12 @@ describe Video do
     Store.stub!(:delete).and_return(true)
   end
   
+  describe &quot;clipping&quot; do
+    it &quot;should return a clipping&quot; do
+      @video.clipping.should be_kind_of(Clipping)
+    end
+  end
+  
   # Classification
   # ==============
   
@@ -128,25 +134,6 @@ describe Video do
     @video.resolution.should be_nil
   end
   
-  # def video_bitrate_in_bits
-  # def audio_bitrate_in_bits
-  
-  it &quot;screenshot&quot; do
-    @video.screenshot.should == 'abc.mov.jpg'
-  end
-  
-  it &quot;thumbnail&quot; do
-    @video.thumbnail.should == 'abc.mov_thumb.jpg'
-  end
-  
-  it &quot;screenshot_url&quot; do
-    @video.screenshot_url.should == &quot;http://videos.pandastream.com/abc.mov.jpg&quot;
-  end
-  
-  it &quot;thumbnail_url&quot; do
-    @video.thumbnail_url.should == &quot;http://videos.pandastream.com/abc.mov_thumb.jpg&quot;
-  end
-  
   # def set_encoded_at
   
   # Encding attr helpers
@@ -173,25 +160,7 @@ describe Video do
   it &quot;should upload_to_s3&quot;
   
   it &quot;should fetch_from_s3&quot;
-  
-  it &quot;should capture_thumbnail_and_upload_to_s3&quot; do
-    inspector = mock(RVideo::Inspector)
-    inspector.should_receive(:capture_frame).with('50%', '/tmp/abc.mov.jpg')
-    RVideo::Inspector.should_receive(:new).with(:file =&gt; '/tmp/abc.mov').and_return(inspector)
     
-    gd = mock(GDResize)
-    gd.should_receive(:resize).with('/tmp/abc.mov.jpg', '/tmp/abc.mov_thumb.jpg', [168,126]) # Dimensions based on thumbnail_height_constrain of 126
-    GDResize.should_receive(:new).and_return(gd)
-    
-    Store.should_receive(:set).with('abc.mov.jpg', '/tmp/abc.mov.jpg').and_return(true)
-    Store.should_receive(:set).with('abc.mov_thumb.jpg', '/tmp/abc.mov_thumb.jpg').and_return(true)
-
-    parent_video = mock (Video)
-    parent_video.should_receive(:thumbnail_position).and_return(false)
-    @video.should_receive(:parent_video).and_return(parent_video)
-    @video.capture_thumbnail_and_upload_to_s3.should be_true
-  end
-  
   # Uploads
   # =======
   
@@ -294,9 +263,6 @@ describe Video do
     lambda {@video.send_notification}.should raise_error(StandardError)
   end
   
-  # it &quot;should send_status_update_to_client&quot; do
-    
-  
   # Encoding
   # ========
   
@@ -357,7 +323,11 @@ describe Video do
     encoding.should_receive(:encode_flv_flash)
   
     encoding.should_receive(:upload_to_s3)
-    encoding.should_receive(:capture_thumbnail_and_upload_to_s3)
+    encoding.should_receive(:generate_thumbnail_selection)
+    clipping = returning(mock(Clipping)) do |c|
+      c.should_receive(:upload_to_store)
+    end
+    encoding.should_receive(:clipping).and_return(clipping)
     
     encoding.should_receive(:notification=).with(0)
     encoding.should_receive(:status=).with(&quot;success&quot;)</diff>
      <filename>spec/models/video_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>32ad89fbf287f0e1527f919975b8c9f689a44753</id>
    </parent>
  </parents>
  <author>
    <name>Martyn Loughran</name>
    <email>martyn@new-bamboo.co.uk</email>
  </author>
  <url>http://github.com/newbamboo/panda/commit/7e3b778d5d847a4e354764d180e379b4ae178477</url>
  <id>7e3b778d5d847a4e354764d180e379b4ae178477</id>
  <committed-date>2008-10-07T09:09:14-07:00</committed-date>
  <authored-date>2008-10-07T09:09:14-07:00</authored-date>
  <message>Integrated Clipping object into existing code (removed lots of code from Video)</message>
  <tree>7c70d5bebb21fddc451e86bc127b6d14f0b0300a</tree>
  <committer>
    <name>Martyn Loughran</name>
    <email>martyn@new-bamboo.co.uk</email>
  </committer>
</commit>
