Class: Dropcaster::Item
- Inherits:
-
Object
- Object
- Dropcaster::Item
- Includes:
- Logging
- Defined in:
- lib/dropcaster/item.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#file_size ⇒ Object
readonly
Returns the value of attribute file_size.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#lyrics ⇒ Object
readonly
Returns the value of attribute lyrics.
-
#pub_date ⇒ Object
readonly
Returns the value of attribute pub_date.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#tag2 ⇒ Object
readonly
Returns the value of attribute tag2.
-
#url ⇒ Object
Returns the value of attribute url.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Attributes included from Logging
Instance Method Summary collapse
-
#initialize(file_path, options = nil) ⇒ Item
constructor
A new instance of Item.
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, =nil) Mp3Info.open(file_path) { |mp3info| @file_path = Pathname.new(File.(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
#artist ⇒ Object
Returns the value of attribute artist.
13 14 15 |
# File 'lib/dropcaster/item.rb', line 13 def artist @artist end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
12 13 14 |
# File 'lib/dropcaster/item.rb', line 12 def duration @duration end |
#file_path ⇒ Object (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_size ⇒ Object (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_url ⇒ Object
Returns the value of attribute image_url.
13 14 15 |
# File 'lib/dropcaster/item.rb', line 13 def image_url @image_url end |
#keywords ⇒ Object
Returns the value of attribute keywords.
13 14 15 |
# File 'lib/dropcaster/item.rb', line 13 def keywords @keywords end |
#lyrics ⇒ Object (readonly)
Returns the value of attribute lyrics.
12 13 14 |
# File 'lib/dropcaster/item.rb', line 12 def lyrics @lyrics end |
#pub_date ⇒ Object (readonly)
Returns the value of attribute pub_date.
12 13 14 |
# File 'lib/dropcaster/item.rb', line 12 def pub_date @pub_date end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
12 13 14 |
# File 'lib/dropcaster/item.rb', line 12 def tag @tag end |
#tag2 ⇒ Object (readonly)
Returns the value of attribute tag2.
12 13 14 |
# File 'lib/dropcaster/item.rb', line 12 def tag2 @tag2 end |
#url ⇒ Object
Returns the value of attribute url.
13 14 15 |
# File 'lib/dropcaster/item.rb', line 13 def url @url end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
12 13 14 |
# File 'lib/dropcaster/item.rb', line 12 def uuid @uuid end |