Class: Muzak::Song

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/muzak/song.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#album_art?, #debug, #debug?, #error, #fail_arity, #info, #music?, #output, #pretty, #verbose, #verbose?, #warn, #warn_arity

Constructor Details

#initialize(path) ⇒ Song



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/muzak/song.rb', line 9

def initialize(path)
  @path = path

  TagLib::FileRef.open(path) do |ref|
    break if ref.null?
    @title = ref.tag.title || File.basename(path, File.extname(path))
    @artist = ref.tag.artist
    @album = ref.tag.album
    @year = ref.tag.year
    @track = ref.tag.track
    @genre = ref.tag.genre
    @comment = ref.tag.comment
    @length = ref.audio_properties.length
  end
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



7
8
9
# File 'lib/muzak/song.rb', line 7

def album
  @album
end

#artistObject (readonly)

Returns the value of attribute artist.



7
8
9
# File 'lib/muzak/song.rb', line 7

def artist
  @artist
end

#commentObject (readonly)

Returns the value of attribute comment.



7
8
9
# File 'lib/muzak/song.rb', line 7

def comment
  @comment
end

#genreObject (readonly)

Returns the value of attribute genre.



7
8
9
# File 'lib/muzak/song.rb', line 7

def genre
  @genre
end

#lengthObject (readonly)

Returns the value of attribute length.



7
8
9
# File 'lib/muzak/song.rb', line 7

def length
  @length
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/muzak/song.rb', line 7

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/muzak/song.rb', line 7

def title
  @title
end

#trackObject (readonly)

Returns the value of attribute track.



7
8
9
# File 'lib/muzak/song.rb', line 7

def track
  @track
end

#yearObject (readonly)

Returns the value of attribute year.



7
8
9
# File 'lib/muzak/song.rb', line 7

def year
  @year
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
# File 'lib/muzak/song.rb', line 40

def ==(other)
  path == other.path
end

#best_guess_album_artObject



25
26
27
28
29
30
# File 'lib/muzak/song.rb', line 25

def best_guess_album_art
  album_dir = File.dirname(path)

  art = Dir.entries(album_dir).find { |ent| album_art?(ent) }
  File.join(album_dir, art) unless art.nil?
end

#full_titleObject



32
33
34
35
36
37
38
# File 'lib/muzak/song.rb', line 32

def full_title
  full = title.dup
  full << " by #{artist}" if artist
  full << " on #{album}" if album

  full
end