Make a Rapid-share Up-loader

Since I don’t make any new posts for quite a while now, I decided to reward you all with a new tutorial, “How to make a Rapid-Share  up-loader”, with this tutorial you will learn how to code a application capable of uploading, automatically, files to, the well known file-hosts, “rapid-share” and “easy-share” and it will return the “download” and “delectation” links.
(The code is made in Delphi)

1. Get the necessary HTML variables

To start with, we need to analyze the form which rapid-share uses to submit the files to their server, this can be done by seeing the page source code:

Shows the rapidshare source code

Let’s take a look at the form code:

<form action="http://rs241l3.rapidshare.com/cgi-bin/upload.cgi?rsuploadid=149017462993654077" enctype="multipart/form-data" method="post">
<div id="progbar" style="display:none;">
<div style="font-size:8pt;">You are uploading:</div>
.</div>
<div id="dateiwahl">
<table style="font-size:8pt;color:#002760;" border="0">
<tbody>
<tr>
<td align="left">
<div id="files">

<a style="font-size:8pt;color:#002760;" href="javascript:switchfiles()">Do you want to upload several files? Please click here</a>
| Maximum upload size 200 MB | Split archives allowed!

<input id="dateiname" name="filecontent" size="65" type="file" /></div></td>
</tr>
</tbody></table>
<div id="infotextfeld" style="display: block; width: 400px; text-align: left;">Share your files for FREE via RapidShare.com!
<a href="http://rapidshare.com/howto_upload.html" target="_blank">Upload assistance</a>
<ol style="color:#002760;">
 <li><strong>Select file and click the upload button</strong></li>
 <li>Share download link</li>
</ol>
Delete your files any time you want.</div>
<input id="btnupload" style="display:none;" name="u" src="/img2/upload_file.jpg" type="image" /></div>
</form>

Let’s remove everything we don’t need:

<form action=”http://rs241l3.rapidshare.com/cgi-bin/upload.cgi?rsuploadid=149017462993654077″ enctype=”multipart/form-data” method=”post”>
<input id=”dateiname” name=”filecontent” size=”65″ type=”file” />
</form>
Finally we can analyze the data:

action=”http://rs241l3 .rapidshare.com/cgi-bin/upload.cgi -> This is the URL we will use to make the post. In Brown you can find the rapid-share server, there’s more then one, our application will use them all.

rsuploadid=149017462993654077 -> This isn’t really necessary, though since we want to make a pretty uploader we will use it.

enctype=”multipart/form-data” -> Obviously the form enctype is a “multipart/form-data”

name=”filecontent” ->This is the variable which will “store” the file and then be sent to the server.

Now that we have all the information we can start coding our app

2. Creating the “Project”

In delphi, start a new project:

rapidshare start new project

Once you’ve done this, make your form look like this:

rapidshare uploader form

Now drop a TidHTTP component on the form:

rapidshare tidhttp

and also drop a OpenDialog component:

rapidshare opendialog

3. Configuring Indy HTTP

Let’s configure the indy events:

rapidshare idhttp events

Make it like this:

rapidshare events code

Now that our “IdHTTP” component is configured let’s proceed.

3. The code

Like you saw on the first step, we will need to extract text from inside HTML tags, I created a easy-to-understand function that we will use in this tutorial:

add the following in your uses “StrUtils”

function TfmMain.GetInnerHTML(FullText: WideString; TagBegin: string; TagEnd: string): string;
var
position: integer;
middle: string;
begin
position := AnsiPos(TagBegin, FullText) + Length(TagBegin); { Get to know where the dam tag is }
middle := AnsiMidStr(FullText, position, Length(FullText)); { Cut the text behind the tag }
position := AnsiPos(TagEnd, middle)-1; { Get to know where's the ending tag }
result := AnsiLeftStr(middle, position); { Cut the text in front of the ending tag }
end;

Now we need to get the uploading link, let’s use our function:

procedure TfmMain.btnUploadFileClick(Sender: TObject);
var
UploadLink: String;
HTMLtoCheck : WideString;
begin
{ Get the upload link }
HTMLtoCheck := IdHTTP1.Get('http://www.rapidshare.com');
UploadLink := GetInnerHTML(HTMLtoCheck,'action="','"');
{ Clear the whole HTML Text to free up some memory }
HTMLtoCheck := '';
end;

the link is on our hands so let’s get the file dialog working, so that we can make the uploading code:

procedure TfmMain.btnBrowseFileClick(Sender: TObject);
begin
OpenDialog1.Filter := 'All Format Files | *.*';
if OpenDialog1.Execute then
begin
txtFile.Text := OpenDialog1.FileName;
end;
end;

the button done, let’s continue:

add the following in your uses “IdMultipartFormData”

procedure TfmMain.btnUploadFileClick(Sender: TObject);
var
UploadLink: String;
HTMLtoCheck : WideString;
FormStuff : TIdMultiPartFormDataStream; {multi-part-form post data}
begin
{ Get the upload link }
HTMLtoCheck := IdHTTP1.Get('http://www.rapidshare.com');
UploadLink := GetInnerHTML(HTMLtoCheck,'action="','"');
HTMLtoCheck := '';
FormStuff := TIdMultiPartFormDataStream.Create; {Create the multi-part-form class}
try
FormStuff.AddFile('filecontent',txtFile.Text,'multipart/form-data'); {add the file}
HTMLtoCheck := IdHTTP1.Post(UploadLink,FormStuff); {make the post}
finally
FreeAndNil(FormStuff); {Free and nil the class}
end;
UploadLink := ''; {free some memory}
end;

all we need now is to get the download and delete link:

procedure TfmMain.btnUploadFileClick(Sender: TObject);
var
UploadLink: String;
HTMLtoCheck : WideString;
FormStuff : TIdMultiPartFormDataStream; {multi-form post data}
begin
{ Get the upload link }
HTMLtoCheck := IdHTTP1.Get('http://www.rapidshare.com');
UploadLink := GetInnerHTML(HTMLtoCheck,'action="','"');
HTMLtoCheck := '';
{ MAKE THE UPLOAD }
FormStuff := TIdMultiPartFormDataStream.Create; {Create the MultiPartForm class}
try
FormStuff.AddFile('filecontent',txtFile.Text,'multipart/form-data'); {add the file}
HTMLtoCheck := IdHTTP1.Post(UploadLink,FormStuff); {make the post}
finally
FreeAndNil(FormStuff); {Free and nil the class}
end;
UploadLink := ''; {free some memory}
{ GET THE LINKS }
txtDownloadLink.Text := GetInnerHTML(HTMLtoCheck,'<div>','</div>');
txtDeleteLink.Text := GetInnerHTML(HTMLtoCheck,'<div>','</div>');
end;

And voilà! You got yourself a rapid-share fully automatic uploader!

rapidshare done

I’ve attached the full project (exe + source + some modifications) :

http://pedroproenca.info/RS%20Uploader.rar

 banner ad

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.



One Response to “Make a Rapid-share Up-loader”

  1. Paulo Mota says:

    E eu a pensar que era a único a gostar de Delphi, e a ser colado em programação. xD
    Também tenho algo do género.

    http://nazgultuga.deviantart.com/art/FilesTube-AP...

    Só que tenho um problema, queria colocar um link, num campo de uma página Proxy, e devolver a página WEB para onde ela se direcciona, quando clico em "GO", mas… não estou a apanhar nada, por enquanto.

Leave a Reply