Class: BandCamp::Song
- Inherits:
-
Object
- Object
- BandCamp::Song
- Defined in:
- lib/band_camp/song.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#title_link ⇒ Object
readonly
Returns the value of attribute title_link.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #download(band_path, options = {}) ⇒ Object
-
#initialize(title, title_link, url, options = {}) ⇒ Song
constructor
A new instance of Song.
- #to_s ⇒ Object
Constructor Details
#initialize(title, title_link, url, options = {}) ⇒ Song
Returns a new instance of Song.
8 9 10 11 12 13 |
# File 'lib/band_camp/song.rb', line 8 def initialize(title, title_link, url, = {}) @title = title @title_link = title_link @url = url @options = end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/band_camp/song.rb', line 6 def title @title end |
#title_link ⇒ Object (readonly)
Returns the value of attribute title_link.
6 7 8 |
# File 'lib/band_camp/song.rb', line 6 def title_link @title_link end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/band_camp/song.rb', line 6 def url @url end |
Instance Method Details
#download(band_path, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/band_camp/song.rb', line 19 def download(band_path, = {}) song_name = BandCamp::file_safe_string(title) if [:index] song_name = "%02d-%s" % [[:index] + 1, song_name] end file_name = File.join(band_path, song_name + ".mp3") if @options[:try] puts "[try] Saving #{file_name}" else Downloader.download(:url => url, :file_name => file_name, :debug => @options[:debug]) id3_tag = ID3Lib::Tag.new(file_name) id3_tag.title = title id3_tag.artist = [:band_name] if [:band_name] id3_tag.album = [:album_name] if [:album_name] if [:index] track = ([:index] + 1).to_s if [:number_of_tracks] track += "/%d" % [:number_of_tracks] end id3_tag.track = track end id3_tag.update! end end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/band_camp/song.rb', line 15 def to_s "title: #{title}" end |