Class: MTP::MP3Track

Inherits:
Track show all
Defined in:
lib/mtp/track.rb

Constant Summary

Constants inherited from Object

Object::PROTECTION_STATUS

Instance Attribute Summary

Attributes inherited from Object

#association, #compressed_size, #data, #date_created, #date_modified, #filename, #format, #id, #image_bit_depth, #image_pix_height, #image_pix_with, #keywords, #ph, #properties, #protection_status, #sequence_number, #thumb_compressed_size, #thumb_format, #thumb_pix_height, #thumb_pix_width

Instance Method Summary collapse

Methods inherited from Object

#<=>, #before_sending, #dump_properties, load, #new_object?, #pack, property_accessor, property_reader, property_writer, register_format, #valid?

Constructor Details

#initialize(localname = nil) ⇒ MP3Track

Returns a new instance of MP3Track.



12
13
14
15
16
# File 'lib/mtp/track.rb', line 12

def initialize(localname = nil)
  super()
  self.format = "MP3"
  self.localname = localname unless localname.nil?
end

Instance Method Details

#after_sendingObject



69
70
71
72
# File 'lib/mtp/track.rb', line 69

def after_sending
  super
  set_properties_from_mp3info(@info) unless @info.nil?
end

#album_nameObject



51
52
53
# File 'lib/mtp/track.rb', line 51

def album_name
  new_object? ? @info.tag.album : properties.album_name
end

#artistObject



31
32
33
# File 'lib/mtp/track.rb', line 31

def artist
  new_object? ? @info.tag.artist : properties.artist
end

#genreObject



43
44
45
# File 'lib/mtp/track.rb', line 43

def genre
  new_object? ? @info.tag.genre_s : properties.genre
end

#inspectObject



55
56
57
58
# File 'lib/mtp/track.rb', line 55

def inspect
  "#<MTP::MP3Track:0x%08x @parent_id=0x%08x @artist=%s @track=%u @name=%s @genre=%s @album_name%s>" % 
    [ @id, @parent_id, artist.inspect, track, name, genre.inspect, album_name.inspect]  
end

#load(ph, id, payload) ⇒ Object



18
19
20
# File 'lib/mtp/track.rb', line 18

def load(ph, id, payload)
  super(ph, id, payload)
end

#localname=(localname) ⇒ Object

read track data and info from a local file



23
24
25
26
27
28
29
# File 'lib/mtp/track.rb', line 23

def localname=(localname)
  @localname = localname
  @info = Mp3Info.new(localname)
  @info.close
  self.filename = File.basename(@localname)
  self.compressed_size = File.size(@localname)
end

#nameObject



35
36
37
# File 'lib/mtp/track.rb', line 35

def name
  new_object? ? @info.tag.title : properties.name
end

#original_release_dateObject



47
48
49
# File 'lib/mtp/track.rb', line 47

def original_release_date
  new_object? ? Time.local(@info.tag.year) : properties.original_release_date
end

#set_properties_from_mp3info(info) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/mtp/track.rb', line 60

def set_properties_from_mp3info(info)
  self.artist = info.tag.artist
  self.name = info.tag.title
  self.track = info.tag.tracknum
  self.genre = info.tag.genre_s
  self.original_release_date = Time.local(info.tag.year) unless info.tag.year.nil?
  self.album_name = info.tag.album
end

#trackObject



39
40
41
# File 'lib/mtp/track.rb', line 39

def track
  new_object? ? @info.tag.tracknum : properties.track
end