<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tender Lovemaking &#187; daap</title>
	<atom:link href="http://tenderlovemaking.com/category/daap/feed/" rel="self" type="application/rss+xml" />
	<link>http://tenderlovemaking.com</link>
	<description>The act of making love, tenderly.</description>
	<lastBuildDate>Thu, 16 Feb 2012 17:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Automatically Query iTunes Shares</title>
		<link>http://tenderlovemaking.com/2006/08/24/automatically-query-itunes-shares/</link>
		<comments>http://tenderlovemaking.com/2006/08/24/automatically-query-itunes-shares/#comments</comments>
		<pubDate>Fri, 25 Aug 2006 03:21:16 +0000</pubDate>
		<dc:creator>Aaron Patterson</dc:creator>
				<category><![CDATA[computadora]]></category>
		<category><![CDATA[daap]]></category>

		<guid isPermaLink="false">http://tenderlovemaking.com/2006/08/24/automatically-query-itunes-shares/</guid>
		<description><![CDATA[Here&#8217;s a quick program I came up with to query iTunes shares as soon as they connect. It uses dnssd to query for iTunes over multicast dns, and Net::DAAP::Client (ruby iTunes client) to query the iTunes &#8230; <a class="more-link" href="http://tenderlovemaking.com/2006/08/24/automatically-query-itunes-shares/">More<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick program I came up with to query iTunes shares as soon as they connect.  It uses <a href="http://rubyforge.org/projects/dnssd/">dnssd</a> to query for iTunes over multicast dns, and <a href="http://rubyforge.org/projects/daapclient/">Net::DAAP::Client</a> (ruby iTunes client) to query the iTunes share.  The program will wait until someone starts up iTunes and automatically queries the iTunes server.</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rubygems'
require 'dnssd'
require 'net/daap'

Thread.abort_on_exception = true

class ITunesResolver
  @@servers = {}
  def self.resolve(br, action = :add)
    Thread.new(br, action) { |br, action|
      DNSSD.resolve(br.name, br.type, br.domain) { |rr|
        tr = rr.text_record

        # Skip servers that have a password
        if ! tr.has_key? &quot;Password&quot; or tr[&quot;Password&quot;] == &quot;false&quot;
          if action == :add
            @@servers[rr.target] = Thread.new(rr.target) { |t|

              # Connect to the server and list all songs
              daap = Net::DAAP::Client.new(t)
              daap.connect do |dsn|
                daap.databases do |db|
                  # Print song names
                  db.songs.sort.each { |s| puts s.name }
                end
              end # End DAAP Query
            }
          else
            (@@servers.delete rr.target).kill if @@servers.has_key? rr.target
          end
        end
        rr.service.stop
      }
    }
  end
end

browse_service = DNSSD.browse('_daap._tcp') do |browse_reply|
  if browse_reply.flags.add?
    ITunesResolver.resolve(browse_reply)
  else
    ITunesResolver.resolve(browse_reply, :del)
  end
end

$stdin.gets
browse_service.stop
</pre>
<p>It&#8217;s not perfect, but the bugs are left as an exercise for the reader to fix!</p>
]]></content:encoded>
			<wfw:commentRss>http://tenderlovemaking.com/2006/08/24/automatically-query-itunes-shares/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Ruby iTunes Client</title>
		<link>http://tenderlovemaking.com/2006/07/09/new-ruby-itunes-client/</link>
		<comments>http://tenderlovemaking.com/2006/07/09/new-ruby-itunes-client/#comments</comments>
		<pubDate>Mon, 10 Jul 2006 00:18:10 +0000</pubDate>
		<dc:creator>Aaron Patterson</dc:creator>
				<category><![CDATA[computadora]]></category>
		<category><![CDATA[daap]]></category>

		<guid isPermaLink="false">http://tenderlovemaking.com/2006/07/09/new-ruby-itunes-client/</guid>
		<description><![CDATA[I just released a new version of the ruby iTunes client, Net::DAAP::Client version 0.2.1. I also released Digest::M4P as a Gem and made daapclient depend on it. I wasn&#8217;t able to release Digest::M4P as a gem &#8230; <a class="more-link" href="http://tenderlovemaking.com/2006/07/09/new-ruby-itunes-client/">More<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just released a new version of the <a href="http://daapclient.rubyforge.org/">ruby iTunes client</a>, Net::DAAP::Client version 0.2.1.  I also released Digest::M4P as a Gem and made daapclient depend on it.  I wasn&#8217;t able to release Digest::M4P as a gem until RubyGems version 0.9.0 was released because of a weird bug.  But now that 0.9.0 is here, everything works!  Too bad the digest code still doesn&#8217;t work on windows&#8230;&#8230;.</p>
<p>I need to release my pure ruby MD5 so that I can make Digest::M4P pure ruby and not have to worry about this windows stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://tenderlovemaking.com/2006/07/09/new-ruby-itunes-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby iTunes Client</title>
		<link>http://tenderlovemaking.com/2006/06/01/ruby-itunes-client/</link>
		<comments>http://tenderlovemaking.com/2006/06/01/ruby-itunes-client/#comments</comments>
		<pubDate>Thu, 01 Jun 2006 18:24:51 +0000</pubDate>
		<dc:creator>Aaron Patterson</dc:creator>
				<category><![CDATA[computadora]]></category>
		<category><![CDATA[daap]]></category>

		<guid isPermaLink="false">http://tenderlovemaking.com/2006/06/01/ruby-itunes-client/</guid>
		<description><![CDATA[I&#8217;m trying to think of cool stuff for a Ruby presentation, so I thought I&#8217;d write up a quick tutorial for the Ruby iTunes client here to see how it sounds. Introduction: DAAP stands for &#8220;Digital &#8230; <a class="more-link" href="http://tenderlovemaking.com/2006/06/01/ruby-itunes-client/">More<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m trying to think of cool stuff for a Ruby presentation, so I thought I&#8217;d write up a quick tutorial for the <a href="http://daapclient.rubyforge.org">Ruby iTunes client</a> here to see how it sounds.</p>
<p><b>Introduction:</b><br />
DAAP stands for &#8220;Digital Audio Access Protocol&#8221;, and is the protocol used by Apple&#8217;s iTunes to share music over a network.  Hence the name Net::DAAP::Client.<br />
<span id="more-11"></span><br />
<b>Installation</b><br />
The client is packaged as a gem, so installation is pretty straightforward.  The only hitch is that <a href="http://rubyforge.org/frs/?group_id=1155&#038;release_id=3750">digest-m4p</a> needs to be installed first.  I am currently working on a pure Ruby implementation of Digest::M4P, so hopefully this process will become a lot easier.</p>
<p>First, download Digest::M4P from <a href="http://rubyforge.org/projects/daapclient/">here</a>.  Unzip the tar.gz file, run ruby on extconf.rb, then run &#8216;make&#8217;, and as root run &#8216;make install&#8217; like this:<br />
<code><br />
$ ruby extconf.rb<br />
$ make<br />
$ sudo make install<br />
[/sourcecode]<br />
Once that is installed, just install the daapclient gem:<br />
<code>$ sudo gem install daapclient[/sourcecode]</p>
<p><b>Usage:</b><br />
Connecting to iTunes is very simple.  Just create a new Net::DAAP::Client, and call connect.  If the connect method is given a block, after the block is executing the client will execute disconnect for you.</p>
<pre class="brush: ruby; title: ; notranslate">
daap = Net::DAAP::Client.new('localhost')
daap.connect do |dsn|
...
end # disconnect is called here for us!
</pre>
<p>DAAP allows any server to contain multiple databases of music, however in practice iTunes servers I have encountered only have one database.  Since a server could have multiple databases, we iterate over them:</p>
<pre class="brush: ruby; title: ; notranslate">
daap.databases.each do |db|
...
end
</pre>
<p>Once we have a handle on the database, we can access the databases attributes, such as the songs, artists, and albums it contains:</p>
<pre class="brush: ruby; title: ; notranslate">
db.songs.each { |song| puts song.name }
db.artists.each { |artist| puts artist.name }
db.albums.each { |album| puts album.name }
</pre>
<p><b>Putting it All Together:</b><br />
Now we can see how each piece, connecting to the server, getting the databases, and listing information, fits together with a simple program to list all songs on an iTunes server:</p>
<pre class="brush: ruby; title: ; notranslate">
daap = Net::DAAP::Client.new('localhost')
daap.connect do |dsn|
  daap.databases.each do |db|
    db.songs.each { |song| puts song.name }
  end
end
</pre>
<p><b>More Information</b><br />
For more information, be sure to check out the examples in the RDoc <a href="http://daapclient.rubyforge.org/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tenderlovemaking.com/2006/06/01/ruby-itunes-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

