Class: Dropcaster::Item

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/dropcaster/item.rb

Instance Attribute Summary collapse

Attributes included from Logging

#logger

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = nil) ⇒ Item

Returns a new instance of Item



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dropcaster/item.rb', line 14

def initialize(file_path, options=nil)
  Mp3Info.open(file_path) { |mp3info|
    @file_name = Pathname.new(File.expand_path(file_path)).relative_path_from(Pathname.new(Dir.pwd)).cleanpath.to_s
    @tag = mp3info.tag
    @tag2 = mp3info.tag2
    @duration = mp3info.length
    if @tag2['ULT']
      @lyrics = {}
      @tag2['ULT'].split(/\x00/).drop(1).each_slice(2) { |k, v| @lyrics[k] = v }
    end
  }

  @file_size = File.new(@file_name).stat.size
  @uuid = Digest::SHA1.hexdigest(File.read(file_name))

  if tag2.TDR.blank?
    logger.info("#{file_path} has no pub date set, using the file's modification time")
    @pub_date = Time.parse(File.new(file_name).mtime.to_s)
  else
    @pub_date = Time.parse(tag2.TDR)
  end
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist



12
13
14
# File 'lib/dropcaster/item.rb', line 12

def artist
  @artist
end

#durationObject (readonly)

Returns the value of attribute duration



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def duration
  @duration
end

#file_nameObject (readonly)

Returns the value of attribute file_name



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def file_name
  @file_name
end

#file_sizeObject (readonly)

Returns the value of attribute file_size



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def file_size
  @file_size
end

#image_urlObject

Returns the value of attribute image_url



12
13
14
# File 'lib/dropcaster/item.rb', line 12

def image_url
  @image_url
end

#keywordsObject

Returns the value of attribute keywords



12
13
14
# File 'lib/dropcaster/item.rb', line 12

def keywords
  @keywords
end

#lyricsObject (readonly)

Returns the value of attribute lyrics



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def lyrics
  @lyrics
end

#pub_dateObject (readonly)

Returns the value of attribute pub_date



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def pub_date
  @pub_date
end

#tagObject (readonly)

Returns the value of attribute tag



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def tag
  @tag
end

#tag2Object (readonly)

Returns the value of attribute tag2



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def tag2
  @tag2
end

#urlObject

Returns the value of attribute url



12
13
14
# File 'lib/dropcaster/item.rb', line 12

def url
  @url
end

#uuidObject (readonly)

Returns the value of attribute uuid



11
12
13
# File 'lib/dropcaster/item.rb', line 11

def uuid
  @uuid
end