Class: Kanye::Track
- Inherits:
-
Object
- Object
- Kanye::Track
- Defined in:
- lib/kanye/track.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #download! ⇒ Object
- #filename ⇒ Object
-
#initialize(params = {}) ⇒ Track
constructor
A new instance of Track.
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Track
Returns a new instance of Track.
8 9 10 11 12 13 14 |
# File 'lib/kanye/track.rb', line 8 def initialize(params={}) @id = params[:id] @key = params[:key] @title = params[:title] @artist = params[:artist] @cookie = params[:cookie] end |
Instance Attribute Details
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
16 17 18 |
# File 'lib/kanye/track.rb', line 16 def artist @artist end |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
16 17 18 |
# File 'lib/kanye/track.rb', line 16 def @cookie end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/kanye/track.rb', line 16 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
16 17 18 |
# File 'lib/kanye/track.rb', line 16 def key @key end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
16 17 18 |
# File 'lib/kanye/track.rb', line 16 def title @title end |
Instance Method Details
#download! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kanye/track.rb', line 22 def download! raise(NoKeyError, "Couldn't find :key for '#{self}'") if key.nil? response = HTTParty.get(url, :headers => {'cookie' => }) raise "Response Code '#{response.code}' - Something has changed." unless response.code == 200 print self, "[ Downloading…" mp3_url = URI.escape(response.parsed_response["url"]) if mp3_url =~ /http:\/\/.*\.s3\.amazonaws\.com\// mp3_url = correct_s3_url!(mp3_url) end puts mp3_url if Kanye.config["debug"] mp3_response = HTTParty.get(mp3_url) File.open(filename, "wb") do |f| f.write(mp3_response.parsed_response) end puts " complete ]" end |
#filename ⇒ Object
54 55 56 57 |
# File 'lib/kanye/track.rb', line 54 def filename name = [artist,title].join('-').gsub(/[ \/]/, "-").downcase File.join(Kanye.download_path, name + ".mp3") end |
#to_s ⇒ Object
48 49 50 51 52 |
# File 'lib/kanye/track.rb', line 48 def to_s t = truncate(title, 42, '…').force_encoding('utf-8').ljust(42) a = truncate(artist, 42, '…').force_encoding('utf-8').ljust(32) [t, "| ", a].join end |
#url ⇒ Object
18 19 20 |
# File 'lib/kanye/track.rb', line 18 def url "http://#{BASE_URL}/serve/source/" + id + '/' + key end |