Sha256: 7ca767caf888e83434f3153981605c3b07bf27b160d47600697417645e39638b

Contents?: true

Size: 1.53 KB

Versions: 8

Compression:

Stored size: 1.53 KB

Contents

module Gluttonberg
  module Library
    module Processor
      require "mp3info"
      class Audio
        attr_accessor :asset

        def self.process(asset_obj)
          if asset_obj.asset_type.asset_category.name == "audio"
            self.collect_mp3_info(asset_obj)
          end
        end

        # Collect mp3 files info using Mp3Info gem
        def self.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 #collect_mp3_info

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gluttonberg-core-2.6.4 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.6.3 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.6.2 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.6.1 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.6.0 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.5.9 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.5.8 lib/gluttonberg/library/processor/audio.rb
gluttonberg-core-2.5.7 lib/gluttonberg/library/processor/audio.rb