Rapidshare.com Link Checker

This is currently outdated but is here for archival purposes. The code was hacked together and is barely an example of good coding. You may however look at it, and try it out if you wish.

- N.

How to install it

You should see a bar at the top of the page asking you to subscribe to the Ubiquity command. If not, then you either do not have Ubiquity installed, or you are already subscribed to the command. You can find more information on how to install Ubiquity and how to expand it on another page.

How to use it

  1. Select a part of the page which contains links to files on the rapidshare.com filehosting service.
  2. Open up ubiquity (ALT+SPACE for me), and type: rscheck.
  3. You should automatically see the links, listed below in the preview pane, and you can now hit Enter.

How it works

After you hit enter, the script will go through the process of extracting rapidshare.com links from the selection. The links will be combined and sent to the checkfiles service on rapidshare.com. The script will then check the returned data, and parse the selection based on the reply from the server.

What will happen after it is run

Files which are no longer available will have their current link stripped and will have a line through them.

Files which are currently available will be linkified (if not already) and will be italicized.

The Script

/***************************************************************************
 *
 *	Project: RSChecker, A Rapidshare link checker for the Ubiquity
 *	extension of Mozilla Firefox Browser.
 *
 *	Creator:	Nasser Al-Hilal
 *	Date:		September 8th, 2008
 *	Version:	1.0
 *
 */
 
// some global variables
var rs_href_match;
var rs_rogue_match;
var rs_objects;
 
function rs_link_object(a,b,c,d,e) {
	this.text = a;
	this.href = b;
	this.name = c;
	this.type = d;
	this.available = e;
}
function rs_get_link_status(dom) {
	dom = dom.replace(/[nrt]/g,'');
	var re = /<p>(.*?)<td>(.*?)<td(.*?)<div class="downloadlink">(.*?)<(.*?)</p>/ig;
 
	var results = new Array();
 
	// loop through and get all possible matches into an array
	var c = 0;
	do {
		found = re.exec(dom);
		if (found == null) {break;}
		results[c] = found;
		c++;
	} while (found != null);
 
	// loop through, and parse results
	for (var i=0; i<results.length; i++) {
		found = results[i];
 
		// here since we need to only check if the link exists
		// to set it up, we get the object related, and we
		// set the available property accordingly
		for (var k = rs_objects.length - 1; k >= 0; k--){
			if (found[4] == rs_objects[k].href) {
				// the link matches the href, so we need to see
				// if it exists or not
				if (found[2].indexOf("does not exist") > -1) {
					rs_objects[k].available = false;
				} else if (found[2].indexOf("File is on") > -1) {
					rs_objects[k].available = true;
				} else {
					// we found the link, but got no return value
					// set to unknown
					rs_objects[k].available = "unknown";
				}
			}
		};
	}
	// return nothing, since this function only modifies
	// the global objects.		
	return true;
}
function rs_display_link_status(htmlstuff) {
	// here is the messy part, this is where we will modify the original links to reflect availability
	content = htmlstuff;
	for (var i = rs_objects.length - 1; i >= 0; i--){
		switch (rs_objects[i].type) {
			case "href":
				// since this is a href, if available, we will leave as is
				// but if not available, we will wrap the a with a span,
				// that crosses out the text
				// if we want to remove the text, we just set new a tag to ''
				if (rs_objects[i].available != true) {
					var new_a_tag = "<span style='text-decoration: line-through;'>" + rs_objects[i].name + "</span>";
 
				} else { // conver to italics
					var new_a_tag = "<span style='font-style: italic;'>" + rs_objects[i].text + "</span>";
				}
				content = content.replace(rs_objects[i].text,new_a_tag);
				break;
			case "rogue":
				// in a rogue situation, we add a link to the text.
				if (rs_objects[i].available == true) {
					var new_a_tag = "<a href='" + rs_objects[i].href + "'>" + rs_objects[i].href + "</a>";
				} else {
					var new_a_tag = "<span style='text-decoration: line-through;'>" + rs_objects[i].href + "</span>";
				}
				content = content.replace(rs_objects[i].text,new_a_tag);					
			break;
		}
	};
	// return the modified content		
	return content;
}
 
CmdUtils.CreateCommand({
    name: "rscheck",
    takes: { "Urls" : noun_arb_text },
    icon: "http://rapidshare.com/img2/favicon.ico",
    homepage: "http://www.nasser.me/rapidsharecom-link-checker",
    author: "Nasser Al-Hilal",
    license: "MPL",
    description: "Checks rapidshare.com links.",
    help: "You can select links and run this command to check them, unavailable links will be parsed with a line through them. Available links will be italicized.",
 
	_get_rapidshare_links: function(content_type) {
		var content = CmdUtils.getHtmlSelection();
 
		if (content_type == "href") {
			var regexp = /<a(.*?)href=('|")(s*)(http://rapidshare.com/files/[0-9]+/(w|.|-)*(w)+?)(s*)('|").*?>([^]*?)</a>/gi;
		} else if (content_type == "rogue") {
			var regexp = /http://rapidshare.com/files/[0-9]+/(w|.|-)*(w)+/ig;
		} else { // bleh, just return an empty string
			return "";
		}
 
		var results = new Array();
		var rslinks = new Array();
 
		// loop through and get all possible matches into an array
		var c = 0;
		do {
			found = regexp.exec(content);
			if (found == null) {break;}
			results[c] = found;
			c++;
		} while (found != null);
 
		for (var i=0; i<results.length; i++) {
			found = results[i];
 
			// create an object and set the values
			// (match_text, link_href, link_name)
			// in rogue case, we only need the match text
			// in href case, we need a different schema
			if (content_type == "href") {
				var alink = new rs_link_object(found[0],found[4],found[9],"href");
			} else if (content_type == "rogue") {
				var alink = new rs_link_object(found[0],found[0],found[0],"rogue");
			} else { // didn't we exit once before? err.
				return "";
			}
 
			// clear the name and link fields too 
			// before creating the object
			//alink.name = alink.name.replace(/[nrt]/g,'');
			alink.href = alink.href.replace(/[nrts]/g,'');
 
			rslinks[i] = alink;
 
		}
		return rslinks;	
	},
 
	_get_rapidshare_unique: function() {
		rs_href_match = this._get_rapidshare_links("href");
		rs_rogue_match = this._get_rapidshare_links("rogue");
 
		// set global variable to rapidshare objects
		// remove elements in rogue who already are in
		// a href object
		var rs_rogue_tmp = new Array();
		var rogue_href_found = false;
		for (var i = rs_rogue_match.length - 1; i >= 0; i--){
			for (var j = rs_href_match.length - 1; j >= 0; j--){
				if (rs_rogue_match[i].href == rs_href_match[j].href) {
					rogue_href_found = true;
				}
			};
			if (!rogue_href_found) { 
				rs_rogue_tmp.push(rs_rogue_match[i]); 
				rogue_href_found = false; 
			}
		};
		rs_rogue_match = rs_rogue_tmp; // new global variable change
 
		rs_objects = rs_href_match.concat(rs_rogue_match); // global variable set
 
		var rs_unique = new Array();
 
		// get rapidshare links into string
		for (var i = rs_objects.length - 1; i >= 0; i--){
			// read values into the unique array
			// which will be sorted out later
			rs_unique[i] = rs_objects[i].href;
		};
 
		// sort out unique array.
		rs_unique = rs_unique.sort();
 
		// reverse them, from smallest to largest
		// dosn't really matter, but fun anyway
		rs_unique = rs_unique.reverse();
 
		return rs_unique.join("n");
	},
 
 
    preview: function( pblock ) {
	// add functionality in the next version to take input from the ubiq cli
        var msg = "Check these links: <br/> ${rslinks} <br/><br/>Checks links on Rapidshare.com.";	
        pblock.innerHTML = CmdUtils.renderTemplate( msg, {rslinks: this._get_rapidshare_unique()} );	
    },
 
    execute: function() {
 
        var postUrl = "http://rapidshare.com/cgi-bin/checkfiles.cgi";
        var txtUrls = this._get_rapidshare_unique();
		var content = CmdUtils.getHtmlSelection();
 
		if (txtUrls.length <= 0) { displayMessage("No links to check"); return; }
 
        jQuery.post(postUrl, {urls: txtUrls}, function(html) {
			// the post call to check the images was a success,
 
			// parse the page first
			rs_get_link_status(html);
 
			// now, parse the content to be edited
			CmdUtils.setSelection(rs_display_link_status(content));
 
			displayMessage("Done querying Rapidshare.com!")
		});		
	}
});

Updates

Thursday 23 October 2008

  • Fixed some typos in the display of the code on this page.
  • Fixed typo of web address for the script in the javascript file
Be Sociable, Share!

  1. Fixed some stuff on the page, added an updates section.

  2. I hope you’ll update the script for the current version of ubiquity, because there are some problems with the italication / stroking – working links are stroked sometimes – also there’s no indicator for installing your script on this site.

    greetings.
    mel

  3. ok – the install indicator pops up after I press the submit comment button :)

  4. Thank for the feedback mel!

    What version of Ubiquity are you using? I’ll check it and report any updates in the comments.

  5. Ubiquity 0.1.8

    :)

Leave a Comment