Class: LastfmM3u::Lastfm
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
Attributes inherited from Base
Instance Method Summary collapse
- #find_tracks(search_type = :file, progressbar = nil) ⇒ Object
-
#initialize(artist, root_dir = '/home/jon/music/trance') ⇒ Lastfm
constructor
A new instance of Lastfm.
- #set_artist(artist) ⇒ Object
- #set_top_tracks ⇒ Object
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
#artist ⇒ Object
Returns the value of attribute artist.
5 6 7 |
# File 'lib/lastfm-m3u/lastfm.rb', line 5 def artist @artist end |
#limit ⇒ Object
Returns the value of attribute limit.
5 6 7 |
# File 'lib/lastfm-m3u/lastfm.rb', line 5 def limit @limit end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
5 6 7 |
# File 'lib/lastfm-m3u/lastfm.rb', line 5 def root_dir @root_dir end |
#tracks ⇒ Object
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, = 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}) .increment if 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_tracks ⇒ Object
20 21 22 |
# File 'lib/lastfm-m3u/lastfm.rb', line 20 def set_top_tracks @tracks = @artist.top_tracks end |