Skip to content

Commit

Permalink
Fix issue with snapshots not being persisted.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmanley committed May 5, 2012
1 parent 94bea7a commit 02f9293
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/models/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def set_metadata
raw_response = %x[mediainfo #{file_path.shellescape} --Output=XML]
parsed_response = Nori.parse(raw_response)[:mediainfo][:file]
parsed_response[:tracks] = parsed_response.delete(:track)
general = parsed_response[:tracks].find {|track| track[:type].eql?('General') && track.delete(:type) }
general = parsed_response[:tracks].find { |track| track[:type].eql?('General') && track.delete(:type) }
parsed_response.merge!(parsed_response[:tracks].delete(general))
self.file_metadata = parsed_response
rescue StandardError => e
Expand Down
2 changes: 0 additions & 2 deletions app/models/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Snapshot

field :video_time, type: Float

before_save :generate_image

def generate_image
Dir.mktmpdir do |dir|
snapshot_path = File.join(dir, "#{File.basename(media.file_path)}_snapshot#{video_time}.png")
Expand Down
10 changes: 4 additions & 6 deletions app/models/snapshot_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class SnapshotIndex
include Mongoid::Timestamps

embedded_in :media, class_name: 'Media'
embeds_many :snapshots
embeds_many :snapshots, cascade_callbacks: true

mount_uploader :image, ImageUploader

Expand All @@ -21,17 +21,15 @@ def create_snapshots
snapshot_count, video_time = 0, 0

until snapshot_count == total_snapshots
snapshot = Snapshot.new

snapshot_count += 1

video_time += increment
video_time = (video_time - increment / total_snapshots).floor
snapshot.video_time = video_time

self.snapshots << snapshot
snapshot = self.snapshots.new(video_time: video_time)
snapshot.generate_image
snapshot.save
end
save
end

def create_index_image
Expand Down
14 changes: 2 additions & 12 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::MimeTypes
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper

process :set_content_type

version :thumb do
process resize_to_fit: [600, 600]
resize_to_fit(600, 600)
end

def store_dir
Expand All @@ -22,15 +23,4 @@ def default_url
def extension_white_list
%w(jpg jpeg gif png)
end

# The following methods are needed for asset path helpers to work (eg. image_path)
# See https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_view/helpers/asset_tag_helper.rb#L453
private
def controller
nil
end

def config
Rails.application.config
end
end

0 comments on commit 02f9293

Please sign in to comment.