<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pedro Proença &#187; Delphi</title>
	<atom:link href="http://pedroproenca.info/category/tutorials/delphi-tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://pedroproenca.info</link>
	<description>delphi, php, mysql, css, html</description>
	<lastBuildDate>Tue, 15 Dec 2009 21:01:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Make a Rapid-share Up-loader</title>
		<link>http://pedroproenca.info/make-a-rapid-share-up-loader</link>
		<comments>http://pedroproenca.info/make-a-rapid-share-up-loader#comments</comments>
		<pubDate>Mon, 14 Dec 2009 17:20:57 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[rapid-share]]></category>
		<category><![CDATA[rapidshare]]></category>
		<category><![CDATA[RS]]></category>
		<category><![CDATA[uploader]]></category>
		<category><![CDATA[vcl]]></category>

		<guid isPermaLink="false">http://pedroproenca.info/?p=68</guid>
		<description><![CDATA[Since I don&#8217;t make any new posts for quite a while now, I decided to reward you all with a new tutorial, &#8220;How to make a Rapid-Share  up-loader&#8221;, with this tutorial you will learn how to code a application capable of uploading, automatically, files to, the well known file-hosts, &#8220;rapid-share&#8221; and &#8220;easy-share&#8221; and it will [...]]]></description>
			<content:encoded><![CDATA[<p>Since I don&#8217;t make any new posts for quite a while now, I decided to reward you all with a new tutorial, &#8220;How to make a Rapid-Share  up-loader&#8221;, with this tutorial you will learn how to code a application capable of uploading, automatically, files to, the well known file-hosts, &#8220;rapid-share&#8221; and &#8220;easy-share&#8221; and it will return the &#8220;download&#8221; and &#8220;delectation&#8221; links.<br />
<strong>(The code is made in Delphi)</strong><br />
<span id="more-68"></span></p>
<h1>1. Get the necessary HTML variables</h1>
<p>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:</p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-uploader-identify-form.jpg"><img class="size-full wp-image-72 alignnone" style="border: 0pt none;" title="rapidshare uploader identify form" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-uploader-identify-form.jpg" alt="Shows the rapidshare source code" width="500" height="400" /></a></p>
<p>Let&#8217;s take a look at the form code:</p>
<pre class="brush:html">&lt;form action="http://rs241l3.rapidshare.com/cgi-bin/upload.cgi?rsuploadid=149017462993654077" enctype="multipart/form-data" method="post"&gt;
&lt;div id="progbar" style="display:none;"&gt;
&lt;div style="font-size:8pt;"&gt;You are uploading:&lt;/div&gt;
.&lt;/div&gt;
&lt;div id="dateiwahl"&gt;
&lt;table style="font-size:8pt;color:#002760;" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align="left"&gt;
&lt;div id="files"&gt;

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

&lt;input id="dateiname" name="filecontent" size="65" type="file" /&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div id="infotextfeld" style="display: block; width: 400px; text-align: left;"&gt;Share your files for FREE via RapidShare.com!
&lt;a href="http://rapidshare.com/howto_upload.html" target="_blank"&gt;Upload assistance&lt;/a&gt;
&lt;ol style="color:#002760;"&gt;
 &lt;li&gt;&lt;strong&gt;Select file and click the upload button&lt;/strong&gt;&lt;/li&gt;
 &lt;li&gt;Share download link&lt;/li&gt;
&lt;/ol&gt;
Delete your files any time you want.&lt;/div&gt;
&lt;input id="btnupload" style="display:none;" name="u" src="/img2/upload_file.jpg" type="image" /&gt;&lt;/div&gt;
&lt;/form&gt;</pre>
<p><strong>Let&#8217;s remove everything we don&#8217;t need:</strong></p>
<p>&lt;form <strong><span style="color: #ff0000;">action=&#8221;http://rs241l3.rapidshare.com/cgi-bin/upload.cgi?rsuploadid=149017462993654077&#8243;</span></strong> <span style="color: #ff0000;"><strong>enctype=&#8221;multipart/form-data&#8221;</strong></span> method=&#8221;post&#8221;&gt;<br />
&lt;input id=&#8221;dateiname&#8221; <span style="color: #ff0000;"><strong>name=&#8221;filecontent&#8221;</strong></span> size=&#8221;65&#8243; type=&#8221;file&#8221; /&gt;<br />
&lt;/form&gt;<br />
<strong>Finally we can analyze the data:</strong></p>
<p><span style="color: #ff0000;"><strong>action=&#8221;</strong></span><span style="color: #ff0000;"><strong>http://</strong></span><span style="color: #800000;"><strong>rs241l3</strong></span><span style="color: #ff0000;"><strong><span style="color: #00ff00;"> </span>.rapidshare.com/cgi-bin/upload.cgi</strong></span> -&gt; This is the URL we will use to make the post. In <span style="color: #800000;"><strong>Brown</strong></span> you can find the rapid-share server, there&#8217;s more then one, our application will use them all.</p>
<p><strong><span style="color: #ff0000;">rsuploadid=149017462993654077 </span></strong>-&gt; This isn&#8217;t really necessary, though since we want to make a pretty uploader we will use it.</p>
<p><span style="color: #ff0000;"><strong>enctype=&#8221;multipart/form-data&#8221;</strong></span> <span style="color: #ff0000;"><strong> </strong></span> -&gt; Obviously the form enctype is a <a href="http://en.wikipedia.org/wiki/MIME">&#8220;multipart/form-data&#8221;</a></p>
<p><span style="color: #ff0000;"><strong>name=&#8221;filecontent&#8221;</strong></span> -&gt;This is the variable which will &#8220;store&#8221; the file and then be sent to the server.</p>
<p>Now that we have all the information we can start coding our app</p>
<h1>2. Creating the &#8220;Project&#8221;</h1>
<p><strong>In delphi, start a new project:</strong></p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-uploader-coding-unit.jpg"><img class="alignnone size-full wp-image-86" style="border: 0pt none;" title="rapidshare start new project" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-start-new-project.jpg" alt="rapidshare start new project" width="545" height="412" /></a></p>
<p><strong>Once you&#8217;ve done this, make your form look like this:</strong></p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-uploader-form.jpg"><img class="alignnone size-full wp-image-87" style="border: 0pt none;" title="rapidshare uploader form" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-uploader-form.jpg" alt="rapidshare uploader form" width="603" height="424" /></a></p>
<p><strong>Now drop a TidHTTP component on the form:</strong></p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-tidhttp.jpg"><img class="alignnone size-full wp-image-88" style="border: 0pt none;" title="rapidshare tidhttp" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-tidhttp.jpg" alt="rapidshare tidhttp" width="569" height="413" /></a></p>
<p><strong>and also drop a OpenDialog component:</strong></p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-opendialog.jpg"><img class="alignnone size-full wp-image-95" style="border: 0pt none;" title="rapidshare opendialog" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-opendialog.jpg" alt="rapidshare opendialog" width="379" height="429" /></a></p>
<h1>3. Configuring Indy HTTP</h1>
<p><strong>Let&#8217;s configure the indy events:</strong></p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-idhttp-events.jpg"><img class="alignnone size-full wp-image-89" style="border: 0pt none;" title="rapidshare idhttp events" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-idhttp-events.jpg" alt="rapidshare idhttp events" width="323" height="338" /></a></p>
<p><strong>Make it like this:</strong></p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-events-code.jpg"><img class="alignnone size-full wp-image-90" style="border: 0pt none;" title="rapidshare events code" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-events-code.jpg" alt="rapidshare events code" width="610" height="376" /></a></p>
<p>Now that our &#8220;IdHTTP&#8221; component is configured let&#8217;s proceed.</p>
<h1>3. The code</h1>
<p><strong>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:</strong></p>
<p><em>add the following in your uses &#8220;StrUtils&#8221;</em></p>
<pre class="brush:delphi">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;</pre>
<p><strong>Now we need to get the uploading link, let&#8217;s use our function:</strong></p>
<pre class="brush:delphi">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;</pre>
<p><strong>the link is on our hands so let&#8217;s get the file dialog working, so that we can make the uploading code:</strong></p>
<pre class="brush:delphi">procedure TfmMain.btnBrowseFileClick(Sender: TObject);
begin
OpenDialog1.Filter := 'All Format Files | *.*';
if OpenDialog1.Execute then
begin
txtFile.Text := OpenDialog1.FileName;
end;
end;</pre>
<p><strong>the button done, let&#8217;s continue:</strong></p>
<p><em>add the following in your uses &#8220;IdMultipartFormData&#8221;</em></p>
<pre class="brush:delphi">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;</pre>
<p>all we need now is to get the download and delete link:</p>
<pre class="brush:delphi">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,'&lt;div&gt;','&lt;/div&gt;');
txtDeleteLink.Text := GetInnerHTML(HTMLtoCheck,'&lt;div&gt;','&lt;/div&gt;');
end;</pre>
<p>And voilà! You got yourself a rapid-share fully automatic uploader!</p>
<p><a href="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-done.jpg"><img class="alignnone size-full wp-image-96" title="rapidshare done" src="http://pedroproenca.info/wp-content/uploads/2009/12/rapidshare-done.jpg" alt="rapidshare done" width="606" height="430" /></a></p>
<p>I&#8217;ve attached the full project (exe + source + some modifications) :</p>
<p><a title="Download RS Uploader" href="http://pedroproenca.info/RS%20Uploader.rar" target="_blank">http://pedroproenca.info/RS%20Uploader.rar</a></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d68').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d68" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;submitHeadline=Make+a+Rapid-share+Up-loader&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;title=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;title=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://pedroproenca.info/make-a-rapid-share-up-loader" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;title=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;bm_description=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;T=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;title=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;title=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://pedroproenca.info/make-a-rapid-share-up-loader" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://pedroproenca.info/make-a-rapid-share-up-loader" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Make+a+Rapid-share+Up-loader+@+http://pedroproenca.info/make-a-rapid-share-up-loader" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://pedroproenca.info/make-a-rapid-share-up-loader&amp;t=Make+a+Rapid-share+Up-loader" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://pedroproenca.info/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d68').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d68').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://pedroproenca.info/make-a-rapid-share-up-loader/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
