Class: Muzak::Song
Overview
Represents a single song for muzak.
Instance Attribute Summary collapse
-
#album ⇒ String?
readonly
The album of the song, identified from metadata.
-
#artist ⇒ String?
readonly
The artist of the song, identified from metadata.
-
#comment ⇒ String?
readonly
Any comments in the song's metadata.
-
#genre ⇒ String?
readonly
The genre of the song, identified from metadata.
-
#length ⇒ Integer
readonly
The length of the song, in seconds.
-
#path ⇒ String
readonly
The fully-qualified path to the song.
-
#title ⇒ String
readonly
The title of the song, identified from metadata.
-
#track ⇒ Integer, 0
readonly
The track number of the song, identified from metadata.
-
#year ⇒ Integer, 0
readonly
The year of the song, identified from metadata.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#best_guess_album_art ⇒ String
A best guess path for the song's cover art.
-
#full_title ⇒ String
The "full" title of the song, including artist and album if available.
-
#initialize(path) ⇒ Song
constructor
A new instance of Song.
Methods included from Utils
#album_art?, #debug, #debug?, #error, #fail_arity, #info, #music?, #output, #pretty, resolve_command, resolve_method, #verbose, #verbose?, #warn, #warn_arity
Constructor Details
#initialize(path) ⇒ Song
Returns a new instance of Song.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/muzak/song.rb', line 37 def initialize(path) @path = path TagLib::FileRef.open(path) do |ref| break if ref.null? @title = ref.tag.title @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 # provide some sane fallbacks @title ||= File.basename(path, File.extname(path)) rescue "" @track ||= 0 # we'll need to sort by track number end |
Instance Attribute Details
#album ⇒ String? (readonly)
Returns the album of the song, identified from metadata.
19 20 21 |
# File 'lib/muzak/song.rb', line 19 def album @album end |
#artist ⇒ String? (readonly)
Returns the artist of the song, identified from metadata.
16 17 18 |
# File 'lib/muzak/song.rb', line 16 def artist @artist end |
#comment ⇒ String? (readonly)
Returns any comments in the song's metadata.
31 32 33 |
# File 'lib/muzak/song.rb', line 31 def comment @comment end |
#genre ⇒ String? (readonly)
Returns the genre of the song, identified from metadata.
28 29 30 |
# File 'lib/muzak/song.rb', line 28 def genre @genre end |
#length ⇒ Integer (readonly)
Returns the length of the song, in seconds.
34 35 36 |
# File 'lib/muzak/song.rb', line 34 def length @length end |
#path ⇒ String (readonly)
Returns the fully-qualified path to the song.
9 10 11 |
# File 'lib/muzak/song.rb', line 9 def path @path end |
#title ⇒ String (readonly)
if metadata is missing, the basename of the path is used instead
Returns the title of the song, identified from metadata.
13 14 15 |
# File 'lib/muzak/song.rb', line 13 def title @title end |
#track ⇒ Integer, 0 (readonly)
Returns the track number of the song, identified from metadata.
25 26 27 |
# File 'lib/muzak/song.rb', line 25 def track @track end |
#year ⇒ Integer, 0 (readonly)
Returns the year of the song, identified from metadata.
22 23 24 |
# File 'lib/muzak/song.rb', line 22 def year @year end |
Instance Method Details
#==(other) ⇒ Object
79 80 81 |
# File 'lib/muzak/song.rb', line 79 def ==(other) path == other.path end |
#best_guess_album_art ⇒ String
Returns A best guess path for the song's cover art.
60 61 62 63 64 65 |
# File 'lib/muzak/song.rb', line 60 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_title ⇒ String
Returns the "full" title of the song, including artist and album if available.
71 72 73 74 75 76 77 |
# File 'lib/muzak/song.rb', line 71 def full_title full = title.dup full << " by #{artist}" if artist full << " on #{album}" if album full end |