Class: Scrobbler::Track

Inherits:
Base
  • Object
show all
Extended by:
ImageClassFuncs
Includes:
ImageObjectFuncs
Defined in:
lib/scrobbler/track.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from ImageClassFuncs

maybe_image_node

Methods included from ImageObjectFuncs

#check_image_node, #image

Methods inherited from Base

add_cache, api_key=, #call, #call_pageable, fetch_http, get, load_from_cache, #populate_data, post_request, #request, request, sanitize, save_to_cache, secret=, validate_response_document

Constructor Details

- (Track) initialize(artist, name, data = {})

Returns a new instance of Track

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
# File 'lib/scrobbler/track.rb', line 49

def initialize(artist, name, data={})
  raise ArgumentError, "Artist is required" if artist.nil?
  raise ArgumentError, "Name is required" if name.empty?
  @artist = artist
  @name = name
  populate_data(data)
end

Instance Attribute Details

- (Object) album (readonly)

Returns the value of attribute album



12
13
14
# File 'lib/scrobbler/track.rb', line 12

def album
  @album
end

- (Object) artist (readonly)

Returns the value of attribute artist



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def artist
  @artist
end

- (Object) count (readonly)

Returns the value of attribute count



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def count
  @count
end

- (Object) date (readonly)

Returns the value of attribute date



12
13
14
# File 'lib/scrobbler/track.rb', line 12

def date
  @date
end

- (Object) duration (readonly)

Returns the value of attribute duration



13
14
15
# File 'lib/scrobbler/track.rb', line 13

def duration
  @duration
end

- (Object) id (readonly)

Returns the value of attribute id



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def id
  @id
end

- (Object) listeners (readonly)

Returns the value of attribute listeners



13
14
15
# File 'lib/scrobbler/track.rb', line 13

def listeners
  @listeners
end

- (Object) mbid (readonly)

Returns the value of attribute mbid



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def mbid
  @mbid
end

- (Object) name (readonly)

Returns the value of attribute name



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def name
  @name
end

- (Object) now_playing (readonly)

Returns the value of attribute now_playing



12
13
14
# File 'lib/scrobbler/track.rb', line 12

def now_playing
  @now_playing
end

- (Object) playcount (readonly)

Returns the value of attribute playcount



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def playcount
  @playcount
end

- (Object) rank (readonly)

Returns the value of attribute rank



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def rank
  @rank
end

- (Object) streamable (readonly)

Returns the value of attribute streamable



12
13
14
# File 'lib/scrobbler/track.rb', line 12

def streamable
  @streamable
end

- (Object) tagcount (readonly)

Returns the value of attribute tagcount



12
13
14
# File 'lib/scrobbler/track.rb', line 12

def tagcount
  @tagcount
end

- (Object) url (readonly)

Returns the value of attribute url



11
12
13
# File 'lib/scrobbler/track.rb', line 11

def url
  @url
end

Class Method Details

+ (Object) fingerprint_metadata(fpid)



15
16
17
# File 'lib/scrobbler/track.rb', line 15

def self.(fpid)
  Base.get('track.getFingerprintMetadata', :tracks, Track, {:fingerprintid => fpid})
end

+ (Object) new_from_libxml(xml)



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
45
46
47
# File 'lib/scrobbler/track.rb', line 19

def self.new_from_libxml(xml)
  data = {}
  xml.children.each do |child|
    data[:name] = child.content if child.name == 'name'
    data[:mbid] = child.content if child.name == 'mbid'
    data[:url] = child.content if child.name == 'url'
    data[:date] = Time.parse(child.content) if child.name == 'date'
    data[:artist] = Artist.new(:xml => child) if child.name == 'artist'
    data[:album] = Album.new(:xml => child) if child.name == 'album'
    data[:playcount] = child.content.to_i if child.name == 'playcount'
    data[:tagcount] = child.content.to_i if child.name == 'tagcount'
    maybe_image_node(data, child)
    if child.name == 'streamable'
      if ['1', 'true'].include?(child.content)
        data[:streamable] = true
      else
        data[:streamable] = false
      end
    end
  end
  
  
  data[:rank] = xml['rank'].to_f if xml['rank']
  data[:now_playing] = true if xml['nowplaying'] && xml['nowplaying'] == 'true'
  
  data[:now_playing] = false if data[:now_playing].nil?
  
  Track.new(data[:artist], data[:name], data)
end

Instance Method Details

- (Object) ==(otherTrack)



132
133
134
135
136
137
# File 'lib/scrobbler/track.rb', line 132

def ==(otherTrack)
  if otherTrack.is_a?(Scrobbler::Track)
    return ((@name == otherTrack.name) && (@artist == otherTrack.artist))
  end
  false
end

- (Object) add_tags(tags)

Raises:

  • (NotImplementedError)


57
58
59
60
# File 'lib/scrobbler/track.rb', line 57

def add_tags(tags)
    # This function requires authentication, but SimpleAuth is not yet 2.0
    raise NotImplementedError
end

- (Object) ban

Raises:

  • (NotImplementedError)


62
63
64
65
# File 'lib/scrobbler/track.rb', line 62

def ban
    # This function requires authentication, but SimpleAuth is not yet 2.0
    raise NotImplementedError
end

- (Object) load_info



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/scrobbler/track.rb', line 68

def load_info
    return nil if @info_loaded
    doc = Base.request('track.getinfo', :artist => @artist.name, :track => @name)
    doc.root.children.each do |childL1|
        next unless childL1.name == 'track'
        childL1.children.each do |child|
            @id = child.content.to_i if child.name == 'id'
            @mbid = child.content if child.name == 'mbid'
            @duration = child.content.to_i if child.name == 'duration'
            @url = child.content if child.name == 'url'
            if child.name == 'streamable'
                if ['1', 'true'].include?(child.content)
                  @streamable = true
                else
                  @streamable = false
                end
            end
            @listeners = child.content.to_i if child.name == 'listeners'
            @playcount = child.content.to_i if child.name == 'playcount'
            @artist = Artist.new_from_libxml(child) if child.name == 'artist'
            @album = Album.new_from_libxml(child) if child.name == 'album'
        end
    end
    @info_loaded = true
end

- (Object) love

Raises:

  • (NotImplementedError)


112
113
114
115
# File 'lib/scrobbler/track.rb', line 112

def love
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

- (Object) remove_tag

Raises:

  • (NotImplementedError)


117
118
119
120
# File 'lib/scrobbler/track.rb', line 117

def remove_tag
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

- (Object) search

Raises:

  • (NotImplementedError)


122
123
124
125
# File 'lib/scrobbler/track.rb', line 122

def search
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

- (Object) share

Raises:

  • (NotImplementedError)


127
128
129
130
# File 'lib/scrobbler/track.rb', line 127

def share
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

- (Object) similar

Raises:

  • (NotImplementedError)


102
103
104
105
# File 'lib/scrobbler/track.rb', line 102

def similar
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

- (Object) tags

Raises:

  • (NotImplementedError)


107
108
109
110
# File 'lib/scrobbler/track.rb', line 107

def tags
  # This function require authentication, but SimpleAuth is not yet 2.0
  raise NotImplementedError
end

- (Object) top_fans(force = false)



94
95
96
# File 'lib/scrobbler/track.rb', line 94

def top_fans(force=false)
  call('track.gettopfans', :topfans, User, {:artist => @artist.name, :track => @name})
end

- (Object) top_tags(force = false)



98
99
100
# File 'lib/scrobbler/track.rb', line 98

def top_tags(force=false)
  call('track.gettoptags', :toptags, Tag, {:artist => @artist.name, :track => @name})
end