OpenMSS
Open Firmware for Maxtor Shared Storage
Forum Chat

General

Hardware

OpenMSS Firmware

Original Firmware

Development

Related


How to automatically download torrents with the MSS

On this page…

Summary

This is an updated version of my TorrentDownloader. It contains a couple of new features, and several bugfixes. It allows you to search and queue torrents from multiple sites, as well as subscribe to RSS feeds of popular TV shows.

Requirements

On the MSS:

  1. CTorrent
  2. lsof
  3. crond

You can install both CTorrent and lsof on your MSS by using ipkg, this will be explained under installation.

On your webserver*:

  1. PHP4
  2. Writeable cache-dir.
  3. Make sure register_globals is OFF! Disable it by adding this line to your .htaccess:

php_flag register_globals off

* It is possible to install Lighttpd with PHP and run the PHP script on you MSS, I haven’t tried this myself, but it should not be any different from installing it on a webserver. Take a look at the forum for PHP installation instructions.

How it works

This collection of scripts will allow you to administrate your torrent downloads remotely. In its most complete form it consists of a website to administrate and manage your downloads and two scripts on your MSS/Kurobox that download torrents automatically.

The use of the website scripts is not neccessary, since the shell scripts function fine without them. Just make sure to set the option for the RSS feed in q3.sh to “no” and the option for url in watchdog.sh to “no” as well. Simply copying .torrent files to the Q3 inbox/ directory will trigger the downloads.

Download

You can find the scripts at my site: Q3.zip

Installation

First and foremost, you need to install CTorrent. This can be done with ipkg. Log on to your MSS and type in the following:

# ipkg update
# ipkg install ctorrent

This will download CTorrent and install it automatically. Do the same for lsof:

# ipkg install lsof

There are several preferences in either of the scripts that will need to be adapted to your situation, I will explain these in their separate sections.

On the webserver

Before you can install the scripts on your webserver, you’ll have to change some default values. After unzipping, you’ll find these in a file called users.php in the lib/ directory. It should look like this:

	// System-wide settings

	define( 'QCOOK', 'Q3' );
	define(	'QTIME', time() + ( 14 * 86400 ) );
	define( 'REDIR', false );

	// User settings

	$user[]	=	array(
				'user' => 'Admin',
				'pass' => 'changeme'
			);

The value you want to change is “changeme”, that’s your password… ;o)

After these simple changes, you can upload all files in the “website” directory to your webserver.

There is one thing you have to do to complete this step. You need to make the directory cache/ writeable on your webserver, CHMOD it to 755 in your FTP program.

On the MSS

I’ve set apart a seperate share for any torrent activity, but you are free to set the script up in any way you want. On my MSS I have an “incoming”-share where I keep the script, the torrents and the data as it downloads. When the download is finished, the script moves it to another location. You can change these settings in the script, just as with the PHP script. Let’s assume you have a dir called “Downloads” in your Public share on the MSS and q3.sh and watchdog.sh are in there, as well as the inbox/ , log/ and temp/ dirs, so basically everything in the mss dir from the archive. The q3.sh script should look like this:

rss=http://YOURWEBSITE/cron.php?rss=YOUR_RSS_ID
dst=/shares/mss-hdd/Public/Other
own=guest

The rss setting can be copied and pasted from the website (the little orange RSS icon is the url to your RSS feed).

In watchdog.sh make sure you copy the YOUR_RSS_ID bit from your actual RSS feed url over here:

url=http://YOURWEBSITE/cron.php?mark=YOUR_RSS_ID

If you don’t want to use the website functionality, simply change the rss and url settings to “no” in both q3.sh and watchdog.sh respectively.

After setting up the variables to reflect the situation on your MSS. It’s time to set up a cron job. Cron is built into Busybox, but it’s not part of the Busybox in OpenMSS 1.2.2-rc3. If you are running OpenMSS 1.2.2-rc3, it’s time to update Busybox using ipkg:

# ipkg install busybox

After installing the new Busybox, you can try typing:

# crontab -e

If you get an error (which I did the first time), it means cron is just missing some directories. Just type this:

# mkdir -p /opt/var/spool/cron/crontabs

That should solve the problem. Now, when you do crontab -e you can add the torrent script, but first we’re going to make sure cron starts every time the MSS boots. Type the following:

# cd /opt/etc/init.d
# vi S99Local

VI can be a bit annoying, but to edit something, you first have to enter “edit mode” by pressing “i”. Then, add “crond &” after “utelnetd &”, like this:

!/bin/sh
utelnetd &
crond &
~

Exit “edit mode” by pressing “Esc” and type the following to exit the vi editor and save your changes: “:x” and press enter. Now, simply start up cron by hand by typing:

# crond &

And you’re all ready to add the q3.sh script as a cron job, just try “crontab -e” again and add the following line:

3 */6 * * * /shares/mss-hdd/Public/Downloads/q3.sh

Let me break that down:

The first bit with the stars determines when cron will start the second bit. It consists of: minutes, hours, day, month, weekday. In our case it’s set to: every third minute, every 4 hours (24/6), any day, any month, any weekday.

So every four hours it will start: /shares/mss-hdd/Public/Downloads/q3.sh - simple as that.

Instructions

After a succesful installation, you can see whether the q3.sh script is checking your website (or not if you configured it that way) by looking at log/progress.log (if you don’t want to wait four hours, trigger the script by executing it manually with ./q3.sh when you’re in its dir):

# cd /shares/mss-hdd/Public/Downloads/log
# tail progress.log

================================
Q3 Download manager started at:
Sat Feb  3 12:03:02 CET 2007

Downloading RSS feed...
Fetching new torrent files...

Checking the inbox for new torrents...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All torrents processed, ending at:
Sat Feb  3 12:03:06 CET 2007
Removing pid...

This means it’s time to add some torrents to your queue! Go to the following url to log in (where queue is the name of the directory you’ve uploaded the script to): http://yoursite.com/queue/index.php?login

The script will present you with a login page. Type in your username in the first box and your password in the second and press “Login” to log in. Next, you’ll see a screen consisting of four parts: Manage Queue, Manage Subscriptions, Search Miscellaneous and Search Television. I will explain them in reverse order.

Search Television:

This allows you to search from a selection of television shows and subscribe to them. When you subscribe to a show, new episodes will automatically be added to your download queue when they become available. The search function is a suggested search, just enter a few letters and all the available options will automatically appear. Click on a show to see the available episodes. Keep in mind that most older episodes are usually not available. You can subscribe to a show by clicking on the title of an episode. If you wish to make changes to your subscription, you can do that on the Manage Subscriptions tab.

Search Miscellaneous:

This is the main search. You can search on several well-known torrent search engines, just enter a search term, select a search engine and click “Find” to see a list of results. The results are colour-coded: Green = good, Blue = reasonable and Red = difficult to impossible. Also, some search engines return torrents that require registration, these are listed in italics. Simply click on a title to add the torrent to your queue.

Manage Subscriptions:

This is an overview of all the television shows you are subscribed to, you can edit the settings by clicking on a title. You can then change several options, the most important being the episode number you are at right now. Sometimes, a certain episode won’t download successfully, so you’ll need to come back here and change the episode number back to the most recent one in your possession, this will trigger a new download of the following episodes.

Manage Queue:

The queue lists all torrents that are waiting to be downloaded. You can edit torrents by clicking on their title, this way you can change their name, priority or remove them from the queue. Torrents that have been downloaded to the inbox on your MSS/Kurobox are marked as “Fetched” with a priority of 0. They remain at the bottom of the queue, and you can remove them by clicking “Clear old queue entries” when they’re done.

That’s about it! I hope this works for you as well as it does for me!

Addendum

Additional search engines

In the lib/ directory, you’ll find a file called engines.php . You can define additional engines for other search sites if you’d like. Use one of the existing engines as an example and I’m sure you’ll be able to figure it out.

Edit Page - Page History - Printable View - Recent Changes
Page last modified on 05.10.2007, at 12:31 CEST
© 2005-07 Jon Suphammer. All Rights Reserved.