Class: LastfmM3u::Lastfm

Inherits:
Base
  • Object
show all
Defined in:
lib/lastfm-m3u/lastfm.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#m3u, #m3u_path

Instance Method Summary collapse

Constructor Details

#initialize(artist, root_dir = '/home/jon/music/trance') ⇒ Lastfm

Returns a new instance of Lastfm.



7
8
9
10
11
12
13
14
# File 'lib/lastfm-m3u/lastfm.rb', line 7

def initialize(artist, root_dir='/home/jon/music/trance')
  init_config
  set_artist(artist)
  set_top_tracks
  @root_dir = root_dir
  @limit = nil
  super()
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



5
6
7
# File 'lib/lastfm-m3u/lastfm.rb', line 5

def artist
  @artist
end

#limitObject

Returns the value of attribute limit.



5
6
7
# File 'lib/lastfm-m3u/lastfm.rb', line 5

def limit
  @limit
end

#root_dirObject

Returns the value of attribute root_dir.



5
6
7
# File 'lib/lastfm-m3u/lastfm.rb', line 5

def root_dir
  @root_dir
end

#tracksObject

Returns the value of attribute tracks.



5
6
7
# File 'lib/lastfm-m3u/lastfm.rb', line 5

def tracks
  @tracks
end

Instance Method Details

#find_tracks(search_type = :file, progressbar = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lastfm-m3u/lastfm.rb', line 24

def find_tracks(search_type = :file, progressbar = nil)
  begin
    raise InvalidSearchType unless SEARCH_TYPES.include?(search_type)
  rescue InvalidSearchType
    $logger.error("Invalid Search Type '#{search_type}', use one of #{SEARCH_TYPES.join(',')}")
    exit
  end
  found_tracks = {}
  search = LastfmM3u::FileSearch.new(root_dir)
  self.limit ||= tracks.size
  tracks[0..limit-1].each do |track|
    track.name = CGI.unescapeHTML(track.name)
    found_tracks[track.name] = search.find(track.name, {search_type: search_type})
    progressbar.increment if progressbar
  end
  found_tracks
end

#set_artist(artist) ⇒ Object



16
17
18
# File 'lib/lastfm-m3u/lastfm.rb', line 16

def set_artist(artist)
  @artist = Rockstar::Artist.new artist
end

#set_top_tracksObject



20
21
22
# File 'lib/lastfm-m3u/lastfm.rb', line 20

def set_top_tracks
  @tracks = @artist.top_tracks
end