Class: BandCamp::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/band_camp/song.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @title = title
  @title_link = title_link
  @url = url
  @options = options
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/band_camp/song.rb', line 6

def title
  @title
end

Returns the value of attribute title_link.



6
7
8
# File 'lib/band_camp/song.rb', line 6

def title_link
  @title_link
end

#urlObject (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, options = {})
  song_name = BandCamp::file_safe_string(title)
  if options[:index]
    song_name = "%02d-%s" % [options[: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 = options[:band_name] if options[:band_name]
    id3_tag.album = options[:album_name] if options[:album_name]
    if options[:index]
      track = (options[:index] + 1).to_s
      if options[:number_of_tracks]
        track += "/%d" % options[:number_of_tracks]
      end
      id3_tag.track = track
    end
    id3_tag.update!
  end
end

#to_sObject



15
16
17
# File 'lib/band_camp/song.rb', line 15

def to_s
  "title: #{title}"
end