FatRat Extension Tutorial

JavaDoc »

Basic procedure

  1. Subclass any of DownloadPlugin, UploadPlugin, ExtractorPlugin, SearchPlugin or AccountInfoPlugin. Place your class(es) info the info.dolezel.fatrat.plugins package.
  2. Annotate your classes. For instance, use DownloadPluginInfo for a DownloadPlugin.
  3. Build a .jar and place it into ~/.local/share/data/java.
  4. Use it.

Basic rules

Examples

A simple download class

package info.dolezel.fatrat.plugins;

import info.dolezel.fatrat.plugins.annotations.DownloadPluginInfo;
import info.dolezel.fatrat.plugins.listeners;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@DownloadPluginInfo(name = "My example extension", regexp = "http://www.example.net/.*", forceSingleTransfer = false, truncIncomplete = true)
public class DownloadPluginExample extends DownloadPlugin {
	private static final Pattern reSimple = Pattern.compile("This is the link: (\\S)");

	public void processLink(String link) {

		// Let's first fetch the link
		fetchPage(link, new PageFetchListener() {
			void onCompleted(ByteBuffer buf, Map<String,String> headers) {

				// Assume the page is UTF-8 encoded
				CharBuffer cb = charsetUtf8.decode(buf);
				Matcher m = reSimple.matcher(cb);
				
				if (m.find())
					startDownload(m.group(1));
				else
					setFailed("Failed to find the link");
			}

			void onFailed(String error) {
				DownloadPluginExample.this.setFailed(error);
			}
		});
	}
}