FatRat Extension Tutorial
JavaDoc »
Basic procedure
- Subclass any of DownloadPlugin, UploadPlugin, ExtractorPlugin, SearchPlugin or AccountInfoPlugin. Place your class(es) info the info.dolezel.fatrat.plugins package.
- Annotate your classes. For instance, use DownloadPluginInfo for a DownloadPlugin.
- Build a .jar and place it into ~/.local/share/data/java.
- Use it.
Basic rules
- The methods you implement may never block, everything must be asynchronous. Use BackgroundWorker if you need to perform a CPU intensive task or do a blocking call.
- Use Plugin.fetchPage() to fetch all the URLs you need. It keeps track of all cookies, so that they can be later used by FatRat.
- Use DownloadPlugin.startWait() to do countdowns.
- Use DownloadPlugin.solveCaptcha() to ask the user to solve a captcha.
- Do not write into the filesystem, it won't work. Extensions are running in a sandbox.
- Fill the annotation values properly!
- Your work must always end with a success or failure call, before you return to FatRat. The only apparent exception is when you're waiting for a callback from FatRat (downloading a page, countdown, waiting for a captcha solution...).
- FatRat ships with the following libraries: Apache Commons IO, Apache Commons Lang, Apache Commons Codec, org.json.
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);
}
});
}
}