RSS+uTorrent+BTC for Automated torrent downloading

Want to tell uTorrent what to do via Ruby? Read on.

First, you need to enable the uTorrent local interface in the application. Then go install btc (instructions on https://www.github.com/bittorrent/btc).

Make sure Ruby is installed. And get the rss gem:

gem install rss

Then create a file called rss.rb and throw this in there:

## START FILE rss.rb
require 'rss'
require 'open-uri'
require 'cgi'
 
PASSKEY = 'YOURPASSKEYHERE'
 
# URL to your Tracker -- Mine looked like
# https:///rss.php?feed=dl&bookmarks=on&passkey=#{PASSKEY}
# Note you need to define this or I'll raise an exception on you!
 
# url = "https:///rss.php?feed=dl&bookmarks=on&passkey=#{PASSKEY}"
 
raise "Did you define the url?" unless defined?(url)
 
torrent_list = `btc list`
 
open(url) do |rss|
  feed = RSS::Parser.parse(rss)
  puts "#{Time.now.to_s} -- Title: #{feed.channel.title}"
  feed.items.each do |item|
    puts "Item: #{item.title}"
    if torrent_list.include? item.title
      puts "Skipping torrent, already in uTorrent"
    else
      puts "Downloading torrent #{item.title}"
      `btc add #{item.link}`
    end
  end
end
 
## END FILE rss.rb

To test, simply run this at command line:

ruby rss.rb

To automate, add a job to your cron tab. From command line (Make sure to set the directory to the right location.):

crontab -e

Add a rule to run this script every minute:

* * * * * cd /Users/ephtoaster/torrenter/ && ruby rss.rb > runs.log

My whole crontab looks like:

MAILTO=""
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin
* * * * * cd /Users/ephtoaster/torrenter/ && ruby rss.rb > runs.log

Making HTTP calls & interacting with Disk from within Photoshop

This blog post has sat in Draft for far too long. I have no intention of writing a full article so let’s let the code live on.

Using the Adobe Photoshop CS ExtendScript Toolkit (which is included by default in the PS scripting environment), we can make HTTP calls, write to disk, and have some fun. Imagine exposing a REST API of batch jobs to execute and having Photoshop pull them down and execute them in near real-time. I did this and it works.

Here is a simple gist of opening a connection and writing the response to a file.

function execute_modifications() {
	var doc = activeDocument;
	var reply = "";
	var conn = new Socket;
 
	// access some URL
	if (conn.open ("www.google.com:80")) {
 
		// issue http command
		conn.write ("GET /index.html HTTP/1.0\n\n");
 
		// read connection response (and a lot of it)
		reply = conn.read(999999);
 
		var file;
 
		try {
			file = new File('~/.ps_actions.cnf');
			if (!file.open('e')) {
				alert('failed to open file: ' + file.error);
			}
 
			if (!file.write(reply)) {
				alert("Failed to write to file: " + file.error);
			}
		} catch(e) {
			alert('Failed to write to file: ' + e + ":" + e.line);
		} finally {
			file.close();
		}
 
		conn.close();
	}
}
 
 
execute_modifications();

More documentation at:
Javascript Tools Guide (Page 17 is where it gets interesting)
Photoshop Scripting