#include ;first select a folder on hard drive with the movie $folder = FileSelectFolder("Selecteer map met film", "",4,"C:\downloads nov") $array = StringSplit($folder, '\', 1) $naam = $array[ubound($array)-1] Dim $delims[4]=[".","[","]","-"] ;add nonsense here for $dI=0 to ubound($delims)-1 $naam = StringReplace($naam, $delims[$dI], " ") Next Dim $toDelete[10]=["dvdrip","axxo","xvid","DiAMOND","eng","2cd","ac3","fxg","r5","2008"] ;add nonsense here for $tI=0 to ubound($toDelete)-1 $naam = StringReplace($naam, $toDelete[$tI], "") Next $naam=StringStripWS ($naam, 2 ) ;scripts takes a title as input and searches subtitles on nlondertitels.com $DOWNLOAD_COUNT = 10 ;maximum amount of subtitles to download ;$folder = "C:\Users\Karel\Ondertitels\" ;folder where you want to save the subtitles ;ask user for title and create folder $titel = InputBox("Ondertitel downloader", "Titel van de film?",$naam) ;DirCreate ( $folder & $titel ) ;$folder = $folder & $titel ;first search in google to find the imdb number $googleUrl = "http://www.google.be/search?hl=nl&q=imdb+" & $titel $oIE = _IECreate($googleUrl, 0, 0); $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended $imdbNr="" For $i=0 to $iNumLinks-1 $oLink = _IELinkGetCollection ($oIE,$i); if (StringInStr($oLink.href, "www.imdb.com/title/tt")) then $imdbNrArray = StringRegExp($oLink.href, 'www.imdb.com/title/tt([0-9]*)',3) ;get the number $imdbNr = $imdbNrArray[0] ExitLoop EndIf Next _IEQuit ($oIE) ConsoleWrite("imdb number = " & $imdbNr) ;search for the subtitles, using the imdb number or the movie title (if no number was found) if $imdbNr<>"" then ;search subs by using the imdb number (best results) ; if $plotinfo ;find imdb plot info TrayTip("Find imdb info..", 10, 16) $sUrl = "www.imdb.com/title/tt" & $imdbNr & "/plotsummary"; $oIE = _IECreate($sUrl, 0, 0); $sText = _IEBodyReadHTML($oIE) ;ConsoleWrite($sText) ;$sText = StringReplace($sText, "\n", " ") $paragraphs = StringRegExp($sText, '(?s)(?i)

(.*?)

',3) ;get the titles.. $parI=0 $plot="

" & $titel & "

" while $parI"; ;ConsoleWrite($paragraphs[$parI]) $parI=$parI+1 wend $sUrl = "www.imdb.com/title/tt" & $imdbNr & ""; $oIE = _IECreate($sUrl, 0, 0); $sText = _IEBodyReadHTML($oIE) $infos = StringRegExp($sText, '(?s)(?i)
(.*?)
',3) ;get the info blocks.. $infoI=0 $infoTxt="" while $infoI"; $infoI=$infoI+1 wend TrayTip("Find cover art..", 10, 16) $sUrl = "http://images.google.be/images?gbv=2&hl=nl&q=%22" & $titel & "%22+poster+movie&btnG=Afbeeldingen+zoeken" $oIE = _IECreate($sUrl, 0, 0); $sText = _IEBodyReadHTML($oIE) ;dyn.Img("","","","http://www.clooneyfiles.com/specials/syriana/syrianaposter.jpg","","","","","","","","","","","","",[]); $imgs = StringRegExp($sText, '(?s)(?i)dyn.Img\("(?:.*?)","(?:.*?)","(?:.*?)","(.*?).jpg"',3) ;find cover art if ubound($imgs)>0 then $image=$imgs[0] & ".jpg" $image = StringReplace($image, "%2520", "%20") ConsoleWrite($image) InetGet($image, $folder & "\Folder.jpg", 1) endif $file = FileOpen($folder & "\info.html", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, "" & @CRLF) FileWrite($file, "" & $plot) FileWrite($file, "" & "

Info

" & $infoTxt) FileWrite($file, "" & @CRLF) FileClose($file) ConsoleWrite($paragraphs) ; endif TrayTip("using the imdb number " & $imdbNr, 10, 16) ;fill in the form on nlondertitels.com $oIE = _IECreate("http://www.nlondertitels.com/", 0, 0); $oForm = _IEFormGetCollection ($oIE, 0) ;get first (and only) form $oQuery = _IEFormElementGetObjByName ($oForm, "search") _IEFormElementSetValue ($oQuery, $imdbNr) $oQuery = _IEFormElementGetObjByName ($oForm, "in") _IEFormElementSetValue ($oQuery, "i") _IEFormSubmit ($oForm,1) ;submit request and wait for answer Else ;search by using the title TrayTip("Couldn't find an imdb number", 10, 16) $sUrl = "http://www.nlondertitels.com/search/q/" & $titel & "/1"; $oIE = _IECreate($sUrl, 0, 0); EndIf ;we are now at the page with the search results -> extract info from the links $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended $downloadIndex = 0; ;find all movie titles on the page (we do this here because the text of each link is just "download") $sText = _IEBodyReadHTML($oIE) $titles = StringRegExp($sText, '(.*?)',3) ;get the titles.. $useTitles=1 if @error<>0 then $useTitles=0 ;there was an error requesting the titles -> don't use them as filename consolewrite("error " & @error & @lf) Endif For $i=0 to $iNumLinks-1 $oLink = _IELinkGetCollection ($oIE,$i) if (StringInStr($oLink.href, "http://www.nlondertitels.com/download/")) then ;if this is a link to a subtitle $downloadIndex = $downloadIndex+1 $sLinkUrl = $oLink.href; ;construct the filename if $useTitles AND ubound($titles)>=$downloadIndex then $filename = $titles[$downloadIndex-1] Else $filename = StringMid ( $sLinkUrl, 1+StringLen ( "http://www.nlondertitels.com/download/" )) EndIf $filename = $filename & ".zip" ;TODO: could be rar also.. 7zip doesn't mind but other unzippers might.. $filename = StringRegExpReplace($filename, "[\\/:\*\?""<>]", "") ;remove all invalid characters from the filename $theFileName = $folder & "\" & $filename consolewrite($sLinkUrl & " > " & $theFileName & @LF) TrayTip($downloadIndex & " / " & $DOWNLOAD_COUNT, "Downloading " & $filename, 10, 16) ;download the sub InetGet ( $sLinkUrl,$theFileName,1) if ($downloadIndex>=$DOWNLOAD_COUNT) then ExitLoop endif endif Next