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.



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

def initialize(file_path, options=nil)
  Mp3Info.open(file_path) { |mp3info|
    @file_path = Pathname.new(File.expand_path(file_path)).relative_path_from(Pathname.new(Dir.pwd)).cleanpath
    @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_path).stat.size
  @uuid = Digest::SHA1.hexdigest(File.read(file_path))

  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_path).mtime.to_s)
  else
    @pub_date = Time.parse(tag2.TDR)
  end
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



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

def artist
  @artist
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#file_sizeObject (readonly)

Returns the value of attribute file_size.



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

def file_size
  @file_size
end

#image_urlObject

Returns the value of attribute image_url.



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

def image_url
  @image_url
end

#keywordsObject

Returns the value of attribute keywords.



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

def keywords
  @keywords
end

#lyricsObject (readonly)

Returns the value of attribute lyrics.



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

def lyrics
  @lyrics
end

#pub_dateObject (readonly)

Returns the value of attribute pub_date.



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

def pub_date
  @pub_date
end

#tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
end

#tag2Object (readonly)

Returns the value of attribute tag2.



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

def tag2
  @tag2
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#uuidObject (readonly)

Returns the value of attribute uuid.



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

def uuid
  @uuid
end