Posts: 863
Threads: 197
Joined: Apr 2005
Is possible download a file of rapidshare without open a explorer (open the first link, wait time, download second link)?
ex. http://rapidshare.com/files/19870643/El ... te_CRC.rar
Posts: 12,141
Threads: 143
Joined: Dec 2002
Macro
;parameters
str url="http://rapidshare.com/files/19870643/Electrical.Engineering.Dictionary.PA.Laplante_CRC.rar"
str save_folder="$desktop$"
;-------------------
;download first page
HtmlDoc hd.InitFromWeb(url)
;get URL of second page
str s url2 sd
hd.GetForm(0 url2 sd)
;out url2
;out sd
;download second page
IntPost url2 "dl.start=Free" s
;out s ;;html of second page
;extract direct download link
str rx=
;<form name="dlf" action="(.+?)"
str url3
if(findrx(s rx 0 0 url3 1)<0) end "failed"
;out url3
;wait (because error if does not wait) and download
40
IntPost url3 "mirror=" s
;out s.len
;out s ;;file data if ok, or html error page if error
;save
str filename.getfilename(url3 1)
str save.from(save_folder "\" filename)
s.setfile(save)
Posts: 863
Threads: 197
Joined: Apr 2005
It works!
One more thing, the time of wait is variable or "try again in about x minutes". Can it be exact (extract time wait)?
Thanks.
Posts: 12,141
Threads: 143
Joined: Dec 2002
When testing, always started from 31. Does it depend on file?
Posts: 12,141
Threads: 143
Joined: Dec 2002
This is from javascript from the second page:
var c=31;
then it is decremented every 1 s.
Posts: 863
Threads: 197
Joined: Apr 2005
I think that the time depends of size of file...
and
after download a file ---> "try again in about x minutes"
Posts: 12,141
Threads: 143
Joined: Dec 2002
Like you extract url3, you also can extract the time. In the page it is
var c=time;
Don't know how about "try again..."
Posts: 863
Threads: 197
Joined: Apr 2005
If you download a big file then the next file to download "after download a file ---> "try again in about x minutes"
ex: http://rapidshare.com/files/36095453/Ya ... art_03.rar
Posts: 863
Threads: 197
Joined: Apr 2005
Is possible add progress dialog?
Posts: 12,141
Threads: 143
Joined: Dec 2002
Member function Http.PostFormData2
;/
function# $action ARRAY(POSTFIELD)&a [str&responsepage] [$headers] [fa] [fparam] [inetflags] [str&responseheaders] [flags] ;;flags: 1 show responsepage download progress
;Posts web form data.
;Returns 1 on success, 0 on failure. Error if a field name is empty or a file cannot be opened.
;At first call Connect to connect to web server.
;This function supersedes Post and IntPost. It is more powerful.
;action - script's path relative to server. See "action" field in form's HTML. Example "forum\login.php".
;a - array containing name-value pairs. POSTFIELD members:
;;;name - field name. Same as "name" field in form's HTML.
;;;value - field value. Same as "value" field in form's HTML. If it is file field, must specify file.
;;;isfile - must be 0 for simple input fields, 1 for file fields.
;responsepage - receives response page (HTML).
;headers - additional headers.
;fa - address of callback function that will be called repeatedly while sending data. Can be used to show progress.
;;;function# action nbAll nbWritten $_file nbAllF nbWrittenF fparam
;;;Arguments:
;;;;;action - 0 starting to send data, 1 sending file, 2 all data sent, 3 starting to receive response, 4 finished.
;;;;;nbAll - total size of data being uploaded; nbWritten - the number of bytes uploaded so far;
;;;;;_file - current file; nbAllF - file size; nbWrittenF - uploaded part of file.
;;;Return value: 0 continue, 1 cancel.
;;;Example: search in forum.
;fparam - some value to pass to the callback function.
;inetflags (QM 2.2.1) - a combination of INTERNET_FLAG_x flags. Documented in the MSDN library on the internet. For example, use INTERNET_FLAG_NO_AUTO_REDIRECT to disable redirection. Flag INTERNET_FLAG_RELOAD is always added.
;responseheaders (QM 2.2.1) - receives raw response headers.
;EXAMPLE
;ARRAY(POSTFIELD) a.create(2)
;a[0].name="testtxt"; a[0].value="some text"; a[0].isfile=0
;a[1].name="testfile"; a[1].value="$desktop$\test.gif"; a[1].isfile=1
;Http h.Connect("www.xxx.com"); str r
;if(!h.PostFormData("form.php" a r)) end "failed"
;out r
type __POSTFILE index __HFile'hfile size str'sf str'sh
type __POSTPROGRESS fa fparam nbtotal wrtotal
int i size size2 bufsize(2*1024) wrfile
str s s1 s2 sb bound sh buf
ARRAY(__POSTFILE) af
POSTFIELD& p; __POSTFILE& f; __POSTPROGRESS pp
for(i 0 a.len)
,if(!a[i].name.len) end "field name is empty"
,if(a[i].isfile) af[].index=i
if(!af.len and !fa and !(flags&1))
,;urlencode, call Post, return
,for i 0 a.len
,,s1=a[i].name; s2=a[i].value
,,s.formata("%s%s=%s" iif(i "&" "") s1.escape(9) s2.escape(9))
,ret Post(action s responsepage headers inetflags responseheaders)
;set headers
INTERNET_BUFFERS b.dwStructSize=sizeof(b)
bound="[]--7d23542a1a12c2"
b.lpcszHeader="Content-Type: multipart/form-data; boundary=7d23542a1a12c2"
if(len(headers)) s=headers; s.trim("[]"); b.lpcszHeader=sh.from(s "[]" b.lpcszHeader)
b.dwHeadersLength=len(b.lpcszHeader)
;format non-file fields and store into b
for i 0 a.len
,&p=a[i]
,if(p.isfile) continue
,sb.formata("%s[]Content-Disposition: form-data; name=''%s''[][]%s" bound+iif(i 0 2) p.name p.value)
b.lpvBuffer=sb
b.dwBufferLength=sb.len
b.dwBufferTotal=sb.len+bound.len+4
;open files, format headers, calculate total data size
for i 0 af.len
,&f=af[i]; &p=a[f.index]
,f.sf.searchpath(p.value)
,if(!GetFileContentType(f.sf s2)) s2="text/plain"
,f.hfile.Create(f.sf OPEN_EXISTING GENERIC_READ FILE_SHARE_READ); err end _error
,f.size=GetFileSize(f.hfile 0)
,b.dwBufferTotal+f.size
,f.sh.format("%s[]Content-Disposition: form-data; name=''%s''; filename=''%s''[]Content-Type: %s[][]" bound+iif(i||sb.len 0 2) p.name f.sf s2)
,b.dwBufferTotal+f.sh.len
;init progress
pp.fa=fa; pp.fparam=fparam; pp.nbtotal=b.dwBufferTotal
if(fa && PostProgress2(0 pp)) ret
;open request, send non-file fields
__HInternet hi=HttpOpenRequest(m_hi "POST" action 0 0 0 INTERNET_FLAG_RELOAD|inetflags 0); if(!hi) goto e
if(!HttpSendRequestEx(hi &b 0 0 0)) goto e
pp.wrtotal=sb.len
;send files
if(af.len) buf.all(bufsize)
for i 0 af.len
,&f=af[i]
,if(fa && PostProgress2(1 pp f.sf f.size)) ret
,if(!InternetWriteFile(hi f.sh f.sh.len &size2) or size2!=f.sh.len) goto e
,for wrfile 0 f.size 0
,,if(!ReadFile(f.hfile buf bufsize &size 0)) ret
,,if(!InternetWriteFile(hi buf size &size2) or size2!=size) goto e
,,wrfile+size2; pp.wrtotal+size2
,,if(fa && PostProgress2(1 pp f.sf f.size wrfile)) ret
,f.hfile.Close
;write last boundary, end request
bound+"--[]"
if(!InternetWriteFile(hi bound bound.len &size2) or size2!=bound.len) goto e
if(!HttpEndRequest(hi 0 0 0)) goto e
if(fa && PostProgress2(2 pp)) ret
;get response headers
if(&responseheaders and !GetResponseHeaders(hi responseheaders)) goto e
;read response
if(&responsepage)
,if(flags&1)
,,int dlg; int* pdlg._new
,,mac "Http_Thread775" "" pdlg
,,rep() 0.01; if(*pdlg) dlg=*pdlg; pdlg._delete; break
,,s1.all(300); _i=300
,,if(HttpQueryInfo(hi HTTP_QUERY_CONTENT_DISPOSITION s1 &_i 0) and findrx(s1 "\bfilename\s*=\s*.+" 0 1 s2)>=0) s2.setwintext(id(6 dlg))
,int hr
,if(fa && PostProgress2(3 pp)) hr=1
,if(!hr and !Read(hi responsepage 0 dlg)) hr=2
,if(dlg) clo dlg; err
,if(hr) ret
if(fa && PostProgress2(4 pp)) ret
ret 1
;e
Error
Member function Http.PostProgress2
function# action __POSTPROGRESS&pp [$fname] [fsize] [fwritten]
ret call(pp.fa action pp.nbtotal pp.wrtotal fname fsize fwritten pp.fparam)
Function Http_Thread775
;\
function *pdlg
int dlg=ShowDialog("Http.GetUrl" 0 0 0 1)
opt waitmsg 1
*pdlg=dlg
wait 0 WD dlg
test
out
Http h.Connect("www.quickmacros.com")
str s
ARRAY(POSTFIELD) a
if(!h.PostFormData2("test/test.php" a s "" 0 0 0 0 1)) end "failed"
str f.expandpath("$desktop$\qm.png")
s.setfile(f)
;run f
Posts: 863
Threads: 197
Joined: Apr 2005
Can you help me convert the above macro (IntPost --> PostFormData2) ?
Posts: 12,141
Threads: 143
Joined: Dec 2002
Macro
;IntPost and Http.PostFormData do the same but are used differently
;with IntPost
str s
IntPost "http://www.xxx.yyy/test/test.php" "name1=value1&name2=value2" s ;;names and values are urlencoded, like in browser address bar
;the same with Http.PostFormData
Http h.Connect("www.xxx.yyy")
ARRAY(POSTFIELD) a.create(2)
a[0].name="name1"; a[0].value="value1" ;;these are not urlencoded
a[1].name="name2"; a[1].value="value2" ;;these are not urlencoded
h.PostFormData("test/test.php" a s)
;Http.PostFormData2 is the same as Http.PostFormData, but has one more argument - flags. If flag 1 set, shows download progress.
h.PostFormData2("test/test.php" a s "" 0 0 0 0 1)
Posts: 863
Threads: 197
Joined: Apr 2005
Then
IntPost url2 "dl.start=Free" s
is =
Http h.Connect(url2)
ARRAY(POSTFIELD) a.create(2)
a[0].name="dl.start=Free"
h.PostFormData(url2 a s)
?
Posts: 12,141
Threads: 143
Joined: Dec 2002
no
need to parse url into server and what is after server
and array length is not 2
and you did not set name and value
Posts: 863
Threads: 197
Joined: Apr 2005
Now I understand it.
Thanks for all.
Posts: 863
Threads: 197
Joined: Apr 2005
Is possible add in progress dialog
Estimated time:
Elapsed time:
Avg Speed (KB/sec):
?
Posts: 12,141
Threads: 143
Joined: Dec 2002
Possible but much work. Need to add code to several System functions.
Posts: 863
Threads: 197
Joined: Apr 2005
Posts: 863
Threads: 197
Joined: Apr 2005
In QM 2.3.2.3
when I run
Macro Macro5
out
Http h.Connect("www.quickmacros.com")
str s
ARRAY(POSTFIELD) a
if(!h.PostFormData2("test.php" a s "" 0 0 0 0 1)) end "failed"
str f.expandpath("$desktop$\qm.png")
s.setfile(f)
Error in Http.PostProgress: unknown identifier.
How fix it?
Posts: 12,141
Threads: 143
Joined: Dec 2002
In this version some internally used types renamed. If some function from forum etc uses them, need to rename there too. But better to not use private system functions. It was my mistake that I used PostProgress (system private function) in PostFormData2.
Create
Member function Http.PostProgress2
function# action __POSTPROGRESS&pp [$fname] [fsize] [fwritten]
ret call(pp.fa action pp.nbtotal pp.wrtotal fname fsize fwritten pp.fparam)
and change PostFormData2
Member function Http.PostFormData2
;/
function# $action ARRAY(POSTFIELD)&a [str&responsepage] [$headers] [fa] [fparam] [inetflags] [str&responseheaders] [flags] ;;flags: 1 show responsepage download progress
;Posts web form data.
;Returns 1 on success, 0 on failure. Error if a field name is empty or a file cannot be opened.
;At first call Connect to connect to web server.
;This function supersedes Post and IntPost. It is more powerful.
;action - script's path relative to server. See "action" field in form's HTML. Example "forum\login.php".
;a - array containing name-value pairs. POSTFIELD members:
;;;name - field name. Same as "name" field in form's HTML.
;;;value - field value. Same as "value" field in form's HTML. If it is file field, must specify file.
;;;isfile - must be 0 for simple input fields, 1 for file fields.
;responsepage - receives response page (HTML).
;headers - additional headers.
;fa - address of callback function that will be called repeatedly while sending data. Can be used to show progress.
;;;function# action nbAll nbWritten $_file nbAllF nbWrittenF fparam
;;;Arguments:
;;;;;action - 0 starting to send data, 1 sending file, 2 all data sent, 3 starting to receive response, 4 finished.
;;;;;nbAll - total size of data being uploaded; nbWritten - the number of bytes uploaded so far;
;;;;;_file - current file; nbAllF - file size; nbWrittenF - uploaded part of file.
;;;Return value: 0 continue, 1 cancel.
;;;Example: search in forum.
;fparam - some value to pass to the callback function.
;inetflags (QM 2.2.1) - a combination of INTERNET_FLAG_x flags. Documented in the MSDN library on the internet. For example, use INTERNET_FLAG_NO_AUTO_REDIRECT to disable redirection. Flag INTERNET_FLAG_RELOAD is always added.
;responseheaders (QM 2.2.1) - receives raw response headers.
;EXAMPLE
;ARRAY(POSTFIELD) a.create(2)
;a[0].name="testtxt"; a[0].value="some text"; a[0].isfile=0
;a[1].name="testfile"; a[1].value="$desktop$\test.gif"; a[1].isfile=1
;Http h.Connect("www.xxx.com"); str r
;if(!h.PostFormData("form.php" a r)) end "failed"
;out r
type __POSTFILE index __HFile'hfile size str'sf str'sh
type __POSTPROGRESS fa fparam nbtotal wrtotal
int i size size2 bufsize(2*1024) wrfile
str s s1 s2 sb bound sh buf
ARRAY(__POSTFILE) af
POSTFIELD& p; __POSTFILE& f; __POSTPROGRESS pp
for(i 0 a.len)
,if(!a[i].name.len) end "field name is empty"
,if(a[i].isfile) af[].index=i
if(!af.len and !fa and !(flags&1))
,;urlencode, call Post, return
,for i 0 a.len
,,s1=a[i].name; s2=a[i].value
,,s.formata("%s%s=%s" iif(i "&" "") s1.escape(9) s2.escape(9))
,ret Post(action s responsepage headers inetflags responseheaders)
;set headers
INTERNET_BUFFERS b.dwStructSize=sizeof(b)
bound="[]--7d23542a1a12c2"
b.lpcszHeader="Content-Type: multipart/form-data; boundary=7d23542a1a12c2"
if(len(headers)) s=headers; s.trim("[]"); b.lpcszHeader=sh.from(s "[]" b.lpcszHeader)
b.dwHeadersLength=len(b.lpcszHeader)
;format non-file fields and store into b
for i 0 a.len
,&p=a[i]
,if(p.isfile) continue
,sb.formata("%s[]Content-Disposition: form-data; name=''%s''[][]%s" bound+iif(i 0 2) p.name p.value)
b.lpvBuffer=sb
b.dwBufferLength=sb.len
b.dwBufferTotal=sb.len+bound.len+4
;open files, format headers, calculate total data size
for i 0 af.len
,&f=af[i]; &p=a[f.index]
,f.sf.searchpath(p.value)
,if(!GetFileContentType(f.sf s2)) s2="text/plain"
,f.hfile.Create(f.sf OPEN_EXISTING GENERIC_READ FILE_SHARE_READ); err end _error
,f.size=GetFileSize(f.hfile 0)
,b.dwBufferTotal+f.size
,f.sh.format("%s[]Content-Disposition: form-data; name=''%s''; filename=''%s''[]Content-Type: %s[][]" bound+iif(i||sb.len 0 2) p.name f.sf s2)
,b.dwBufferTotal+f.sh.len
;init progress
pp.fa=fa; pp.fparam=fparam; pp.nbtotal=b.dwBufferTotal
if(fa && PostProgress2(0 pp)) ret
;open request, send non-file fields
__HInternet hi=HttpOpenRequest(m_hi "POST" action 0 0 0 INTERNET_FLAG_RELOAD|inetflags 0); if(!hi) goto e
if(!HttpSendRequestEx(hi &b 0 0 0)) goto e
pp.wrtotal=sb.len
;send files
if(af.len) buf.all(bufsize)
for i 0 af.len
,&f=af[i]
,if(fa && PostProgress2(1 pp f.sf f.size)) ret
,if(!InternetWriteFile(hi f.sh f.sh.len &size2) or size2!=f.sh.len) goto e
,for wrfile 0 f.size 0
,,if(!ReadFile(f.hfile buf bufsize &size 0)) ret
,,if(!InternetWriteFile(hi buf size &size2) or size2!=size) goto e
,,wrfile+size2; pp.wrtotal+size2
,,if(fa && PostProgress2(1 pp f.sf f.size wrfile)) ret
,f.hfile.Close
;write last boundary, end request
bound+"--[]"
if(!InternetWriteFile(hi bound bound.len &size2) or size2!=bound.len) goto e
if(!HttpEndRequest(hi 0 0 0)) goto e
if(fa && PostProgress2(2 pp)) ret
;get response headers
if(&responseheaders and !GetResponseHeaders(hi responseheaders)) goto e
;read response
if(&responsepage)
,if(flags&1)
,,int dlg; int* pdlg._new
,,mac "Http_Thread775" "" pdlg
,,rep() 0.01; if(*pdlg) dlg=*pdlg; pdlg._delete; break
,,s1.all(300); _i=300
,,if(HttpQueryInfo(hi HTTP_QUERY_CONTENT_DISPOSITION s1 &_i 0) and findrx(s1 "\bfilename\s*=\s*.+" 0 1 s2)>=0) s2.setwintext(id(6 dlg))
,int hr
,if(fa && PostProgress2(3 pp)) hr=1
,if(!hr and !Read(hi responsepage 0 dlg)) hr=2
,if(dlg) clo dlg; err
,if(hr) ret
if(fa && PostProgress2(4 pp)) ret
ret 1
;e
Error
Here I changed PostProgress to PostProgress2.
Posts: 863
Threads: 197
Joined: Apr 2005
Thanks.
not yet possible to do
Estimated time:
Elapsed time:
Avg Speed (KB/sec):
?
Posts: 12,141
Threads: 143
Joined: Dec 2002
I did not work with this more. Would need to change several system functions.
Posts: 863
Threads: 197
Joined: Apr 2005
Is possible with QM 2.3.2.7
Estimated time:
Elapsed time:
Avg Speed (KB/sec):
?
Posts: 12,141
Threads: 143
Joined: Dec 2002
Next version will show only current speed.
Posts: 863
Threads: 197
Joined: Apr 2005
In macro
Macro Macro5
;parameters
str url="http://rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar"
str save_folder="$desktop$"
;-------------------
;download first page
HtmlDoc hd.InitFromWeb(url)
;get URL of second page
str s url2 sd
hd.GetForm(0 url2 sd)
;out url2
;out sd
;download second page
IntPost url2 "dl.start=Free" s
;out s ;;html of second page
;extract direct download link
str rx=
;<form name="dlf" action="(.+?)"
str url3
if(findrx(s rx 0 0 url3 1)<0) end "failed"
;out url3
;wait (because error if does not wait) and download
40
IntPost url3 "mirror=" s
;out s.len
;out s ;;file data if ok, or html error page if error
;save
str filename.getfilename(url3 1)
str save.from(save_folder "\" filename)
s.setfile(save)
Error (RT) in Macro5: container not found
Do you know why?
Posts: 12,141
Threads: 143
Joined: Dec 2002
It happens when the page does not contain forms.
Posts: 863
Threads: 197
Joined: Apr 2005
...
</script>
<h1>FILE DOWNLOAD</h1>
<div class="klappbox">
<p class="downloadlink">http://rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar <font style="color:#8E908F;">| 51119 KB</font></p>
<center>
<table>
<tr valign="top">
<td width="300" style="text-align:center;">
<form action="http://rs716.rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar" method="post">
<input type="hidden" name="dl.start" value="PREMIUM" />
<img src="/img2/dl_schnell.gif" />
<br />
<input type="submit" value="Premium user" />
</form>
</td>
<td width="300" style="text-align:center;">
<form id="ff" action="http://rs716.rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar" method="post">
<input type="hidden" name="dl.start" value="Free" />
<img src="/img2/dl_langsam.gif">
<br />
<input type="submit" value="Free user" />
</form>
<script type="text/javascript">
<!--
if (window.location.hash == "#dlt")
document.getElementById("ff").action += "#dlt";
//-->
</script>
...
Posts: 12,141
Threads: 143
Joined: Dec 2002
On my computer works. Maybe depends on IE version.
After
HtmlDoc hd.InitFromWeb(url)
insert
out hd.GetHtml
Is it normal HTML, containing <form action="...?
Posts: 863
Threads: 197
Joined: Apr 2005
...
//-->
</script>
<h1>FILE DOWNLOAD</h1>
<div class="klappbox">
<p class="downloadlink">http://rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar <font style="color:#8E908F;">| 51119 KB</font></p>
<center>
<table>
<tr valign="top">
<td width="300" style="text-align:center;">
<form action="http://rs716.rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar" method="post">
<input type="hidden" name="dl.start" value="PREMIUM" />
<img src="/img2/dl_schnell.gif" />
<br />
<input type="submit" value="Premium user" />
</form>
</td>
<td width="300" style="text-align:center;">
<form id="ff" action="http://rs716.rapidshare.com/files/342182548/Cambridge_Advanced_Learners_Dictionary.part4.rar" method="post">
<input type="hidden" name="dl.start" value="Free" />
<img src="/img2/dl_langsam.gif">
<br />
<input type="submit" value="Free user" />
</form>
<script type="text/javascript">
<!--
if (window.location.hash == "#dlt")
document.getElementById("ff").action += "#dlt";
//-->
</script>
</td>
</tr>
</table>
</center>
...
Posts: 12,141
Threads: 143
Joined: Dec 2002
Again. In some other macro it happened when the initial HTML was without HTML/HEAD/BODY tags. Now I don't know why. But it worked previously? On the same computer, with the same IE version? Maybe now rapidshare added some HTML that your IE does not recognize and cannot parse.
|