Class: Scrobbler::Track

Inherits:
Base
  • Object
show all
Defined in:
lib/scrobbler/track.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key=, connection, fetch_and_parse, sanitize

Constructor Details

#initialize(artist, name) ⇒ Track

Returns a new instance of Track.

Raises:

  • (ArgumentError)


74
75
76
77
78
79
# File 'lib/scrobbler/track.rb', line 74

def initialize(artist, name)
  raise ArgumentError, "Artist is required" if artist.blank?
  raise ArgumentError, "Name is required" if name.blank?
  @artist = artist
  @name = name
end

Instance Attribute Details

#albumObject

Returns the value of attribute album.



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def album
  @album
end

#album_mbidObject

Returns the value of attribute album_mbid.



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def album_mbid
  @album_mbid
end

#artistObject

Returns the value of attribute artist.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def artist
  @artist
end

#artist_mbidObject

Returns the value of attribute artist_mbid.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def artist_mbid
  @artist_mbid
end

#chartpositionObject

for weekly top tracks



45
46
47
# File 'lib/scrobbler/track.rb', line 45

def chartposition
  @chartposition
end

#countObject

only seems to be used on top tracks for tag



42
43
44
# File 'lib/scrobbler/track.rb', line 42

def count
  @count
end

#dateObject

Returns the value of attribute date.



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def date
  @date
end

#date_utsObject

Returns the value of attribute date_uts.



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def date_uts
  @date_uts
end

#imageObject

only seems to be used on top tracks for tag



42
43
44
# File 'lib/scrobbler/track.rb', line 42

def image
  @image
end

#mbidObject

Returns the value of attribute mbid.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def mbid
  @mbid
end

#nameObject

Returns the value of attribute name.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def name
  @name
end

#now_playingObject

Returns the value of attribute now_playing.



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def now_playing
  @now_playing
end

#playcountObject

Returns the value of attribute playcount.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def playcount
  @playcount
end

#rankObject

Returns the value of attribute rank.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def rank
  @rank
end

#reachObject

Returns the value of attribute reach.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def reach
  @reach
end

#streamableObject

Returns the value of attribute streamable.



39
40
41
# File 'lib/scrobbler/track.rb', line 39

def streamable
  @streamable
end

#thumbnailObject

only seems to be used on top tracks for tag



42
43
44
# File 'lib/scrobbler/track.rb', line 42

def thumbnail
  @thumbnail
end

#urlObject

Returns the value of attribute url.



38
39
40
# File 'lib/scrobbler/track.rb', line 38

def url
  @url
end

Class Method Details

.new_from_xml(xml, doc = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/scrobbler/track.rb', line 48

def new_from_xml(xml, doc=nil)
  artist          = xml.at('/artist/name').inner_html if xml.at('/artist/name')
  artist          = xml.at(:artist).inner_html        if artist.nil? && xml.at(:artist)
  name            = xml.at(:name).inner_html          if xml.at(:name)
  t               = Track.new(artist, name)
  t.artist_mbid   = xml.at(:artist)['mbid']           if xml.at(:artist) && xml.at(:artist)['mbid']
  t.artist_mbid   = xml.at('/artist/mbid').inner_html if t.artist_mbid.nil? && xml.at('/artist/mbid')
  t.mbid          = xml.at(:mbid).inner_html          if xml.at(:mbid)
  t.playcount     = xml.at(:playcount).inner_html     if xml.at(:playcount)
  t.chartposition = xml.at(:chartposition).inner_html if xml.at(:chartposition)
  t.rank          = xml['rank'] if xml['rank']
  t.url           = xml.at('/url').inner_html         if xml.at('/url')
  t.streamable    = xml.at('/streamable').inner_html  if xml.at('/streamable')
  t.count         = xml.at('/tagcount').inner_html    if xml.at('/tagcount')
  t.album         = xml.at(:album).inner_html         if xml.at(:album)
  t.album_mbid    = xml.at(:album)['mbid']            if xml.at(:album) && xml.at(:album)['mbid']
  t.date          = Time.parse((xml).at(:date).inner_html)  if xml.at(:date)
  t.date_uts      = xml.at(:date)['uts']              if xml.at(:date) && xml.at(:date)['uts']
  t.thumbnail = xml.at('/image[@size="small"]').inner_html if xml.at('/image[@size="small"]')
  t.image = xml.at('/image[@size="medium"]').inner_html   if xml.at('/image[@size="medium"]')
  t.now_playing = true if xml['nowplaying'] && xml['nowplaying'] == 'true'
  t.now_playing = false unless t.now_playing
  t
end

Instance Method Details

#fans(force = false) ⇒ Object



81
82
83
# File 'lib/scrobbler/track.rb', line 81

def fans(force=false)
  get_instance2('track.gettopfans', :fans, :user, {'artist'=>@artist, 'track'=>@name}, force)
end

#tags(force = false) ⇒ Object



85
86
87
# File 'lib/scrobbler/track.rb', line 85

def tags(force=false)
  get_instance2('track.gettoptags', :tags, :tag, {'artist'=>@artist, 'track'=>@name}, force)
end