Class: Gluttonberg::Library::Processor::Audio
- Inherits:
-
Object
- Object
- Gluttonberg::Library::Processor::Audio
- Defined in:
- lib/gluttonberg/library/processor/audio.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
Returns the value of attribute asset.
Class Method Summary collapse
Instance Method Summary collapse
-
#collect_mp3_info(asset) ⇒ Object
Collect mp3 files info using Mp3Info gem.
Instance Attribute Details
#asset ⇒ Object
Returns the value of attribute asset.
6 7 8 |
# File 'lib/gluttonberg/library/processor/audio.rb', line 6 def asset @asset end |
Class Method Details
.process(asset_obj) ⇒ Object
8 9 10 11 12 |
# File 'lib/gluttonberg/library/processor/audio.rb', line 8 def self.process(asset_obj) if asset_obj.asset_type.asset_category.name == "audio" collect_mp3_info(asset) end end |
Instance Method Details
#collect_mp3_info(asset) ⇒ Object
Collect mp3 files info using Mp3Info gem
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gluttonberg/library/processor/audio.rb', line 15 def collect_mp3_info(asset) audio = AudioAssetAttribute.find( :first , :conditions => {:asset_id => asset.id}) begin #open mp3 file Mp3Info.open(location_on_disk) do |mp3| if audio.blank? AudioAssetAttribute.create( :asset_id => asset.id , :length => mp3.length , :title => mp3.tag.title , :artist => mp3.tag.artist , :album => mp3.tag.album , :tracknum => mp3.tag.tracknum) else audio.update_attributes( {:length => mp3.length, :genre =>"" , :title => mp3.tag.title , :artist => mp3.tag.artist , :album => mp3.tag.album , :tracknum => mp3.tag.tracknum }) end end if Gluttonberg::Setting.get_setting("audio_assets") == "Enable" Delayed::Job.enqueue AudioJob.new(asset.id) end rescue => detail # if exception occurs and asset has some attributes, then remove them. unless audio.blank? audio.update_attributes( {:length => nil , :title => nil , :artist => nil , :album => nil , :tracknum => nil }) end end end |