Class: Net::DAAP::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/net/daap/database.rb

Overview

This class contains a database found on an iTunes server.

Constant Summary collapse

@@SONG_ATTRIBUTES =
%w{ dmap.itemid dmap.itemname dmap.persistentid
                             daap.songalbum daap.songartist daap.songformat
daap.songsize }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Database

Returns a new instance of Database.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/net/daap/database.rb', line 26

def initialize(args)
  @persistentid   = args['dmap.persistentid']
  @name           = args['dmap.itemname']
  @containercount = args['dmap.containercount']
  @id             = args['dmap.itemid']
  @itemcount      = args['dmap.itemcount']
  @daap           = args[:daap]
  @songs          = []
  @artists        = []
  @albums         = []
  load_songs
end

Instance Attribute Details

#containercountObject (readonly)

Returns the value of attribute containercount.



19
20
21
# File 'lib/net/daap/database.rb', line 19

def containercount
  @containercount
end

#idObject (readonly)

Returns the value of attribute id.



19
20
21
# File 'lib/net/daap/database.rb', line 19

def id
  @id
end

#itemcountObject (readonly)

Returns the value of attribute itemcount.



19
20
21
# File 'lib/net/daap/database.rb', line 19

def itemcount
  @itemcount
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/net/daap/database.rb', line 19

def name
  @name
end

#persistentidObject (readonly)

Returns the value of attribute persistentid.



19
20
21
# File 'lib/net/daap/database.rb', line 19

def persistentid
  @persistentid
end

Instance Method Details

#playlistsObject

Returns the playlists associated with this database



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/net/daap/database.rb', line 40

def playlists
  url = "databases/#{@id}/containers?meta=dmap.itemid,dmap.itemname,dmap.persistentid,com.apple.itunes.smart-playlist"
  res = @daap.do_get(url)

  listings = @daap.dmap.find(res, "daap.databaseplaylists/dmap.listing")

  playlists = []
  @daap.unpack_listing(listings) do |value|
    playlist = Playlist.new( value.merge( 
                              :daap     => @daap,
                              :db       => self ))
    if block_given?
      yield playlist
    else
      playlists << playlist
    end
  end
  playlists
end