<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>code/so_delicious/README</filename>
    </added>
    <added>
      <filename>code/so_delicious/index.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,15 @@
 #!/usr/bin/env ruby
+require 'open3'
+require 'cgi'
 require 'rexml/document'
 require 'sqlite3'
 
+wget = &quot;wget&quot;
+wget_options = []
+wget_options.push(&quot;-e robots=off&quot;)
+wget_options.push(&quot;--user-agent=\&quot;Mozilla/5.0 (X11; U; Linux; fr; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6\&quot;&quot;); 
+wget_options.push(&quot;-P cache -t2 -pkHE -R mpeg,mpg,avi,mov&quot;)
+
 puts &quot;So Delicious..&quot;
 begin
 file = File.open(&quot;myDelicious.xml&quot;)
@@ -11,6 +19,7 @@ db.execute(&quot;CREATE TABLE IF NOT EXISTS bookmarks (
               id INTEGER PRIMARY KEY,
               link varchar(1024),
               name varchar(255),
+              local_url varchar(1024),
               time DATE
               )&quot;)
 db.execute(&quot;CREATE TABLE IF NOT EXISTS tags (
@@ -27,23 +36,28 @@ rescue
   exit
 end
 
-doc.elements.each(&quot;posts/post&quot;) do |post|
+omg=0
 
+doc.elements.each(&quot;posts/post&quot;) do |post|
+   exit if omg &gt; 5
+   omg += 1
    rows = db.execute( &quot;SELECT * FROM bookmarks WHERE link=?&quot;, post.attributes['href'] )
-   post.attributes['href'] =~ /:\/\/(.*)/
-   begin
-     puts &quot;Stat-ing #{$1}&quot;
-     File.stat($1)
-     file_not_found = 0
-   rescue
-     file_not_found = 1
-   end
    if rows.size == 0
      puts &quot;Downloading &quot;+post.attributes['description']
-     `wget -R mov,avi -t 5 -pk &quot;#{post.attributes['href']}&quot;`
+     cmd = &quot;#{wget} #{wget_options.join(&quot; &quot;)} \&quot;#{post.attributes['href']}\&quot;&quot;
+     #puts &quot;Running: #{cmd}&quot;
+     filename = &quot;&quot;
+     Open3.popen3(cmd) do |stdin, stdout, stderr|
+       err = stderr.read
+       err =~ /Saving to: `(.*)\/(.*?)'$/
+       path = $1
+       filename = path + '/' + CGI.escape($2)
+       
+       puts &quot;SAVED TO: #{filename}&quot;
+     end
 
      # Do bookmark
-     db.execute( &quot;INSERT INTO bookmarks VALUES (NULL,?,?,?)&quot;, post.attributes['href'], post.attributes['description'], post.attributes['time'] )
+     db.execute( &quot;INSERT INTO bookmarks VALUES (NULL,?,?,?,?)&quot;, post.attributes['href'], post.attributes['description'], filename, post.attributes['time'])
      rows = db.execute( &quot;SELECT * FROM bookmarks WHERE link=?&quot;, post.attributes['href'] )
      bid = rows[0][0]
 
@@ -64,10 +78,6 @@ doc.elements.each(&quot;posts/post&quot;) do |post|
        end
      end
      puts
-   elsif file_not_found == 1
-     # Only download.
-     puts &quot;Downloading &quot;+post.attributes['description']
-     `wget -r -l 1 &quot;#{post.attributes['href']}&quot;`
    else
      puts &quot;Already have #{post.attributes['description']}&quot;
    end</diff>
      <filename>code/so_delicious/so_delicious.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0ec9e9395b41fc70d8327a43149e28705b957c78</id>
    </parent>
  </parents>
  <author>
    <name>Erik</name>
    <email>hank@davros.ralree.dyndns.org</email>
  </author>
  <url>http://github.com/hank/life/commit/fbeb5dcf7ef8d7493c4e223dda573ef681364a86</url>
  <id>fbeb5dcf7ef8d7493c4e223dda573ef681364a86</id>
  <committed-date>2009-03-29T13:06:32-07:00</committed-date>
  <authored-date>2009-03-29T13:06:32-07:00</authored-date>
  <message>Almost working well...</message>
  <tree>bf17d02089151acfb1055fdf7159e62d41b08e63</tree>
  <committer>
    <name>Erik</name>
    <email>hank@davros.ralree.dyndns.org</email>
  </committer>
</commit>
