Remotely Send torrent from webbrowser to ruTorrent (uTorrent and wTorrent)

saroos1

Member
May 25, 2018
718
0
16
Hey I found this script at userscrits.org and modified it a bit. I have gotten it to work with Firefox + greasemoneky and Opera. It works out-of-the-box on all URLs that ends with .torrent but you can add more yourself just edit the script, its pretty easy, all explained inside it.

I have tested this with ruTorrent on Firefox (needs greasemonkey) and Opera (without authentication but Im sure you can find out how to make it work with too maybe something like user:[email protected]/rutorrent).

Okay heres the script:

Firefox:
greasemonkey
http://www.greasespot.net/
script
http://userscripts.org/scripts/show/76489

Opera:
I have put an attachment here that is the script for Opera users.
(yea I know this is ruTorrent forum still info belongs smiley.gif ) I know wTorrent will not work since the script uses Greasmonkey commands I do not know how to edit to make it work. As for uTorrent I havent looked into it really but it seems uTorrent uses a Cookie function and need to be setup to be used and Im not sure how to do that, if you really need to do anything at all.

And there might be unused code in the script but I belive it to be of little importance.

To use the script in opera you have to open the script and edit the settings as in firefox there is a setup function thats not in opera, however I have put in explenations and there should only be 2 settings to edit smiley.gif

How to enable User JavaScripts in Opera
Quote
To enable user JavaScript, use Tools > Preferences > Advanced > Content > JavaScript options, and select the directory where you will put your User JavaScript files. Opera will load all files in the specified directory whose names end with .js and will use them as User JavaScript files. If a file name ends with .user.js it will be assumed to use Greasemonkey notation.​


In case the attachment dont work, or gets removed after a while of being untouched heres the script for Opera (save in the folder u choose above and call it whateveryouwant.user.js)

Code:
// ==UserScript==
// @name Frag.Mine.Nu :: Send torrent to (u/ru/w)Torrent WebUI
// @namespace idkwhattoputhere
// @include *
// ==/UserScript==

// Frag.Mine.Nu :: Send torrent to uTorrent WebUI by Rain724 (modified by Penetal)

// Adding custom site instructions:
// Ok, the system I programed is kind of hard to explain, although it seems like the best way to
// manage mutipal sites with different codebases.
// On to the instructions:
// The format of siteArray is:
// 1 - Name of site. (If the torrent site you are trying to add is: thetorrentsite.org, the name would be "thetorrentsite" w/o the .org)
// 2 - Strip SSL. (If the site is using an unsinged SSL certificate uTorrent might not like it. If so, set this to "1" for that site. ruTorrent and wTorrent auto-overide this to accept SSL)
// 3 - Use cookies. (Some site require cookies to download torrents, if so, set this to "1")
// 4 - Search String 1 (String of text in every download url, like "action=download" or "download.php")
// 5 - Search String 2 (A string of text that is NOT in every download url.** EXPLAINED BELOW **)
// 6 - Link text (By defualt, "?T " is used on What, although some sites " Send to wUI" looks better. This can be any string of text though)
// 7 - Separation text (Text that will show up before the Link text, if no Separation text is needed, set it to "")
// 8 - set to 1 if you want "Search String 1" to only search the very end of the url for your word.
//
// ** SEARCH STRING 2 **
// Some sites have a .torrent download link AND a .zip or .txt download link. If this is the case, set this to ".zip", ".txt", or some other string of text that comes up in every .zip/.txt link.
// If the site you are trying to add to the script DOES NOT have a 2nd download link for .zip/.txt, set Search String 2 to "?"
var siteArray = []; // << DO NOT EDIT THIS LINE
siteArray[0] = [".", "0", "0", ".torrent", "details", "WebUI", "-{remote}-", "1"];


/*Set webUI mode:
What webUI are you using?
1) uTorrent
2) ruTorrent
3) wTorrent
Type 1,2, or 3 below
leaveing it as 0 it will not work.
*/
var webUIType = "0";

/*
What is your wTorrent hostname or ip address?
(ex: "1.2.3.4" or "user.seedboxservice.com")
If you are useing ruTorrent remember to put the whole adress to the webUI
(ex: "yourdomain.com/rutorrent")
*/
var webIP = 'somesite.com';

/*
if you use wTorrent edit below aswell
IMPORTANT! I do not expetc that wtorrent will work until
the part below is working, I do not know how to fix this
section from greasemonkey to a form that opera can understand
its the GM_ that wont work as its a GreaseMoneky command.

I have commented out the function below to reduse js errors.

function post(url, data, func) {
GM_xmlhttpRequest({
method: "POST",
url: url,
headers:{'Content-type':'application/x-www-form-urlencoded'},
data: data,
onload: function(xhr) { func(xhr.responseText); }
});
}
this function is operating longer down in the script.
if you are able to fix it please post it!!
*/

var wtorrent_connect_string;
//this is just for those who use wTorrent
if (webUIType == "3")
{
var wHost = webIP;

//What port is your wTorrent running on?
var wPort = '';
//What is your wTorrent username?
var wUser = '';
//What is your wTorrent password?
var wPass = '';
//Do you want torrents to be added to wTorrent as private? "1" for yes, "2" for no.
var wPvtAdd = '';
//Is your wTorrent running on an ssl encrypted server? "1" for yes, "2" for no.
var wSSL = '';
//Do you want downloaded torrents to autostart? "1" for yes, "2" for no.
var wStart = '';
if (wSSL == "1") { wtorrent_connect_string = 'https://'+wHost+':'+wPort+'/'; } else { wtorrent_connect_string = 'http://'+wHost+':'+wPort+'/'; }
post(wtorrent_connect_string,'userf='+wUser+'&passwdf='+wPass+'&user_login=Login', function(info) { var isLoggedIn = true });
}



/////////////////////////////////
// DO NOT EDIT BELOW THIS POINT//
/////////////////////////////////



//Rest of script
var useCookie = "0";
var innerSep = "";
var isWhat = "";
var stripssl = "";
if(webUIType == "1" || webUIType == "2")
{
var ifEventListener = false;
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.style.display = "none";
}

start();
function start()
{
var links = getLinks();
for (var i=0, link; link = links[i++]; )
{
if (match(link.href))
{
if (stripssl == "1")
{
link.href = link.href.replace(/http?s/, "http");
if (isWhat == "1")
{
link.href = link.href.replace(/ssl/, "www");
}
}
var uTorrentLink = makeUTorrentLink(link);
link.parentNode.insertBefore(uTorrentLink, link.nextSibling);
var separator = makeSep();
link.parentNode.insertBefore(separator, link.nextSibling);
}
}
}

function makeUTorrentLink(link) {

var uTorrentLink = document.createElement('a');
var theCookie = setCookie();
var uTorrentFrameSrc = makeWebUILink(webIP, link.href, theCookie);
var wTorrentTorrentURL = link.href;
uTorrentLink.href = uTorrentFrameSrc;
if (webUIType == "1" || webUIType == "2")
{
uTorrentLink.addEventListener("click",
function(e) {
iframe.setAttribute("src", uTorrentFrameSrc);
if(!ifEventListener) {
iframe.addEventListener("load", function() {
window.alert("Torrent added!");
}, false);
ifEventListener = true;
}
e.preventDefault();
}, false);
}
if (webUIType == "3")
{
var wTorrentRequestURL = 'torrenturl='+encodeURIComponent(wTorrentTorrentURL);
if (wPvtAdd == "1")
{
wTorrentRequestURL = wTorrentRequestURL+'&private=on';
}
if (wStart == "1")
{
wTorrentRequestURL = wTorrentRequestURL+'&start_now=on';
}
uTorrentLink.id = wTorrentRequestURL;
uTorrentLink.addEventListener("click", function(e) { e.preventDefault(); wTorrentClick(e)}, false);
}
uTorrentLink.innerHTML = linkText;
return uTorrentLink;
}
function makeWebUILink(webIPforLink, linkhref, cookie)
{
if (webUIType == "1")
{
return "http://"+webIPforLink+"/gui/?action=add-url&s="+escape(linkhref)+cookie;
}
if (webUIType == "2")
{
return "http://"+webIPforLink+"/php/addtorrent.php?url="+escape(linkhref)+cookie;
}
if (webUIType == "3")
{
return 'wtorrent:'+linkhref;
}
}

function makeSep() {
var separatorText = document.createElement("text");
separatorText.innerHTML = innerSep;
return separatorText;
}

function wTorrentClick(sent)
{
sent = sent.target.id;
post(wtorrent_connect_string+'index.php?cls=AddT', sent, function(addedResponce) {
var match_added = /Torrent added correctly/gmi;
var already_exists = /Error: File already exists in torrent directory, can't create .torrent/gmi;
if (addedResponce.match(match_added)) {
alert('Torrent Successfully Added wTorrent!');
}
else if (addedResponce.match(already_exists)) {
alert('Torrent has already been added to wTorrent!');
}
else {
alert('Something is broken! Verify that you entered your wTorrent details/information correctly!');
}
})
}

/*function post(url, data, func) {
GM_xmlhttpRequest({
method: "POST",
url: url,
headers:{'Content-type':'application/x-www-form-urlencoded'},
data: data,
onload: function(xhr) { func(xhr.responseText); }
});
}*/

function setCookie() {
if (useCookie == "1")
{
return escape(":COOKIE:") + escape(document.cookie.replace(" ", ""));
}
return "";
}

function getLinks()
{
var doc_links = document.links;
var links = [];
for (var i=0, link; link = doc_links[i++];) {
links.push(link);
}
return links;
}

function match(url) {
for (var i=0;i<siteArray.length;i++)
{
if((siteArray[7]=="1") && url.match(siteArray[0]) && (url.lastIndexOf(siteArray[3])==(url.length-siteArray[3].length)) && !url.match(siteArray[4]))
{
if(siteArray[1] == "1" && webUIType != "2" && webUIType != "3") { stripssl = "1"; }
if(siteArray[2] == "1") { useCookie = "1"; }
if(url.match("ssl.what.cd")) { isWhat = "1"; }
if(siteArray[6] != "") { innerSep = siteArray[6]; }
if(siteArray[5] != "") { linkText = siteArray[5]; }
return 1;
}
else if((siteArray[7]=="0") && url.match(siteArray[0]) && url.match(siteArray[3]) && !url.match(siteArray[4]))
{
if(siteArray[1] == "1" && webUIType != "2" && webUIType != "3") { stripssl = "1"; }
if(siteArray[2] == "1") { useCookie = "1"; }
if(url.match("ssl.what.cd")) { isWhat = "1"; }
if(siteArray[6] != "") { innerSep = siteArray[6]; }
if(siteArray[5] != "") { linkText = siteArray[5]; }
return 1;
}
}
}
 

simur612

Member
May 25, 2018
879
0
16
nice work! I'm going to sticky this....though i might end up moving it to another category.
 

peshua19

Member
May 25, 2018
897
0
16
thank you not bad for my first post wink.gif feels good give what little I can back to this amazing project
 

lisas4567

Member
May 25, 2018
773
0
16
yes, this is nice. I'd eventually like to see a plugin for firefox and/or chrome which does the same thing. This is still very nice.
 

saroos1

Member
May 25, 2018
718
0
16
I did this as a workaround for the lack of a feature to have popup window in the webUI that can add the torrent in the search plugin. which would be a nice feautre

Edit: will put that as a request now I think grin.gif
 

randac56

Member
May 25, 2018
915
0
16
I'm not sure I understand *what* this script is doing...
Correct me if my understanding is wrong:

1. Visit some private/public torrent website on your local desktop.
2. Find a .torrent file available there that you'd like to download
3. Run this greasemonkey script on that URL which will send the .torrent download link to your remote rutorrent box, causing it to be added to rutorrent automatically. Cookies and auth values are handled automagically so the private torrentsite doesn't bark at you for browsing/grabbing the torrent from different IPs

is this correct?
 

peshua19

Member
May 25, 2018
897
0
16
By no means do I want to come off as a smartass but sending torrents from my browser to seedbox (thus utorrent) takes two lines of code (if you even want to go as far as calling it that), namely

For windows:
@echo off
scp %1 user@host:/path/to/rtorrent/watchdir

For linux:
#!/bin/bash
scp $1 user@host:/path/to/rtorrent/watchdir

save as .bat or .sh file (+ make executable), set as default app for handling torrents in your browser. No need to jump through hoops and add a torrent through a web interface, all you need is the scp binary and a private/public keypair for your server.
 

lisas4567

Member
May 25, 2018
773
0
16
This script installs in Chromium, but I have no way of getting the settings page because Chromium has only rudimentary Greasemonkey support.



Uploaded with ImageShack.us

Edit 1:
This only works for public trackers (meaning no unique passkey).
Pretty much useless to me. wink.gif
 

saroos1

Member
May 25, 2018
718
0
16
This script installs in Chromium, but I have no way of getting the settings page because Chromium has only rudimentary Greasemonkey support.
Use https://chrome.google.com/extensions/detail/pipnnjjknlabchljabhmnpdfpdobpnkk to edit scripts in chrome. You have to re-intall the script with this running after deleting it from tools > extensions so that you aren't weighing down chrome. You actually can go finding the scripts in chrome and edit it but such a pain.