Skip to content
Snippets Groups Projects
Commit ab40d0f7 authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

Add File_Format Method & Fix Default_Thumbnail

parent 2be39c0a
No related branches found
No related tags found
No related merge requests found
...@@ -3,22 +3,27 @@ class ThumbnailGeneratorWorker ...@@ -3,22 +3,27 @@ class ThumbnailGeneratorWorker
include Sidekiq::Worker include Sidekiq::Worker
include RepositoriesProxy include RepositoriesProxy
include Thumbnail::Creation include Thumbnail::Creation
include Thumbnail::Formats
def perform(learning_object_id) def perform(learning_object_id)
item = learning_object_repository.find(learning_object_id) item = learning_object_repository.find(learning_object_id)
filename = item.get_bitstream_filename_of "ORIGINAL" filename = item.get_bitstream_filename_of "ORIGINAL"
size = "360x360" size = "530x298"
begin unless accepted_formats.include? file_format filename
retrieve_link = item.get_bitstream_retrievelink_of "ORIGINAL" item.thumbnail = default_thumbnail
file = download_bitstream(retrieve_link,filename)
rescue
puts "ERROR!!! Some error occurred during file download."
else else
item.thumbnail = generate_thumbnail(file,filename,size) begin
delete_downloaded_bitstream(file) retrieve_link = item.get_bitstream_retrievelink_of "ORIGINAL"
file = download_bitstream(retrieve_link,filename)
rescue
puts "ERROR!!! Some error occurred during file download."
else
item.thumbnail = generate_thumbnail(file,filename,size)
delete_downloaded_bitstream(file)
end
end end
learning_object_repository.update_property(item,"thumbnail",item.thumbnail) learning_object_repository.update_property(item,"thumbnail",item.thumbnail)
......
...@@ -6,7 +6,7 @@ namespace :thumbnail do ...@@ -6,7 +6,7 @@ namespace :thumbnail do
include RepositoriesProxy include RepositoriesProxy
# Quantity of items fetched on each iteration # Quantity of items fetched on each iteration
limit = 1000 limit = 500
# Start point from where items will be fetched # Start point from where items will be fetched
offset = 0 offset = 0
......
...@@ -4,7 +4,7 @@ module Thumbnail ...@@ -4,7 +4,7 @@ module Thumbnail
include Formats include Formats
def generate_thumbnail(input, filename, size) def generate_thumbnail(input, filename, size)
unless accepted_formats.include? File.extname(filename) unless accepted_formats.include? file_format(filename)
return default_thumbnail return default_thumbnail
else else
thumbnail = thumbnail_path(filename, size) thumbnail = thumbnail_path(filename, size)
...@@ -24,6 +24,10 @@ module Thumbnail ...@@ -24,6 +24,10 @@ module Thumbnail
end end
def default_thumbnail
@default_thumbnail ||= nil
end
private private
def generate_video_thumbnail(input,output,size) def generate_video_thumbnail(input,output,size)
...@@ -52,10 +56,6 @@ module Thumbnail ...@@ -52,10 +56,6 @@ module Thumbnail
thumbnail_path = "#{thumbnails_dir}/#{thumbnail_name}_#{size}.jpg" thumbnail_path = "#{thumbnails_dir}/#{thumbnail_name}_#{size}.jpg"
end end
def default_thumbnail
@default_thumbnail ||= "#{thumbnails_dir}/default_thumbnail.jpg"
end
def thumbnails_dir def thumbnails_dir
@thumbnails_dir ||= "/thumbnails" @thumbnails_dir ||= "/thumbnails"
end end
......
module Thumbnail module Thumbnail
module Formats module Formats
def file_format file
unless file.nil?
file_format = File.extname(file)
else
file_format = ""
end
file_format
end
def accepted_video_formats def accepted_video_formats
lower = [".mp4", ".wmv", ".3gp", ".asf", ".avi", ".flv", ".mov", ".mpg", ".mpeg", ".rmvb", ".vob", ".webm"] lower = [".mp4", ".wmv", ".3gp", ".asf", ".avi", ".flv", ".mov", ".mpg", ".mpeg", ".rmvb", ".vob", ".webm"]
upper = [".MP4", ".WMV", ".3GP", ".ASF", ".AVI", ".FLV", ".MOV", ".MPG", ".MPEG", ".RMVB", ".VOB", ".WEBM"] upper = [".MP4", ".WMV", ".3GP", ".ASF", ".AVI", ".FLV", ".MOV", ".MPG", ".MPEG", ".RMVB", ".VOB", ".WEBM"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment