fures
Joined: 31 Jan 2008 Posts: 30
|
Posted: Wed Jul 09, 2008 8:52 pm Post subject: Mass Video (+YouTube) Ripper with Real Multithread Download |
|
|
This script will:
- scan html files
- following thru any given click-depth
- for linked or embeded video/audio/pic stuff (you define file extension),
- put filtered file links into a download queue,
- and start a real multithreaded download process with 1-16 parallel downloads (auto sorted re-naming).
It also uses "link-stripping" for link-in-link type urls.
It also supports flv files from YouTube + Altavista, Alltheweb, Google ...
You can add direct search links to start ripping from e.g. YouTube + keywords
Can download some mass, so be careful with your discspace...
Give it a look & try if curious.
cheers,
fures
PS: I used some code from other coders in my script:
- HTTPQueryInfo from olfen
- Eval - evaluate arithmetic expressions from Laszlo
Thanks for them.
The ripper script:
| Code: |
#SingleInstance FORCE
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
AutoExec:
GoSub, CheckUpdate
;Search Page follow vars
PVs = Custom|Google|YouTube|Altavista|AllTheWeb|AskJolene XXX
PV1 = pn=[PageNumber]
PV2 = num=10&start=([PageNumber]-1)*10
PV3 = page=[PageNumber]
PV4 = stq=([PageNumber]-1)*20
PV5 = o=([PageNumber]-1)*10
PV6 = pn=[PageNumber]
;Direct Search keywords
DSs = YouTube|Altavista Video|Altavista Audio|AllTheWeb Video|AllTheWeb MP3|AskJolene XXX Video
DS1 = http://www.youtube.com/results?search_query=[KeyWords]&search_type=&aq=f
DS2 = http://www.altavista.com/video/results?itag=ody&q=[KeyWords]&mvf=mpeg&mvf=avi&mvf=qt&mvf=msmedia&mvf=realmedia&mvf=flash&mvf=other&mvd=all
DS3 = http://www.altavista.com/audio/results?itag=ody&q=[KeyWords]&maf=mp3&maf=wav&maf=msmedia&maf=realmedia&maf=aiff&maf=other&mad=all
DS4 = http://www.alltheweb.com/search?cat=vid&cs=iso88591&rys=0&itag=crv&q=[KeyWords]&ocjp=1
DS5 = http://www.alltheweb.com/search?cat=mp3&cs=iso88591&q=[KeyWords]&rys=0&itag=crv
DS6 := "http://search.askjolene.com/search?aid=3&sort=date&mgc=1214123489.77&cc=&adv=&qr=[KeyWords]&submit=Ask%21&media=mov&mindate=&maxdate=&sort=date&len=&nummov="
Max_Threads = 8
myDownload_Multi = 1
NumLinks=0
NumRipps=0
NumFiles=0
Gui, +lastfound
w1 := WinExist()
Gui, Color, abccdf ;1E889E ;bbdcef
Gui, Add, StatusBar,,Not yet started
;Counters
SB_SetParts(200,130,130)
SB_SetText("`t`t0 links scanned",2)
SB_SetText("`t`t0 links followed",3)
SB_SetText("`t`t0 files ripped",4)
;Masking rectangle
Gui, Add, Text, x256 y15 w350 h20 0x13, %A_Space%
;Tabs
Gui, Add, Tab2, Section -Background x15 y15 w575 h470 Choose1 vmyTab AltSubmit, Start && Setup|Ripper Tree|Download Queue
Gui, Tab, 2 ;Ripper Tree
ImageListID := IL_Create(5)
IL_Add(ImageListID, "down.ico")
IL_Add(ImageListID, "error.ico")
IL_Add(ImageListID, "info.ico")
IL_Add(ImageListID, "ok.ico")
IL_Add(ImageListID, "search.ico")
Gui, Add, TreeView, xs+5 ys+25 w565 h440 vmap gGui_TV_event ImageList%ImageListID%,
Gui, Tab, 3 ;Download Queue
Gui, Add, Edit, xs+5 ys+25 w565 h440 vDNL_Q -Wrap,
Gui, Tab, 1
;Link List
Gui, Add, Edit, xs+11 ys+25 w550 h70 vLinkList, Link list to ripp
;Direct search
Gui, Add, Text, xs+11 y+8, Add direct search on
Gui, Add, DropDownList, x+5 yp-3 vDirSearch AltSubmit, %DSs%
Gui, Add, Text, x+5 yp+3, for:
Gui, Add, Edit, x+5 yp-3 w200 vDirSearchKeyword,
Gui, Add, Button, x+5 yp h20 gDirectSearchAdd,Add to link list
;Save Dir
Gui, Add, Text, xs+11 y+10 h20 , Save dir:
Gui, Add, Edit, x+5 yp-3 w350 h20 vSaveDir, %A_Desktop%\myRipper
Gui, Add, Button, x+5 yp w50 h20 gSaveDir_Browse, Browse
Gui, Add, Button, x+5 yp w90 h20 gSaveDir_Open, Open Save-dir
;Download or List or Copy
Gui, Add, Radio, Section x26 y+15 h20 gGui_Conf vDownloadFiles Checked, Download files in
Gui, Add, Radio, xs yp+20 h20 gGui_Conf vDownloadList, Just create a download-list for a download manager
Gui, Add, Radio, xs yp+20 h20 gGui_Conf vDownloadCopy, Just copy download-links to the clipboard
Gui, Add, CheckBox, xs+20 yp+20 h20 vConfirmDownloadWindow Checked, Auto-confirm download manager popup window
Gui, Add, Edit, xs+100 ys w40 h20 Number vMax_Threads_Edit
Gui, Add, UpDown, vMax_Threads Range1-16, %Max_Threads%
Gui, Add, Text, x+4 yp+3 h20 , simultaneous download-threads
Gui, Add, Text, x+1 yp-3 h20 ,
;File Download Filters
Gui, Add, Edit, Section x26 y280 w290 h130 Disabled -VScroll,
Gui, Add, Text, xp+7 yp-7 C0000AA, %A_Space%File Download Filters%A_Space%
Gui, Add, Text, xs+10 ys+20, File extension list:
Gui, Add, Edit, xs+120 yp w160 h20 vFilterList, .wmv,.mpg,.avi,.mov,.flv
Gui, Add, Text, xs+10 yp+20, File name exclude list:
Gui, Add, Edit, xs+120 yp w160 h20 vFNexclude, trailer,teaser
Gui, Add, Text, xs+10 yp+20, File name include list:
Gui, Add, Edit, xs+120 yp w160 h20 vFNinclude,
Gui, Add, Text, xs+10 yp+20, Skip file if in history:
Gui, Add, Radio, xs+120 yp h20 gGui_Hist vHistGl, Global
Gui, Add, Radio, x+2 yp h20 gGui_Hist vHistDir, Save-Dir
Gui, Add, Radio, x+2 yp h20 gGui_Hist vHistNo Checked, No
Gui, Add, CheckBox, xs+120 yp+20 h20 vHistEx, only if file is still in its Save-Dir
;Link Follow Filters
Gui, Add, Edit, Section x326 y180 w250 h90 Disabled -VScroll,
Gui, Add, Text, xp+7 yp-7 C0000AA, %A_Space%Link Follow Filters%A_Space%
Gui, Add, Text, xs+10 ys+20, Click depth:
Gui, Add, Edit, xs+90 yp w50 h20 vClickDepth,
Gui, Add, Text, xs+10 yp+20, Url exclude list:
Gui, Add, Edit, xs+90 yp w150 h20 vLKexclude,
Gui, Add, Text, xs+10 yp+20, Url include list:
Gui, Add, Edit, xs+90 yp w150 h20 vLKinclude,
;Tricks
Gui, Add, Edit, Section x326 y280 w250 h90 Disabled -VScroll,
Gui, Add, Text, xp+7 yp-7 C0000AA, %A_Space%Tricks%A_Space%
Gui, Add, CheckBox, xs+10 ys+20 h20 gGui_Strip vdoStripping Checked, Do link stripping? (Link-in-Link)
Gui, Add, CheckBox, xs+30 yp+20 h20 vonlyStripping, Follow only stripped links?
;Follow Search
Gui, Add, Edit, Section x326 y380 w250 h90 Disabled -VScroll,
Gui, Add, Text, xp+7 yp-7 C0000AA, %A_Space%Follow Search Pages%A_Space%
Gui, Add, CheckBox, xs+10 ys+20 h20 gGui_Srch vFollowSearch, Follow
Gui, Add, Edit, x+2 yp w25 h20 vMaxFollow, 10
Gui, Add, Text, x+3 yp+3 h20 , pages:
Gui, Add, Text, x+0 yp-3 h20 ,
Gui, Add, DropDownList, x+0 yp w110 vPagNumType gGui_PNType AltSubmit Choose1, %PVs%
Gui, Add, Text, xs+10 yp+25, Page Var in link: ( e.g. pn=[PageNumber]*10 )
Gui, Add, Edit, xs+10 yp+15 w230 h20 vPageVar,
Gui, Tab ;No Tab
;Buttons Row
Gui, Add, Button, x26 y500 w100 h30 gStart, Start Ripper
Gui, Add, Button, x+10 yp w50 h30 gPauseit, Pause
Gui, Add, Button, x+10 yp w50 h30 gResumeit, Resume
Gui, Add, Button, x+10 yp w100 h30 gStop, Stop Ripper
Gui, Add, Button, x+10 yp w100 h30 gExit, Exit && Stop All
Gui, Add, Button, x+10 yp w100 h30 gCheckUpdateX, Check Program Update
Gui, Show, h568 w605, SuperRipperWin
Gui, Submit, NoHide
GuiControl, Disable, ConfirmDownloadWindow
GuiControl, Disable, PageVar
GuiControl, Disable, PagNumType
GuiControl, Disable, MaxFollow
GuiControl, Disable, Pause
GuiControl, Disable, Stop
GuiControl, Disable, Resume
GuiControl, Disable, HistEx
GuiControl, +gGetUrlIE, Internet Explorer_Server1
GuiControl, Hide, UrlIEX
GuiControl, Hide, GoIEX
GuiControl, Hide, StopIEX
GuiControl, Hide, BackIEX
ControlClick,x34 y78,ahk_id %w1%
Send, ^a
;Checking for broken downloads
isDnlProc = 0
PrevProcDnl =
Loop, Read, %A_ScriptDir%\myDownload.ini
{
pos := InStr(A_LoopReadLine,"=")
If not pos
Continue
If (pos = StrLen(A_LoopReadLine))
Continue
kell := SubStr(A_LoopReadLine,pos+1)
kell = %kell%
If not kell
Continue
isDnlProc += 1
StringSplit,tDnl,kell,|
trunID = %tDnl1%
turl = %tDnl2%
tfil = %tDnl3%
PrevProcDnl = %PrevProcDnl%¤%turl%|%tfil% ;Download Queue - PrevProc
}
If isDnlProc() ;sets PrevProcDnlText
{
Gui, 99:Add, Text, x20 y20 w300, Some downloads not finished from a previous session:
Gui, 99:Add, Text, x20 y+10 w300, %PrevProcDnlText%
SplitPath,tfil,tfile,tdir
Gui, 99:Add, Text, x20 y+20 w300, Save Dir was:`n%tdir%
Gui, 99:Add, Text, x20 y+20 w300, What do you want to do?
Gui, 99:Add, Button, x20 y+30 h25 gPrevProcDelAll, Delete All from List
Gui, 99:Add, Button, x+20 yp h25 gPrevProcDoAll, Finish All Downloads Now
Gui, 99:Add, Button, x+20 yp h25 gPrevProcCancel Default, Cancel
Gui, 99:Show
}
Return
;**************************************************************************
Exit:
GuiClose:
Gui, Submit
FileDelete,%SaveDir%\History_This_Dir.html
FileDelete,%A_ScriptDir%\History_Global.html
FileAppend,%This_Dir_Hist%,%SaveDir%\History_This_Dir.html
FileAppend,%GL_Hist%,%A_ScriptDir%\History_Global.html
Loop, %Max_Threads% ;Check for active runIDs
{
runIDx = runID%A_Index%
IniRead, runID, %A_ScriptDir%\myDownload.ini, Running, %runIDx%
IfNotEqual,runID,ERROR
{
StringSplit,tDnl,runID,|
trunID = %tDnl1%
turl = %tDnl2%
tfil = %tDnl3%
Process, Exist, %trunID%
If (ErrorLevel = trunID) ;Successfully closed
{
Loop, 5 ;try closing
{
Process, Close, %trunID%
If (ErrorLevel = trunID) ;Successfully closed
{
;IniWrite, %A_Space%, %A_ScriptDir%\myDownload.ini, Running, %runIDx%
Break
}
else
Sleep, 200
}
}
}
}
FileDelete,%A_ScriptDir%\myDownload.ini
ExitApp
Return
Start:
Gui, Submit, NoHide
If (ClickDepth="")
{
MsgBox, Click depth is not defined. Please do!
Return
}
If (not SaveDir)
{
MsgBox, Save dir is not defined. Please do!
Return
}
IfNotExist,%SaveDir%
{
MsgBox, 4, , Save dir does not exist: %SaveDir% `n`nCreate it now?
IfMsgBox No
Return
FileCreateDir,%SaveDir%
If ErrorLevel
{
MsgBox, Error creating %SaveDir%
Return
}
}
else ;exist SaveDir
{
IfExist,%SaveDir%\History_This_Dir.html
{
MsgBox, 4, , Save dir was already used for another ripper session.`n`nAre you sure you want to add downloads to this dir?
IfMsgBox No
Return
}
}
If (InStr(FilterList,"Filter list") or not FilterList)
{
MsgBox, File extension list is not defined. Please do!
Return
}
If (LinkList="Link list to ripp" or not LinkList)
{
MsgBox, Link list is not defined. Please do!
Return
}
SB_SetText("Ripping...",1)
GuiControl, Enable, Pause
GuiControl, Enable, Stop Ripper
GuiControl, Disable, Start Ripper
GuiControl, Disable, LinkList
TV_Delete()
x_url = ;this run history delete
FileRead,GL_Hist,%A_ScriptDir%\History_Global.html
FileRead,This_Dir_Hist,%SaveDir%\History_This_Dir.html
GuiControl, Choose, myTab, 2
FileDelete,%A_ScriptDir%\myDownload.ini
Dnl =
ThisRunTime = %A_Now%
SetTimer,Check_myDnlList,1000
SetTimer,CheckReadyDNL,1000
SetTimer,UpdateDownloadQueue,1000
Loop, Parse, LinkList, `n, `r
{
If not A_LoopField
Continue
link := A_Loopfield
P := TV_Add(link)
Down_and_Ripp(link,P,ClickDepth,SaveDir,FilterList)
If Stopper
Break
If FollowSearch
GoSub, GetNextSearch
}
SB_SetText("Stopped",1)
GuiControl, Choose, myTab, 1
GuiControl, Disable, Pause
GuiControl, Disable, Stop Ripper
GuiControl, Enable, Start Ripper
GuiControl, Enable, LinkList
GoSub, Gui_Conf
Stopper =
Return
Pauseit:
SB_SetText("Paused...",1)
GuiControl, Disable, Pause
GuiControl, Enable, Resume
GuiControl, Enable, LinkList
GoSub, Gui_Conf
Loop
{
Sleep, 100
If (Resumer or Stopper)
Break
}
SB_SetText("Ripping resumed...",1)
Gui, Submit, NoHide
GuiControl, Enable, Pause
GuiControl, Disable, Resume
GuiControl, Disable, LinkList
Resumer =
Return
Resumeit:
Resumer = 1
Return
Stop:
Stopper = 1
MsgBox,0,,Please wait for the current downloads to finish.`n`nOr click Exit to stop and quit immediately.,5
Return
GetNextSearch:
link2 := link
If PageVar
{
Loop ;by pagenum
{
pagenum := A_Index+1
PageNumber := pagenum
SB_SetText("Ripping... Cont.Search page " PageNumber " of " MaxFollow,1)
Addi =
Loop, parse, PageVar, &
{
StringSplit, OutVar, A_LoopField, =
If (OutVar0 < 2)
Break
Addi := Addi . "&" . OutVar1 . "=" . Eval(OutVar2)
PageNumber := PageNumber-1
Subt := OutVar1 . "=" . Eval(OutVar2) ;PageNumber-1
StringReplace,link2,link2,%Subt%,,All
StringReplace,link2,link2,&&,&,All
StringReplace,link2,link2,?&,?,All
If (SubStr(link2,0,1) = "&")
link2 := SubStr(link2,1,-1)
PageNumber := PageNumber+1
}
If Stopper
Break
link3 := link2 . Addi
link3 := urlDecode(link3)
IfNotInString,link3,:// ;www link
link3 := "http://" link3
UrlDownloadToFile,%link3%,%SaveDir%\temp_depth%ClickDepth%.html
FileRead fileContent, %SaveDir%\temp_depth%ClickDepth%.html
If fileContent contains forbidden,not match,not found
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon2",PrntTxt " ==> ERROR CONTENT: not match or 404 not found or 403 forbidden")
FileDelete,%SaveDir%\temp_depth%ClickDepth%.html
Break
}
GuiControl,, LinkList, %LinkList%`nFollow Search Pages: page %pagenum%. ;Link:%link3%
P := TV_Add(link3)
Down_and_Ripp(link3,P,ClickDepth,SaveDir,FilterList)
If (Stopper or A_Index+1 >= MaxFollow)
Break
}
GuiControl,, LinkList, %LinkList%
}
Return
DirectSearchAdd:
Gui, Submit, NoHide
StringReplace,DSKW,DirSearchKeyword,%A_Space%,+,All
DSthis := DS%DirSearch%
StringReplace,DSthis,DSthis,[KeyWords],%DSKW%,All
If (LinkList = "Link list to ripp" or !LinkList)
GuiControl,, LinkList, %DSthis%
else
GuiControl,, LinkList, %LinkList%`n%DSthis%
MsgBox, Link for this search is added to the link list.
Return
PrevProcCancel:
Gui, 99:Destroy
Return
PrevProcDelAll:
Gui, 99:Destroy
FileDelete, %A_ScriptDir%\myDownload.ini
Return
PrevProcDoAll:
Gui, 99:Destroy
IfNotExist,%tdir%
FileCreateDir,%tdir%
Dnl = %PrevProcDnl%
SetTimer,Check_myDnlList,1000
SetTimer,CheckReadyDNL,1000
SetTimer,UpdateDownloadQueue,1000
Return
Gui_PNType:
Gui, Submit, NoHide
PVthis := PV%PagNumType%
If (PagNumType = 1)
GuiControl, Enable, PageVar
else
{
GuiControl,, PageVar, %PVthis%
GuiControl, Disable, PageVar
}
Return
Gui_Strip: ;do stripping
Gui, Submit, NoHide
If doStripping
GuiControl, Enable, onlyStripping
else
GuiControl, Disable, onlyStripping
Return
Gui_Hist: ;history
Gui, Submit, NoHide
If HistNo
GuiControl, Disable, HistEx
else
GuiControl, Enable, HistEx
Return
Gui_Srch: ;follow search page
Gui, Submit, NoHide
If FollowSearch
{
If (PagNumType = 1)
GuiControl, Enable, PageVar
GuiControl, Enable, MaxFollow
GuiControl, Enable, PagNumType
}
else
{
GuiControl, Disable, PageVar
GuiControl, Disable, MaxFollow
GuiControl, Disable, PagNumType
}
Return
Gui_Conf: ;download-list-copy
Gui, Submit, NoHide
If DownloadCopy
GuiControl, Enable, ConfirmDownloadWindow
else
GuiControl, Disable, ConfirmDownloadWindow
If DownloadFiles
{
GuiControl, Enable, Max_Threads
GuiControl, Enable, Max_Threads_Edit
}
else
{
GuiControl, Disable, Max_Threads
GuiControl, Disable, Max_Threads_Edit
}
Return
Gui_TV_event:
GuiControl, +Redraw, map
Return
SaveDir_Open:
Run, %SaveDir%
Return
SaveDir_Browse:
FileSelectFolder, SaveDir, %A_Desktop%, 1, Please select or create a folder to save downloaded files
GuiControl,, SaveDir, %SaveDir%
Return
Down_and_Ripp(link,Prnt,depth,dir,filters)
{
Global Stopper,FNexclude,onlyStripping,doStripping,LKexclude,LKinclude,FNinclude,ThisRunTime,ConfirmDownloadWindow
Global StripStringList,ClickDepth,NumLinks,NumRipps,NumFiles,DupFilter,map,DownloadList,DownloadCopy,x_url,Dnl,myDownload_Multi,UseIE
Global GL_Hist,This_Dir_Hist,HistGl,HistDir,HistEx
If (depth<0)
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon3",PrntTxt " ==> NOT FOLLOW: depth is not enough.")
Return
}
If Stopper
Return
NumLinks += 1
SB_SetText("`t`t" NumLinks " links scanned",2)
SB_SetText("`t`t" NumRipps " links followed",3)
SB_SetText("`t`t" NumFiles " files ripped",4)
link := urlDecode(link)
If (ClickDepth <> depth) ;except for the top level
{
;Link exclude-include filters
If LKexclude
If link contains %LKexclude%
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon3",PrntTxt " ==> FILTER: Link contains exclude.")
Return
}
If LKinclude
If link not contains %LKinclude%
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon3",PrntTxt " ==> FILTER: Link not contain include.")
Return
}
}
NumRipps += 1
IfNotInString,link,://
link = http://%link%
;download link
Sleep, 100
ErrorLevel =
URLDownloadToFile,%link%,%dir%\temp_depth%depth%.html
If not ErrorLevel
{
;Checking 404 Not Found in content
FileGetSize,FileSize,%dir%\temp_depth%depth%.html
If (FileSize < (100*1024)) ;if small - check content
{
FileRead,SavedFileContent,%dir%\temp_depth%depth%.html
If SavedFileContent contains forbidden,not found ;if 404 not found - delete
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon2",PrntTxt " ==> ERROR CONTENT: 404 not found or 403 forbidden")
FileDelete,%dir%\temp_depth%depth%.html
Return
}
}
}
else
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon2",PrntTxt " ==> ERROR DOWNLOADING.")
Return
}
FileRead fileContent, %dir%\temp_depth%depth%.html
murl =
kell = 0
i := 0
;get Youtube flv object
IfInString,link,watch?v=
{
RegExMatch(link, "i)v=(\w+)", v)
s := RegExMatch(fileContent, "i)fullscreen?", x)
If s
{
If not v1
RegExMatch(link, "i)video_id=(\w+)", v, s)
RegExMatch(fileContent, "i)&t=(.+?)&", t, s)
RegExMatch(fileContent, "i)&l=(.+?)&", l, s)
RegExMatch(fileContent, "i)&title=(.+?)';", tit, s)
If (v1 and l1 and t1)
{
url = http://www.youtube.com/get_video?video_id=%v1%&l=%l1%&t=%t1%|%tit1%
i++
url := urlDecode(url)
murl = %murl%1%url%`n
If (filters and depth=0) ;last level
If filters contains flv,youtube,yt,flash
kell = 1
}
}
}
;get embedded objects src=
searchPos := 1
Loop
{
fp := RegExMatch(fileContent, "i)src\s?=[\s'""]?(.+?)[\s>'""]", url, searchPos)
;fp := RegExMatch(fileContent, "iJ)src\s*=\s*(?:""(?'l'[^""]+)""|'(?'l'[^']+)'|(?'l'[^\s>]*)[\s>])", url, searchPos)
url = %url1%
If (fp = 0)
Break ; Not found
searchPos := fp + StrLen(url)
IfEqual, url, #
Continue
If not url
Break
i++
url := urlDecode(url)
OutExtension := SubStr(url,InStr(url,".",false,0))
If (depth=0)
{
If OutExtension contains %filters% ;Download
{
murl = %murl%1%url%`n
kell = 1
}
}
else
{
If OutExtension contains %filters% ;Download
murl = %murl%1%url%`n
else If url contains /watch? ;YouTube object
murl = %murl%2%url%`n
else If url contains url=http,url=www ;Stripped1
murl = %murl%3%url%`n
else If url contains =http,=www.,** ;Stripped2
murl = %murl%4%url%`n
else
murl = %murl%9%url%`n
}
}
;get all urls: href=
searchPos := 1
Loop
{
;fp := RegExMatch(fileContent, "iJ)<a\s[^>]*href\s*=\s*(?:""(?'l'[^""]+)""|'(?'l'[^']+)'|(?'l'\S+))", ur, searchPos)
;fp := RegExMatch(fileContent, "iJ)<a\s[^>]*href\s*=\s*(?:""(?'l'[^""]+)""|'(?'l'[^']+)'|(?'l'[^\s>]*)[\s>])", ur, searchPos)
fp := RegExMatch(fileContent, "i)<a\s[^>]*href\s?=[\s'""]?(.+?)[\s>'""]", url, searchPos)
url = %url1%
If (fp = 0)
Break ; Not found
searchPos := fp + StrLen(url)
IfEqual, url, #
Continue
If not url
Break
i++
url := urlDecode(url)
OutExtension := SubStr(url,InStr(url,".",false,0))
If (depth=0)
{
If OutExtension contains %filters% ;Download
{
murl = %murl%1%url%`n
kell = 1
}
}
else
{
If OutExtension contains %filters% ;Download
murl = %murl%1%url%`n
else If url contains /watch? ;YouTube object
murl = %murl%2%url%`n
else If url contains url=http,url=www ;Stripped1
murl = %murl%3%url%`n
else If url contains =http,=www.,** ;Stripped2
murl = %murl%4%url%`n
else
murl = %murl%9%url%`n
}
}
; MsgBox, % murl
; Return
If (i=0)
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon3",PrntTxt " ==> NO url found in html content.")
Return
}
If (kell=0 and depth=0)
{
TV_GetText(PrntTxt,Prnt)
TV_Modify(Prnt,"Icon3",PrntTxt " ==> NO file-extension found in html content.")
Return
}
;Sort and screen for duplicates
Sort, murl, U ;Unique
i = 1
Loop, parse, murl, `n
{
ezurl := SubStr(A_LoopField,2)
IfEqual,ezurl,, Continue
i++
P%A_Index% := TV_Add(ezurl,Prnt,"Icon999")
}
;loop thru all urls - urldecoded
TV_Modify(Prnt,"Expand")
TV_Modify(Prnt,"Icon5")
Loop, %i%
{
If Stopper
Return
Pthis := P%A_Index%
TV_Modify(Pthis,"Select")
TV_Modify(Pthis,"Icon5")
;thisurl := murl%A_Index%
tuID := TV_GetText(thisurl,Pthis)
if not thisurl
{ TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR: no url")
Continue
}
IfInString,thisurl,javascript:
{ TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: javascript:")
Continue
}
IfInString,thisurl,mailto:
{ TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: mailto:")
Continue
}
IfNotInString,thisurl,:// ;short link
{
If (InStr(link,"/",false,0) = (InStr(link,"://")+2)) ;the last / = http://
link = %link%/
If (SubStr(thisurl,1,3)="../")
{
;link = http://www.dom.com/files/images/joop.html?mi=34&ti=93
eleje := SubStr(link,1,InStr(link,"/",false,0)) ;http://www.dom.com/files/images/
eleje := SubStr(eleje,1,-1) ;http://www.dom.com/files/images
eleje := SubStr(link,1,InStr(link,"/",false,0)) ;http://www.dom.com/files/
StringReplace,thisurl,thisurl,../,/,All
thisurl := eleje . "/" . thisurl ;only the domain
}
else If (SubStr(thisurl,1,1)="/")
thisurl := SubStr(link,1,InStr(link,"/",false,10)) . "/" . thisurl ;only the domain
else
thisurl := SubStr(link,1,InStr(link,"/",false,0)) . "/" . thisurl ;also the dirs
}
StringReplace,thisurl,thisurl,//,/,All
StringReplace,thisurl,thisurl,//,/,All
StringReplace,thisurl,thisurl,//,/,All
StringReplace,thisurl,thisurl,:/,://,All
;do Stripping
LinkStripped =
If doStripping
{
StringReplace,thisurl,thisurl,&,&,All
;If (InStr(thisurl,"://",false,10))
If thisurl contains =http
{
thisurl := SubStr(thisurl,InStr(thisurl,"=http")+1)
vege := InStr(thisurl,"&")
if vege
thisurl := SubStr(thisurl,1,InStr(thisurl,"&")-1)
LinkStripped = 1
}
else If thisurl contains =www.
{
thisurl := SubStr(thisurl,InStr(thisurl,"=www.")+1)
vege := InStr(thisurl,"&")
if vege
thisurl := SubStr(thisurl,1,InStr(thisurl,"&")-1)
LinkStripped = 1
}
;http://av.rds.yahoo.com/_ylt=A0geunlv1jZIgmcAkohbDqMX;_ylu=X3oDMTA2bTQ0OXZjBHNlYwNzcg--/SIG=12qmgbg9f/EXP=1211639791/**http%3a//www.jays-links.com/info_files/video.wmv
else If thisurl contains ** ;Altavista
{
thisurl := SubStr(thisurl,InStr(thisurl,"**")+2)
vege := InStr(thisurl,"&")
if vege
thisurl := SubStr(thisurl,1,InStr(thisurl,"&")-1)
LinkStripped = 1
}
IfNotInString,thisurl,:// ;www... stripped link
thisurl := "http://" . thisurl
}
;Setting filename
IfInString,thisurl,youtube.com/get
{
;http://www.youtube.com/get_video?video_id=%v1%&l=%l1%&t=%t1%|%tit1%
StringSplit,out,thisurl,|
thisurl := out1
filename := SubStr(out2,1,35) ".flv"
}
else
filename := SubStr(thisurl,InStr(thisurl,"/",false,0)+1)
TV_Modify(Pthis,"Icon5",thisurl)
;Stripping file-extension from ?k=...&l=...
IfInString,filename,?
StringLeft,filename,filename,InStr(filename,"?")-1
IfInString,filename,&
StringLeft,filename,filename,InStr(filename,"&")-1
OutExtension := SubStr(filename,InStr(filename,".",false,0))
If OutExtension contains %filters%
isfile = 1
else
isfile =
;history
skipit =
;this run
pos := InStr(x_url,thisurl)
If pos
{
If isfile
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: Same FILE as before")
skipit = 1
}
else
{
vpos := InStr(x_url,"¤",false,pos)
hist2 =
Loop
{
x := SubStr(x_url,vpos+A_Index,1)
If (!x or x = "|")
Break
hist2 = %dpx%%x%
}
If (hist2 >= depth)
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: Same URL as before (hist.depth=" hist2 " >= act.depth=" depth ")")
skipit = 1
}
}
}
;This Dir history
If HistDir
{
pos := InStr(This_Dir_Hist,"from:" thisurl)
If pos
{
If HistEx
{
topos := InStr(This_Dir_Hist,"to:",false,pos)+3
tovpos := InStr(This_Dir_Hist,"<br>",false,topos)
filehist := SubStr(This_Dir_Hist,topos,tovpos-topos)
SplitPath, filehist, OutFileName
IfExist,%dir%\%OutFileName%
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER History This-Dir: This file already exist in this dir")
skipit = 1
}
IfExist,%filehist%
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER History This-Dir: This file already exist at: " filehist)
skipit = 1
}
}
else
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER History This-Dir.")
skipit = 1
}
}
}
;Global history
If HistGl
{
pos := InStr(GL_Hist,"from:" thisurl)
If pos
{
If HistEx
{
topos := InStr(GL_Hist,"to:",false,pos)+3
tovpos := InStr(GL_Hist,"<br>",false,topos)
filehist := SubStr(GL_Hist,topos,tovpos-topos)
SplitPath, filehist, OutFileName
IfExist,%dir%\%OutFileName%
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER History Global: This file already exist in this dir")
skipit = 1
}
IfExist,%filehist%
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER History Global: This file already exist at: " filehist)
skipit = 1
}
}
else
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER History Global.")
skipit = 1
}
}
}
If skipit
Continue
Save = 1
If OutExtension not contains %filters% ;if url-filename not contains extension filters
{
;TV_GetText(PthisTxt,Pthis)
;TV_Modify(Pthis,"",PthisTxt " ==> FILTER: Not in file-extension list.")
Save =
}
If Save
If FNinclude
If filename not contains %FNinclude% ;if url-filename not contains iclude filters
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: Filename not contain include.")
Save =
}
If Save
If FNexclude
If filename contains %FNexclude% ;if url-filename contains exclude filters
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: Filename contains exclude.")
Save =
}
Sleep, 100
If Save
{
TV_Modify(Pthis,"Icon1")
FileSaveName = %dir%\DNL_%A_Now%_%filename%
FileSaveName_final = %dir%\%A_Now%_%filename%
;FileAppend,<a href="%thisurl%">%filename%</a> - from %thisurl%<br>`n,%dir%\History_%ThisRunTime%.html
;FileAppend,<a href="%thisurl%">%filename%</a> - from %thisurl%<br>`n,%A_ScriptDir%\History_Global.html
This_Dir_Hist = %This_Dir_Hist%<a href="%thisurl%">%filename%</a> - from:%thisurl% to:%FileSaveName_final%<br>`n
GL_Hist = %GL_Hist%<a href="%thisurl%">%filename%</a> - from:%thisurl% to:%FileSaveName_final%<br>`n
If myDownload_Multi ;my multi thread download method
{
ErrorLevel =
Dnl = %Dnl%¤%thisurl%|%FileSaveName_final% ;Download Queue
If not ErrorLevel
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon4",PthisTxt " ==> File added to myDownload.")
NumFiles += 1
x_url = %x_url%|%thisurl%¤%depth% ;history
}
else
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR while adding to myDownload.")
}
}
else If DownloadList ;just create a list for a download manager
{
ErrorLevel =
FileAppend,%thisurl%`n,%dir%\%ThisRunTime%_DnlList.txt
If not ErrorLevel
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon4",PthisTxt " ==> File added to download-list.")
NumFiles += 1
x_url = %x_url%|%thisurl%¤%depth% ;history
}
else
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR while adding to download-list.")
}
}
else If DownloadCopy ;just copy to clipboard
{
ErrorLevel =
Clipboard := thisurl
Sleep, 250
If not ErrorLevel
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon4",PthisTxt " ==> File copied to clipboard.")
NumFiles += 1
x_url = %x_url%|%thisurl%¤%depth% ;history
}
else
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR while copying to clipboard.")
}
IfWinActive,ahk_class #32770 ;download adding window
{
If ConfirmDownloadWindow
{
Control,Uncheck,,Button7,A ;auto-generate filename
ControlSetText,Edit5,%A_Now%_%filename%,A ;save as
Sleep, 30
Send, {enter}
Sleep, 250
IfWinActive,ahk_class #32770 ;download confirm window
{
Send, {enter}
Sleep, 250
}
}
else
{
WinWaitNotActive,ahk_class #32770 ;download adding window
}
}
}
else ;oldfashioned one-thread download
{
Save2 = 1
ErrorLevel =
URLDownloadToFile,%thisurl%,%FileSaveName% ;save to dir
;myURLDownloadToFile(thisurl,FileSaveName)
If not ErrorLevel
{
;Checking 404 Not Found in content
FileGetSize,FileSize,%FileSaveName%
If (FileSize < (10*1024)) ;if small - check content
{
FileRead,SavedFileContent,%FileSaveName%
If SavedFileContent contains forbidden,not found ;if 404 not found - delete
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR CONTENT: 404 not found or 403 forbidden.")
FileDelete,%FileSaveName%
Save2 =
}
}
If DupFilter
{
Loop, %dir%\*.*
{
thisFN := SubStr(A_LoopFileName,16)
IfEqual,thisFN,%filename%
IfEqual,A_LoopFileSize,%FileSize%
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> DUPL FILTER: File not saved.")
FileDelete,%FileSaveName%
Save2 =
Break
}
}
}
If Save2 ;OK - leave it saved
{
Loop, 33
{
FileCopy,%FileSaveName%,%FileSaveName_final%,1
If not ErrorLevel
Break
Sleep, 250
}
If not ErrorLevel
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon4",PthisTxt " ==> File saved OK.")
NumFiles += 1
x_url = %x_url%|%thisurl%¤%depth% ;history
}
else
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR COPYING to save location.")
}
FileDelete,%FileSaveName%
}
SavedFileContent =
}
else ;ErrorLevel URLDownloadToFile
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon2",PthisTxt " ==> ERROR DOWNLOADING.")
FileDelete,%FileSaveName%
}
}
}
else ;not Save
{
If onlyStripping
If not LinkStripped ;this is not a stripped link
{
TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> NOT FOLLOWING: not a stripped link.")
Continue
}
If filename not contains .mov,.mp3,.mpe,.wav,.mp4,.avi,.mpg,.wmv,.wma,.jpg,.gif,.png ;if url is not a file
{
x_url = %x_url%|%thisurl%¤%depth% ;history
Down_and_Ripp(thisurl,Pthis,depth-1,dir,filters)
}
else
{ TV_GetText(PthisTxt,Pthis)
TV_Modify(Pthis,"Icon3",PthisTxt " ==> FILTER: Not in file-extension list.")
}
}
}
FileDelete,%dir%\temp_depth%depth%.html
TV_Modify(Prnt,"-Expand")
TV_Modify(Prnt,"Icon4")
Return
}
urlDecode(str) {
Loop
If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
Else Break
Return, str
}
CheckUpdateX:
fromMenu = 1
GoSub, CheckUpdate
fromMenu =
Return
CheckUpdate:
ext = ahk
If A_IsCompiled
ext = exe
URLDownloadToFile, http://wfures.eqnet.hu/SuperRipper/SuperRipper.%ext%, %A_ScriptDir%\upd_%A_ScriptName%
IfNotExist, %A_ScriptDir%\upd_%A_ScriptName%
Return
CurrentVersion := myGetVersion(A_ScriptFullPath)
DLVersion := myGetVersion(A_ScriptDir . "\upd_" . A_ScriptName)
;MsgBox,4,New version,???`n`nCurrent version: %CurrentVersion%`nNew version: %DLVersion%`n`nDo you want to update now?
IfGreaterOrEqual, CurrentVersion, %DLVersion%
{
FileDelete, %A_ScriptDir%\upd_%A_ScriptName%
If fromMenu
MsgBox,0,No update,This is the most up-to-date version: %CurrentVersion%,10
Return
}
If not SilentProgramUpdate
{
MsgBox,4,New version,An updated version is available.`n`nCurrent version: %CurrentVersion%`nNew version: %DLVersion%`n`nDo you want to update now?
IfMsgBox, Yes
sleep, 50
else
{
FileDelete, %A_ScriptDir%\upd_%A_ScriptName%
MsgBox,0,No update now,No update now.,10
Return
}
; MsgBox,4,New version,To change to the new version the program is restarting now.`n`nOK?
; IfMsgBox, Yes
; sleep, 50
; else
; {
; MsgBox,0,No update now,The program will refresh at the next launch,10
; Return
; }
}
GoSub, DoUpdateReload
Return
myGetVersion(pth)
{
IfInString, pth, .ahk
{
Loop, Read, %pth%
{
StringSplit,ver,A_LoopReadLine,=
thisVersion := ver2
Break
}
}
else IfInString, pth, .exe
FileGetVersion,thisVersion,%pth%
else
Return
Return, thisVersion
}
DoUpdateReload:
;the Dir command should take a few seconds - used as a pause
thisBATfile = %A_ScriptDir%\upd_this.bat
FileDelete, %thisBATfile%
FileAppend,
(
dir c:\windows\system32 /b /s
del "%A_ScriptDir%\%A_ScriptName%"
copy "%A_ScriptDir%\upd_%A_ScriptName%" "%A_ScriptDir%\%A_ScriptName%"
del "%A_ScriptDir%\upd_%A_ScriptName%"
start "title" "%A_ScriptDir%\%A_ScriptName%"
dir c:\windows\system32 /b /s
del "%thisBATfile%"
), %thisBATfile%
sleep, 3000
Run, %COMSPEC% /c "%thisBATfile%",,hide
ExitApp
Return
CheckReadyDNL:
Critical
Loop, %Max_Threads% ;Check for finished runID
{
runIDx = runID%A_Index%
IniRead, runID, %A_ScriptDir%\myDownload.ini, Running, %runIDx%, %A_Space%
If runID
{
StringSplit,tDnl,runID,|
trunID = %tDnl1%
turl = %tDnl2%
tfil = %tDnl3%
Process, Exist, %trunID%
If not ErrorLevel ;This is ready
{
IniWrite, %A_Space%, %A_ScriptDir%\myDownload.ini, Running, %runIDx%
;Post checking
FileGetSize,size,%tfil% ;Check size
if (size < (10*1024)) ;redirect html
{
FileRead,SavedFileContent,%tfil%
;if content = html code
If SavedFileContent contains <html>,<body>,<br> ;faulty content
IfNotInString,FilterList,.htm
{
;delete file
FileDelete,%tfil%
;Remove from run-history
StringReplace,x_url,x_url,|%turl%,,All
;Remove from History_Global
StringReplace,GL_Hist,GL_Hist,from %turl%,*DEL*,All
Loop
{
pos1 := InStr(GL_Hist,"*DEL*")
if not pos1
Break
chunk1 := SubStr(GL_Hist,1,pos1)
pos2 := InStr(chunk1,"<a",false,0) ;1st <a backwords
pos3 := Instr(GL_Hist,"<br>",false,pos1) ;1st <br> forewords from pos1
If pos3
chunk3 := SubStr(GL_Hist,pos2,pos3+3-pos2)
StringReplace,GL_Hist,GL_Hist,%chunk3%,,All
}
;Remove from History_This_Dir
StringReplace,This_Dir_Hist,This_Dir_Hist,from %turl%,*DEL*,All
Loop
{
pos1 := InStr(This_Dir_Hist,"*DEL*")
if not pos1
Break
chunk1 := SubStr(This_Dir_Hist,1,pos1)
pos2 := InStr(chunk1,"<a",false,0) ;1st <a backwords
pos3 := Instr(This_Dir_Hist,"<br>",false,pos1) ;1st <br> forewords from pos1
If pos3
chunk3 := SubStr(This_Dir_Hist,pos2,pos3+3-pos2)
StringReplace,This_Dir_Hist,This_Dir_Hist,%chunk3%,,All
}
LinkList = %LinkList%`n%turl%
}
}
}
}
}
Return
Check_myDnlList:
Critical
; If (!Dnl and ! isDnlProc()) ;empty download-queue and no running download-thread
; {
; SetTimer, Check_myDnlList, OFF
; SetTimer, CheckReadyDNL, OFF
; SetTimer, UpdateDownloadQueue, OFF
; }
Loop, parse, Dnl, ¤
{
IfEqual,A_LoopField,
Continue
StringSplit,tDnl,A_LoopField,|
turl = %tDnl1%
tfil = %tDnl2%
delthis =
Loop, %Max_Threads% ;Check for empty runID
{
runIDx = runID%A_Index%
IniRead, runID, %A_ScriptDir%\myDownload.ini, Running, %runIDx%, %A_Space%
If !runID
{
;scriptname "url" "save file" "pos-index" "dupl-filter"
IfExist,C:\Program Files\AutoHotkey\AutoHotkey.exe
Run, "C:\Program Files\AutoHotkey\AutoHotkey.exe" "myDownload.ahk" "%turl%" "%tfil%" %A_Index%,,,runID
else IfExist,myDownload.exe
Run, "myDownload.exe" "%turl%" "%tfil%" %A_Index%,,,runID
else
{
MsgBox, The myDownload.exe component is missing, and AutoHotkey is not found.
ExitApp
}
IniWrite, %runID%|%turl%|%tfil%, %A_ScriptDir%\myDownload.ini, Running, %runIDx%
delthis = 1
Break
}
}
If delthis
{
StringReplace, Dnl, Dnl, %A_LoopField%,, A
StringReplace, Dnl, Dnl, ¤¤,¤, A
}
}
Return
isDnlProc()
{
Global PrevProcDnlText
isDnlProc = 0
PrevProcDnl =
PrevProcDnlText =
;Gui, 99:Add, Text, x20 y20 w300, Some downloads not finished from a previous session:
Loop, Read, %A_ScriptDir%\myDownload.ini
{
pos := InStr(A_LoopReadLine,"=")
If not pos
Continue
If (pos = StrLen(A_LoopReadLine))
Continue
kell := SubStr(A_LoopReadLine,pos+1)
kell = %kell%
If not kell
Continue
isDnlProc += 1
StringSplit,tDnl,kell,|
trunID = %tDnl1%
turl = %tDnl2%
tfil = %tDnl3%
PrevProcDnl = %PrevProcDnl%¤%turl%|%tfil% ;Download Queue - PrevProc
PrevProcDnlText = %PrevProcDnlText%`n%turl%
;Gui, 99:Add, Text, x20 y+10 w300, %turl%
}
Return, isDnlProc
}
UpdateDownloadQueue:
;update Download Queue control
StringReplace, DNL_Q, Dnl,¤,`n, A
GuiControl,,DNL_Q,Waiting for download:`n%DNL_Q%
Return
; AHK 1.0.46+
; evaluate arithmetic expressions containing
; unary +,- (-2*3; +3)
; +,-,*,/,\(or % = mod); **(or @ = power)
; (..); var (pi, e); abs(),sqrt(),floor()
Eval(x) { ; expression preprocessing
Static pi = 3.141592653589793, e = 2.718281828459045
StringReplace x, x,[,, All ;Old [Var] compatibility
StringReplace x, x,],, All ;Old [Var] compatibility
StringReplace x, x,`%, \, All ; % -> \ for MOD
x := RegExReplace(x,"\s*") ; remove whitespace
x := RegExReplace(x,"([a-zA-Z]\w*)([^\w\(]|$)","%$1%$2") ; var -> %var%
Transform x, Deref, %x% ; dereference all %var%
StringReplace x, x, -, #, All ; # = subtraction
StringReplace x, x, (#, (0#, All ; (-x -> (0-x
If (Asc(x) = Asc("#"))
x = 0%x% ; leading -x -> 0-x
StringReplace x, x, (+, (, All ; (+x -> (x
If (Asc(x) = Asc("+"))
StringTrimLeft x, x, 1 ; leading +x -> x
StringReplace x, x, **, @, All ; ** -> @ for easier process
Loop { ; find innermost (..)
If !RegExMatch(x, "(.*)\(([^\(\)]*)\)(.*)", y)
Break
x := y1 . Eval@(y2) . y3 ; replace "(x)" with value of x
}
Return Eval@(x) ; no more (..)
}
Eval@(x) {
RegExMatch(x, "(.*)(\+|\#)(.*)", y) ; execute rightmost +- operator
IfEqual y2,+, Return Eval@(y1) + Eval@(y3)
IfEqual y2,#, Return Eval@(y1) - Eval@(y3)
; execute rightmost */% operator
RegExMatch(x, "(.*)(\*|\/|\\)(.*)", y)
IfEqual y2,*, Return Eval@(y1) * Eval@(y3)
IfEqual y2,/, Return Eval@(y1) / Eval@(y3)
IfEqual y2,\, Return Mod(Eval@(y1),Eval@(y3))
; execute rightmost power
StringGetPos i, x, @, R
IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) ** Eval@(SubStr(x,2+i))
; execute rightmost function
If !RegExMatch(x,".*(abs|floor|sqrt)(.*)", y)
Return x ; no more function
IfEqual y1,abs, Return abs( Eval@(y2))
IfEqual y1,floor,Return floor(Eval@(y2))
IfEqual y1,sqrt, Return sqrt( Eval@(y2))
}
|
The download thread script (copy to the same dir)
| Code: |
#SingleInstance OFF
#NoTrayIcon
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
if 0 < 2 ; The left side of a non-expression if-statement is always the name of a variable.
{
;MsgBox This script requires at least 2 incoming parameters but it only received %0%.
; ExitApp
}
StringReplace, 1, 1, ",, All
StringReplace, 2, 2, ",, All
StringReplace, 3, 3, ",, All
;StringReplace, 4, 4, ",, All
url = %1%
save = %2%
pospar = %3%
if not url
{
url = http://www.bbdo.hu/mytest/magyar/works/007_work1.wmv
sleep, 5000
}
if not save
save = temp.wmv
if not pospar
pospar = 1
SplitPath,save,file
rfile := SubStr(file,InStr(file,"_")+1)
;StringSplit,rfile,file,_
urlfile := file
If rfile
urlfile := rfile
;message = 0x11100
;OnMessage(message, "SetCounter")
Loop, 20
{
pos%A_Index% := ((A_Index-1) * 31)+100
}
posy := pos%pospar%
;Progress, x10 y%posy% M2 T FM8 FS8 h80 w300, , ., mydnl
;wn := WinExist("mydnl")
;WinMinimize,ahk_id %wn%
Gui, +lastfound -caption +Border +ToolWindow ;+owner
wn := WinExist()
Gui, Add, Progress, Section x55 vProgressBar w100 +Smooth cBDDCEF
Gui, Font, bold
Gui, Add, Text, ys, %urlfile%
Gui, Add, Text, vProgressN BackgroundTrans x90 ys+2, connecting...
Gui, Font
Gui, Add, Text, vKB ys w150, getting info...
Gui, Add, Button, ys x5 w48 h20 gExit, Close
Gui, Show, NoActivate x10 y%posy% w300 h30, Downloading...
total := HttpQueryInfo(url, 5)
If not total
ExitApp
GuiControl, , KB, % "(" round(total/1024) " kB)"
FileDelete, %save%
res:=Download(url, save, message, 500)
ExitApp
Return
Exit:
GuiEscape:
GuiClose:
ExitApp
Download(url, save, msg = 0x1100, sleep = 1000) {
;total := HttpQueryInfo(url, 5)
Global total
SetTimer, _dlprocess, %sleep%
UrlDownloadToFile, %url%, %save%
SetTimer, _dlprocess, Off
Return, ErrorLevel
_dlprocess:
FileGetSize, current, %save%, K
;Process, Exist
;PostMessage, msg, current * 1024, total, , ahk_pid %ErrorLevel%
SetCounter(current * 1024, total)
Exit
}
; SetCounter(wParam, lParam) {
; global url,save
; SplitPath,url,urlfile
; progress := Round(wParam / lParam * 100)
; wParam := wParam // 1024
; lParam := lParam // 1024
; Progress, %progress%, %url%, %urlfile%: %wParam% kB of %lParam% kB, %progress%`% - Downloading...
; }
SetCounter(wParam, lParam) {
progress := Round(wParam / lParam * 100)
GuiControl, , ProgressBar, %progress%
GuiControl, , ProgressN, %progress%`%
;wParam := wParam // 1024
;lParam := lParam // 1024
;GuiControl, , KB, (%wParam% kB of %lParam% kB)
;Gui, Show, , %progress%`% - Downloading...
}
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
QueryInfoFlag
HTTP_QUERY_RAW_HEADERS = 21
Receives all the headers returned by the server.
Each header is terminated by "\0". An additional "\0" terminates the list of headers.
HTTP_QUERY_CONTENT_LENGTH = 5
Retrieves the size of the resource, in bytes.
HTTP_QUERY_CONTENT_TYPE = 1
Receives the content type of the resource (such as text/html).
Find more at: http://msdn.microsoft.com/library/en-us/wininet/wininet/query_info_flags.asp
Proxy Settings:
INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration
INTERNET_OPEN_TYPE_DIRECT 1 // direct to net
INTERNET_OPEN_TYPE_PROXY 3 // via named proxy
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS
*/ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
hModule := DllCall("LoadLibrary", "str", "wininet.dll")
If (Proxy != "")
AccessType=3
Else
AccessType=1
io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags
If (ErrorLevel != 0 or io_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}
iou_hInternet := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or iou_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}
VarSetCapacity(buffer, 1024, 0)
VarSetCapacity(buffer_len, 4, 0)
Loop, 5
{
hqi := DllCall("wininet\HttpQueryInfoA"
, "uint", iou_hInternet
, "uint", QueryInfoFlag ;dwInfoLevel
, "uint", &buffer
, "uint", &buffer_len
, "uint", 0) ;lpdwIndex
If (hqi = 1) {
hqi=success
break
}
}
IfNotEqual, hqi, success, SetEnv, res, timeout
If (hqi = "success") {
p := &buffer
Loop
{
l := DllCall("lstrlen", "UInt", p)
VarSetCapacity(tmp_var, l+1, 0)
DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
p += l + 1
res := res . "`n" . tmp_var
If (*p = 0)
Break
}
StringTrimLeft, res, res, 1
}
DllCall("wininet\InternetCloseHandle", "uint", iou_hInternet)
DllCall("wininet\InternetCloseHandle", "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)
return, res
}
|
and finally some icons (copy into the same dir)
in this folder |
|