Maximus1 Posted July 14, 2010 Share Posted July 14, 2010 (edited) after two days of writing, thinking and wondering my tool is ready.... oh a nice dream ;-) as you know am i a newbe and have a little bit to learn how to do it right. my code will tell you more than my bad english. only one question. why do i get a stack overflow or something not so different? ok a second question.... how do i get the gui acessable while running the functions? expandcollapse popupHotKeySet("{PGUP}","start") #include <IE.au3> #include <String.au3> #include <Array.au3> #include <INet.au3> #include <Process.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> $a="0000001" ;imdb actor nummer $file3= "test.opt" ;das file mit der nummer des letzten actors der abgearbeitet wurde $file1="temp.txt" ;erstes tempfile $file2="temp1.txt" ;zweites tempfile $Stringleft1 = "<title>" ;linker string beim actorname $Stringright1 = "</title>" ;rechter string beim actorname $Stringleft2 = "/rg/action-box-name/headshot/media/" $Stringright2 = $a $Stringleft3 ="http://ia.media-imdb.com/images/" ;linker string beim bilderdownload $Stringright3 =".jpg" ;rechter string beim bilderdownload $url1="http://www.imdb.com/name/nm" ;der teil der loopanfangsadresse... wird mit dem wert aus $a ergänzt $url2="http://www.imdb.com/rg/action-box-name/headshot/media/" $dir1="\" ;verzeichnis wo die fertigen daten hin sollen ;~ $dir2=$dir&$dir1 $filename="\folder.jpg" Opt("GUIOnEventMode", 1) ;Wechsle in den OnEvent Modus GUICreate("IMDB Actor Loader", 200, 90, 192, 124, -1, BitOR($WS_EX_WINDOWEDGE,$WS_EX_CONTEXTHELP)) GUISetIcon("C:\Windows\System32\shell32.dll", -44) $a1= GUICtrlCreateLabel("Nummer", 10, 10, 43, 17) $a1a=GUICtrlCreateLabel("", 100, 8, 100, 17) $a2= GUICtrlCreateLabel("Actor", 10, 35, 43, 17) $a2a=GUICtrlCreateLabel("", 100, 35, 100, 17) ;~ $start = GUICtrlCreateButton("OK", 70, 55, 60) ;~ GUICtrlSetOnEvent($start, "Start") $save = GUICtrlCreateButton("Folder", 115, 55, 60) GUICtrlSetOnEvent($save, "Folder") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState(@SW_SHOW) ;GUI anzeigen ;~ Lade die nummer aus dem .opt file FileOpen(""&$file3,0) $a=FileReadLine(""&$file3,-1) ;setze wert von $a auf das was in der letzten zeile der datzei steht FileClose(""&$file3) ;~ mach erstmal nix ausser warten While 1 Sleep(10) WEnd ;~ Send("{PGUP}") Func start() While 1 $msg = GUIGetMsg() INetGet($url1&$a,""& $file1,0,0) $source= FileRead($file1) $string=_StringBetween($source,$Stringleft1,$Stringright1);actorname auslesen If @error Then ;fehlermeldung abfangen und in funktion umleiten _error() ;fehler-umgehungsfunktion aufrufen EndIf GUICtrlSetData($a1a,$a) ;actornummer in GUI schreiben GUICtrlSetData($a2a,$string[0]) ;actorname in GUI schreiben $actor=DirCreate($dir& $string[0]) ;verzeichnis mit actorname erstellen $string2=_StringBetween($source,$Stringleft2,$Stringright2);bildadresse auslesen If @error Then ;fehlermeldung abfangen und in funktion umleiten DirRemove(""&$dir& $string[0],1) ;erstellten ordner wieder löschen _error() ;fehler-umgehungsfunktion aufrufen EndIf $bilderseite=$url2&$string2[0]&$a ;link zusammensetzen, da bei inetget nur 2 variablen funktionieren InetGet($bilderseite,""& $file2,0,0) $source1= FileRead($file2) $string3=_StringBetween($source,$Stringleft3,$Stringright3);teil des links für das bild auslesen $bildonline=$Stringleft3 & $string3[0] & $Stringright3 ;link zusammensetzen, da bei inetget nur 2 variablen funktionieren $bildspeicherort=$dir&$string[0]&$filename ;dateispeicherort mit dateinamen erstellen InetGet($bildonline,""&$bildspeicherort,0,1) ;lade bild in den dateispeicherort $a=$a+1 ;nächste usernummer erstellen FileOpen($file3,2) ;letzte nummer datei öffnen FileWriteLine("" &$file3, "" & $a) ;letzte nummer reinschreiben FileClose(""&$file3) ;letzte nummer datei schliessen If $a = 999999 Then MsgBox(0,"Ende","ende") ExitLoop EndIf WEnd EndFunc ;~ fehler umgehungsfunktion Func _error() $a=$a+1 GUICtrlSetData($a1a,$a) If $a = 999999 Then MsgBox(0,"Ende","ende") Exit EndIf Send("{PGUP}") ;gehe in zurück in die funktion start ( goto :-) ) EndFunc ;~ Speicherort festlegen Func Folder() Global $dir=FileSelectFolder("Choose a folder.", "",1)&$dir1 ;speicherort dialog MsgBox(0,"","" &$dir) If $dir = "\" Then ;wenn variable $dir leer ist gehts nicht weiter MsgBox(0,"Error","Choose a folder.") Else If $dir = "Computer\" Then ;wenn variable $dir "Computer" ist gehts nicht weiter MsgBox(0,"Error","Choose a real folder.") Else $start = GUICtrlCreateButton("OK", 25, 55, 60) ;ok button erstellen GUICtrlSetOnEvent($start, "Start") ;start event freigeben EndIf EndIf EndFunc ;~ mach das fenster zu es zieht Func CLOSEClicked() ;geht nur wenn keine andere funktion arbeitet Exit EndFunc Edited July 14, 2010 by Maximus1 Link to comment Share on other sites More sharing options...
kaotkbliss Posted July 14, 2010 Share Posted July 14, 2010 (edited) because I don't know any language but english, it makes it hard for me to understang your ;comments but I think at least part of the problem is here While 1 Sleep(1) WEnd try While 1 Sleep(10) WEnd *Edit* to answer your second question you can solve both problems by using While 1 $msg = GUIGetMsg() ... ... WEnd or even HotKeySet() Edited July 14, 2010 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Maximus1 Posted July 14, 2010 Author Share Posted July 14, 2010 (edited) sorry i posted a version with some massive errors. the while loop is now "for next" i update the code now. damn something went wrong here. nothing works :-( Edited July 14, 2010 by Maximus1 Link to comment Share on other sites More sharing options...
Maximus1 Posted July 14, 2010 Author Share Posted July 14, 2010 while 1 $msg = GUIGetMsg() didn`t make the gui reacting on $GUI_EVENT_CLOSE changing sleep(1) to 10 will resilt in a lower use of memory ? script restored to the last version which was running. Link to comment Share on other sites More sharing options...
Tvern Posted July 15, 2010 Share Posted July 15, 2010 (edited) The RAM problem was probably caused by your error function which caused an infinite loop leading to a stack overflow. Example: start -> error -> hotkey -> start -> error -> hotkey etc The start function never finishes, it just waits for error to finish, which in turn is waiting for another start... I've written a fix for this and made a few other changes. *Eliminated many variables. *Changed many vars from global to local. *Used an ini to store the last downloaded number. I'd also store the folder dir here. *Renamed some vars. Mainly so I could see what I was doing. *Took the loop out of the function to keep the UI responsive. Have a look: expandcollapse popup#include <String.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $sDir, $cNummer, $cActor, $bStart ;these variables are used inside functions, so I declared them as global Global $sFile = "test.opt" Global $nLastCompleted = IniRead($sFile,"Progress","LastCompleted",1) Opt("GUIOnEventMode", 1) GUICreate("IMDB Actor Loader", 200, 90, 192, 124, -1, BitOR($WS_EX_WINDOWEDGE,$WS_EX_CONTEXTHELP)) GUISetIcon("C:\Windows\System32\shell32.dll", -44) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;moved this up as I like to keep GUI and GUICtrl stuff seperated. GUICtrlCreateLabel("Nummer", 10, 10, 43, 17) ;There was no reason to store the CtrlID at this point, as it isn't used elsewhere in the script. $cNummer = GUICtrlCreateLabel("", 100, 8, 100, 17) ;Gave this variable a more descriptive name. GUICtrlCreateLabel("Actor", 10, 35, 43, 17) ;There was no reason to store the CtrlID at this point, as it isn't used elsewhere in the script. $cActor = GUICtrlCreateLabel("", 100, 35, 100, 17) ;Gave this variable a more descriptive name. GUICtrlCreateButton("Folder", 115, 55, 60) ;There was no reason to store the CtrlID at this point, as we can refer to the last created control on the next line. GUICtrlSetOnEvent(-1, "Folder") ;Instead of a CtrlID I used "-1" to refer to the last created control. GUISetState(@SW_SHOW) ;Your schipt will always return here, which keeps the UI responsive. (or atleast it should) While 1 Sleep(1) ;idle the cpu. (practically the same as sleep(10)) If $bStart Then ;bStart is a bool variable; it can be either TRUE, or FALSE. If it is true, the next lines are executed. $nLastCompleted += 1 ;add 1 to lastcompleted, which gives the number of the next actor to process. _Run($nLastCompleted) ;this will run the function _Run, and pass it the number of the next actor to be downloaded. IniWrite($sFile, "Progress", "LastCompleted", $nLastCompleted) ;when _Run is done the number is writen to the inifile. ;You could also only make it write a number if you exit the script, which is nicer, but you have to avoid crashes, or it won't write anything. EndIf WEnd ;this is the function that's pressed by the start button. Func start() $bStart = Not $bStart ;if $bStart = FALSE, it changes to TRUE, starting the function and vice versa. If $bStart Then ;if we just started the function. ($bStart = TRUE), then this is true. GUICtrlSetData(@GUI_CtrlId,"Stop") ;the function is running, so the button text has to say "stop" Else GUICtrlSetData(@GUI_CtrlId,"Start") ;the function just stopped, so the button text has to say "start" again. EndIf EndFunc ;this function will get the picture of one actor each time it's called. Which actor will depend on the value of $nActor Func _run($nActor) ;$nActor will act as a local variable that get's is value from $nLastCompleted on line 29. This avoids the use of global variables. Local $sSource, $sName, $sImageUrl ;some local variables with descriptive names. Local $sNameLeft = "<title>" Local $sNameRight = "</title>" Local $sImageSiteLeft = "/rg/action-box-name/headshot/media/" Local $sImageLeft = "http://ia.media-imdb.com/images/" Local $sFileName = "\folder.jpg" $sSource = BinaryToString(InetRead("http://www.imdb.com/name/nm" & $nActor)) ;Directly download the source into a var, scipping the temp file. $sName = _StringBetween($sSource, $sNameLeft, $sNameRight) If @error Then Return ;the old error function caused an infinite loop leading to a stack overflow error. This just ends the function "_Run", returning to line 30. GUICtrlSetData($cNummer, $nActor) GUICtrlSetData($cActor, $sName[0]) $sImageSiteUrl = _StringBetween($sSource, $sImageSiteLeft, '"') If @error Then Return ;return to line 30 $sSource = BinaryToString(InetRead("http://www.imdb.com/rg/action-box-name/headshot/media/" & $sImageSiteUrl[0])) ;directly download source to a variable again. $sImageUrl = _StringBetween($sSource, $sImageLeft, '"') DirCreate($sDir & $sName[0]) InetGet($sImageLeft & $sImageUrl[0], $sDir & $sName[0] & $sFileName,0,1) ;if this line is reached the function was successfully finished and the script will continue with line 30. EndFunc Func Folder() Do $dir=FileSelectFolder("Choose a folder.", "",1) ;This will repeat untill a valid folder is chosen Until StringInStr(FileGetAttrib($dir),"D") GUICtrlCreateButton("OK", 25, 55, 60) GUICtrlSetOnEvent(-1, "Start") $dir &= "\" EndFunc Func CLOSEClicked() ;geht nur wenn keine andere funktion arbeitet ;actually while another function runs the event gets queue'd and executed when the function returns. ;Because of this it is important not to have functions that run for a very long time ;This is the reason I took the loop out of Function "_Run", making it return to process any waiting events after each actor. Exit EndFunc Edit: added comments and made minor adjustments. Edited July 15, 2010 by Tvern Link to comment Share on other sites More sharing options...
Maximus1 Posted July 15, 2010 Author Share Posted July 15, 2010 (edited) oh thats hard. now i have to read very much to understand what you wrote in that script. thanks for your help Edit: i`ve tested it and the gui doesn`t react on the X button. is it realy so difficult for autoit? i have some questions. i hope you can explain to me. If @error Then Return ;the old error function caused an infinite loop leading to a stack overflow error. return to what/where? when are the data written to the ini file? in lines 27-28? how is this going? i see a while loop and some functions, how do they work together? where does $nActor come from? Edited July 15, 2010 by Maximus1 Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 return to what/where? What it does is it makes the function exit when there is an error encountered at the previous line. when are the data written to the ini file? in lines 27-28? how is this going? i see a while loop and some functions, how do they work together? While 1 Sleep(1) If $bStart Then _Run($nLastCompleted) IniWrite($sFile, "Progress", "LastCompleted", $nLastCompleted) ;<--- data written to ini file here $nLastCompleted += 1 EndIf WEnd Link to comment Share on other sites More sharing options...
Tvern Posted July 15, 2010 Share Posted July 15, 2010 Oh thats hard. now i have to read very much to understand what you wrote in that script. Yeah I ususally supply more comments, but I really had to go to bed. I'll update my script with a more commented one. If you have any questions about it just ask. The x button works for me. Is this the full script, or is it part of a project? return to what/where? A function only ends if it reaches "EndFunc", or "Return", or if the entire script ends. This means that if you have a function that calls another function before it ends, the remainder of the function will wait untill the other function returns. If that function never ends because it calls the first function again you have an increasing number of unfinished functions waiting untill they can finish. If a function reaches "Return", or "EndFunc", the script continues with the line after the one that called the function in the first place. I'll try to demonstrate it, but I'm not sure how clearly I'll be able to do so. ;this script improperly has a function calling itsself to create a loop ;this is a simplified model of what you had in the original script. (start->error->hotkey->start) Global $i _Function() Func _Function() $i += 1 ;just to keep a count (oh btw this just means: "$i = $i + 1", or "Increase $i by 1") ConsoleWrite("Function has started " & $i & " times." & @CRLF) ;This shows you whenever _Function1 is started. Remember that every started function has to end at some point. _Function() ;This calls _Function again, the current _Function can only end if this ever returns. $i -= 1 ;If _Function ever returns we can be sure we'll be able to end this function. MsgBox(0,"Function has ended",$i & " instances of function are still waiting to finish") EndFunc ;this script shows how to get similar functionality, without the recursive function calls. Global $i While $i < 4000 ;more than twice as many as in the other example. _Function() WEnd Func _Function() $i += 1 ;just to keep a count ConsoleWrite("Function has started " & $i & " times." & @CRLF) ;This shows you whenever _Function1 is started. Remember that every started function has to end at some point. Return ;The function will properly end now and another one will be started, even thourh the messagebox has not been displayed. $i -= 1 MsgBox(0,"Function has ended",$i & " instances of function are still waiting to finish") ;we don't want to click an infinite amount of messageboxes, best exit the function before this line. EndFunc A certain level of recursion (functions starting functions and waiting for them to return) is ok, but at one point all waiting functions will have to be able to finish. Link to comment Share on other sites More sharing options...
Maximus1 Posted July 15, 2010 Author Share Posted July 15, 2010 (edited) now i begin to realize. you use a small while loop and let the _run function end. when an error occures the "return" will go to "while 1" and when the bool $bStart=1 , the small while loop gets worked again and ......is it right?i realy thank you so much for showing me to do it a very much better way.i wrote the tool to get my database nearly complete. now the tool runs very well and i want to give it for free to the media browser community. do i have your ok?now i`ve seen you made more comments.fantastic Edited July 15, 2010 by Maximus1 Link to comment Share on other sites More sharing options...
Tvern Posted July 15, 2010 Share Posted July 15, 2010 When an error occures the "return" will go to "while 1" and when the bool $bStart=1 , the small while loop gets worked again and ......is it right?Almost. It's basically the same as when the function would have finished successfully, so it just continues from where _run was called. Inside the while loop, but not at the top.Do i have your ok?Ofcoarse. Link to comment Share on other sites More sharing options...
Maximus1 Posted July 16, 2010 Author Share Posted July 16, 2010 hi there, a new problem. after changing the code to run on TMDB i tried to add the folder to the inifile... this was easy. reading the entry at startup is done to, but how do i make the start button visible when $dir is set? the following will do the job, but after 2-3 seconds the start button changes to the alternate text and is inaccessible. i`ve set the not functioning as comment expandcollapse popup#include <String.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $dir, $cNummer, $cActor, $bStart Global $sFile = "test.opt" ;das file mit der nummer des letzten actors der abgearbeitet wurde Global $nLastCompleted = IniRead($sFile,"Progress","LastCompleted",1) Global $dir = IniRead($sFile,"Data","Folder","NotFound") ;NEW reads the folder to $dir Opt("GUIOnEventMode", 1) ;Wechsle in den OnEvent Modus GUICreate("IMDB Actor Loader", 200, 90, 192, 124, -1, BitOR($WS_EX_WINDOWEDGE,$WS_EX_CONTEXTHELP)) GUISetIcon("C:\Windows\System32\shell32.dll", -44) GUICtrlCreateLabel("Nummer", 10, 10, 43, 17) $cNummer = GUICtrlCreateLabel("", 100, 8, 100, 17) GUICtrlCreateLabel("Actor", 10, 35, 43, 17) $cActor = GUICtrlCreateLabel("", 100, 35, 100, 17) GUICtrlCreateButton("Folder", 115, 55, 60) GUICtrlSetOnEvent(-1, "Folder") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState(@SW_SHOW) ;GUI anzeigen MsgBox(0,"folder",""&$dir) ;~ if $dir = "NotFound" Then ;~ MsgBox(0,"if not 1",""&$dir) ;~ GUICtrlCreateButton("----->", 25, 55, 60) ;ok button erstellen ;~ ElseIf $dir = "" Then ;~ GUICtrlCreateButton("----->", 25, 55, 60) ;ok button erstellen ;~ Else ;~ GUICtrlCreateButton("OK", 25, 55, 60) ;ok button erstellen ;~ GUICtrlSetOnEvent(-1, "Start") ;start event freigeben ;~ EndIf ;~ mach erstmal nix ausser warten While 1 Sleep(1) If $bStart Then _Run($nLastCompleted) IniWrite($sFile, "Progress", "LastCompleted", $nLastCompleted) $nLastCompleted += 1 EndIf WEnd Func start() $bStart = Not $bStart If $bStart Then GUICtrlSetData(@GUI_CtrlId,"Stop") Else GUICtrlSetData(@GUI_CtrlId,"Start") EndIf EndFunc Func _run($nActor) Local $sSource, $sName, $sImageUrl Local $sNameLeft = "<h2>" ;linker string beim actorname Local $sNameRight = "</h2>" ;rechter string beim actorname Local $sImageLeft = "http://hwcdn.themoviedb.org/profiles/" ;linker string beim bilderdownload Local $sFileName = "\folder.jpg" $sSource = BinaryToString(InetRead("http://www.themoviedb.org/person/" & $nActor)) $sName = _StringBetween($sSource, $sNameLeft, $sNameRight) ;actorname auslesen If @error Then Return ;the old error function caused an infinite loop leading to a stack overflow error. GUICtrlSetData($cNummer, $nActor) ;actornummer in GUI schreiben GUICtrlSetData($cActor, $sName[0]) ;actorname in GUI schreiben $sImageUrl = _StringBetween($sSource, $sImageLeft, '"') ;teil des links für das bild auslesen If @error Then Return DirCreate($dir & $sName[0]) InetGet($sImageLeft & $sImageUrl[0], $dir & $sName[0] & $sFileName,0,1) ;lade bild in den dateispeicherort EndFunc ;~ Speicherort festlegen Func Folder() Do $dir=FileSelectFolder("Choose a folder.", "",1) ;This will repeat untill a valid folder is chosen Until StringInStr(FileGetAttrib($dir),"D") IniWrite($sFile, "Data", "Folder", $dir) ;NEW writes $dir to inifile GUICtrlCreateButton("OK", 25, 55, 60) ;ok button erstellen GUICtrlSetOnEvent(-1, "Start") ;start event freigeben $dir &= "\" EndFunc ;~ mach das fenster zu es zieht Func CLOSEClicked() ;geht nur wenn keine andere funktion arbeitet Exit EndFunc can you help me again please or show me a site where i can read about it? Link to comment Share on other sites More sharing options...
Tvern Posted July 16, 2010 Share Posted July 16, 2010 I just noticed the folder function will actually create a new button each time it's run, creating a load of buttons on top of eachother. Try this: expandcollapse popup#include <String.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $dir, $cNummer, $cActor, $bStart, $cStart Global $sFile = "test.opt" ;das file mit der nummer des letzten actors der abgearbeitet wurde Global $nLastCompleted = IniRead($sFile,"Progress","LastCompleted",1) Global $dir = IniRead($sFile,"Data","Folder","NotFound") ;NEW reads the folder to $dir Opt("GUIOnEventMode", 1) ;Wechsle in den OnEvent Modus GUICreate("IMDB Actor Loader", 200, 90, 192, 124, -1, BitOR($WS_EX_WINDOWEDGE,$WS_EX_CONTEXTHELP)) GUISetIcon("C:\Windows\System32\shell32.dll", -44) GUICtrlCreateLabel("Nummer", 10, 10, 43, 17) $cNummer = GUICtrlCreateLabel("", 100, 8, 100, 17) GUICtrlCreateLabel("Actor", 10, 35, 43, 17) $cActor = GUICtrlCreateLabel("", 100, 35, 100, 17) GUICtrlCreateButton("Folder", 115, 55, 60) GUICtrlSetOnEvent(-1, "Folder") $cStart = GUICtrlCreateButton("Start", 25, 55, 60) ;create start button GUICtrlSetOnEvent($cStart, "Start") ;start event freigeben If Not StringInStr(FileGetAttrib($dir),"D") Then GUICtrlSetState($cStart,$GUI_DISABLE) ;disable the start button if no valid path is loaded GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState(@SW_SHOW) ;GUI anzeigen ;~ if $dir = "NotFound" Then ;~ MsgBox(0,"if not 1",""&$dir) ;~ GUICtrlCreateButton("----->", 25, 55, 60) ;ok button erstellen ;~ ElseIf $dir = "" Then ;~ GUICtrlCreateButton("----->", 25, 55, 60) ;ok button erstellen ;~ Else ;~ GUICtrlCreateButton("OK", 25, 55, 60) ;ok button erstellen ;~ GUICtrlSetOnEvent(-1, "Start") ;start event freigeben ;~ EndIf ;~ mach erstmal nix ausser warten While 1 Sleep(1) If $bStart Then _Run($nLastCompleted) IniWrite($sFile, "Progress", "LastCompleted", $nLastCompleted) $nLastCompleted += 1 EndIf WEnd Func start() $bStart = Not $bStart If $bStart Then GUICtrlSetData(@GUI_CtrlId,"Stop") Else GUICtrlSetData(@GUI_CtrlId,"Start") EndIf EndFunc Func _run($nActor) Local $sSource, $sName, $sImageUrl Local $sNameLeft = "<h2>" ;linker string beim actorname Local $sNameRight = "</h2>" ;rechter string beim actorname Local $sImageLeft = "http://hwcdn.themoviedb.org/profiles/" ;linker string beim bilderdownload Local $sFileName = "\folder.jpg" $sSource = BinaryToString(InetRead("http://www.themoviedb.org/person/" & $nActor)) $sName = _StringBetween($sSource, $sNameLeft, $sNameRight) ;actorname auslesen If @error Then Return ;the old error function caused an infinite loop leading to a stack overflow error. GUICtrlSetData($cNummer, $nActor) ;actornummer in GUI schreiben GUICtrlSetData($cActor, $sName[0]) ;actorname in GUI schreiben $sImageUrl = _StringBetween($sSource, $sImageLeft, '"') ;teil des links für das bild auslesen If @error Then Return DirCreate($dir & $sName[0]) InetGet($sImageLeft & $sImageUrl[0], $dir & $sName[0] & $sFileName,0,1) ;lade bild in den dateispeicherort EndFunc ;~ Speicherort festlegen Func Folder() Do $dir=FileSelectFolder("Choose a folder.", "",1) ;This will repeat untill a valid folder is chosen Until StringInStr(FileGetAttrib($dir),"D") IniWrite($sFile, "Data", "Folder", $dir) ;NEW writes $dir to inifile GUICtrlSetState($cStart,$GUI_Enable) ;enable the start button $dir &= "\" EndFunc ;~ mach das fenster zu es zieht Func CLOSEClicked() ;geht nur wenn keine andere funktion arbeitet Exit EndFunc Link to comment Share on other sites More sharing options...
Maximus1 Posted July 16, 2010 Author Share Posted July 16, 2010 (edited) thanks that works :-) i`ve found a bug. when i start the tool and the folder is loaded a \ has to be added. Global $dir = IniRead($sFile,"Data","Folder","NotFound")&"\" fixes it. now i have 2 tools. one for imdb and one for tmdb. the tmdb servers are realy fast and the imdb servers are slow. Edited July 16, 2010 by Maximus1 Link to comment Share on other sites More sharing options...
Tvern Posted July 16, 2010 Share Posted July 16, 2010 Seen as the two tools are so similar I would try to combine them into one with a dropdown that allows you to select which one to use. p.s. Make sure you apply the changes to the start button to both scripts. Link to comment Share on other sites More sharing options...
Maximus1 Posted July 16, 2010 Author Share Posted July 16, 2010 (edited) i made the startbutton thing in both tools. to combine the 2 tools i do not have the knowledge.... at the moment. i`ll look in 1 or 2 days. for everyone who want to see the code: IMDB: expandcollapse popup#include <String.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $dir, $cNummer, $cActor, $bStart Global $sFile = "test.opt" ;das file mit der nummer des letzten actors der abgearbeitet wurde Global $nLastCompleted = IniRead($sFile,"Progress","LastCompleted",1) Global $dir = IniRead($sFile,"Data","Folder","NotFound")&"\" Opt("GUIOnEventMode", 1) ;Wechsle in den OnEvent Modus GUICreate("IMDB Actor Loader", 200, 90, 192, 124, -1, BitOR($WS_EX_WINDOWEDGE,$WS_EX_CONTEXTHELP)) GUISetIcon("C:\Windows\System32\shell32.dll", -44) GUICtrlCreateLabel("Nummer", 10, 10, 43, 17) $cNummer = GUICtrlCreateLabel("", 100, 8, 100, 17) GUICtrlCreateLabel("Actor", 10, 35, 43, 17) $cActor = GUICtrlCreateLabel("", 100, 35, 100, 17) GUICtrlCreateButton("Folder", 115, 55, 60) GUICtrlSetOnEvent(-1, "Folder") $cStart = GUICtrlCreateButton("Start", 25, 55, 60) ;create start button GUICtrlSetOnEvent($cStart, "Start") ;start event freigeben If Not StringInStr(FileGetAttrib($dir),"D") Then GUICtrlSetState($cStart,$GUI_DISABLE) ;disable the start button if no valid path is loaded GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState(@SW_SHOW) ;GUI anzeigen ;~ mach erstmal nix ausser warten While 1 Sleep(1) If $bStart Then _Run($nLastCompleted) IniWrite($sFile, "Progress", "LastCompleted", $nLastCompleted) $nLastCompleted += 1 EndIf WEnd Func start() $bStart = Not $bStart If $bStart Then GUICtrlSetData(@GUI_CtrlId,"Stop") Else GUICtrlSetData(@GUI_CtrlId,"Start") EndIf EndFunc Func _run($nActor) Local $sSource, $sName, $sImageUrl Local $sNameLeft = "<title>" ;linker string beim actorname Local $sNameRight = "</title>" ;rechter string beim actorname Local $sImageSiteLeft = "/rg/action-box-name/headshot/media/" Local $sImageLeft = "http://ia.media-imdb.com/images/" ;linker string beim bilderdownload Local $sFileName = "\folder.jpg" $sSource = BinaryToString(InetRead("http://www.imdb.com/name/nm" & $nActor)) $sName = _StringBetween($sSource, $sNameLeft, $sNameRight) ;actorname auslesen If @error Then Return ;the old error function caused an infinite loop leading to a stack overflow error. GUICtrlSetData($cNummer, $nActor) ;actornummer in GUI schreiben GUICtrlSetData($cActor, $sName[0]) ;actorname in GUI schreiben $sImageSiteUrl = _StringBetween($sSource, $sImageSiteLeft, '"') ;bildadresse auslesen If @error Then Return ;fehlermeldung abfangen und in funktion umleiten $sSource = BinaryToString(InetRead("http://www.imdb.com/rg/action-box-name/headshot/media/" & $sImageSiteUrl[0])) $sImageUrl = _StringBetween($sSource, $sImageLeft, '"') ;teil des links für das bild auslesen If FileExists($dir & $sName[0]) Then Return DirCreate($dir & $sName[0]) InetGet($sImageLeft & $sImageUrl[0], $dir & $sName[0] & $sFileName,0,1) ;lade bild in den dateispeicherort EndFunc ;~ Speicherort festlegen Func Folder() Do $dir=FileSelectFolder("Choose a folder.", "",1) ;This will repeat untill a valid folder is chosen Until StringInStr(FileGetAttrib($dir),"D") IniWrite($sFile, "Data", "Folder", $dir) GUICtrlCreateButton("OK", 25, 55, 60) ;ok button erstellen GUICtrlSetOnEvent(-1, "Start") ;start event freigeben $dir &= "\" EndFunc ;~ mach das fenster zu es zieht Func CLOSEClicked() ;geht nur wenn keine andere funktion arbeitet Exit EndFunc TMDB: expandcollapse popup#include <String.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $dir, $cNummer, $cActor, $bStart Global $sFile = "test.opt" ;das file mit der nummer des letzten actors der abgearbeitet wurde Global $nLastCompleted = IniRead($sFile,"Progress","LastCompleted",1) Global $dir = IniRead($sFile,"Data","Folder","NotFound")&"\" Opt("GUIOnEventMode", 1) ;Wechsle in den OnEvent Modus GUICreate("TMDB Actor Loader", 200, 90, 192, 124, -1, BitOR($WS_EX_WINDOWEDGE,$WS_EX_CONTEXTHELP)) GUISetIcon("C:\Windows\System32\shell32.dll", -44) GUICtrlCreateLabel("Nummer", 10, 10, 43, 17) $cNummer = GUICtrlCreateLabel("", 100, 8, 100, 17) GUICtrlCreateLabel("Actor", 10, 35, 43, 17) $cActor = GUICtrlCreateLabel("", 100, 35, 100, 17) GUICtrlCreateButton("Folder", 115, 55, 60) GUICtrlSetOnEvent(-1, "Folder") $cStart = GUICtrlCreateButton("Start", 25, 55, 60) ;create start button GUICtrlSetOnEvent($cStart, "Start") ;start event freigeben If Not StringInStr(FileGetAttrib($dir),"D") Then GUICtrlSetState($cStart,$GUI_DISABLE) ;disable the start button if no valid path is loaded GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState(@SW_SHOW) ;GUI anzeigen ;~ mach erstmal nix ausser warten While 1 Sleep(1) If $bStart Then _Run($nLastCompleted) IniWrite($sFile, "Progress", "LastCompleted", $nLastCompleted) $nLastCompleted += 1 EndIf WEnd Func start() $bStart = Not $bStart If $bStart Then GUICtrlSetData(@GUI_CtrlId,"Stop") Else GUICtrlSetData(@GUI_CtrlId,"Start") EndIf EndFunc Func _run($nActor) Local $sSource, $sName, $sImageUrl Local $sNameLeft = "<h2>" ;linker string beim actorname Local $sNameRight = "</h2>" ;rechter string beim actorname Local $sImageLeft = "http://hwcdn.themoviedb.org/profiles/" ;linker string beim bilderdownload Local $sFileName = "\folder.jpg" $sSource = BinaryToString(InetRead("http://www.themoviedb.org/person/" & $nActor)) $sName = _StringBetween($sSource, $sNameLeft, $sNameRight) ;actorname auslesen If @error Then Return ;the old error function caused an infinite loop leading to a stack overflow error. GUICtrlSetData($cNummer, $nActor) ;actornummer in GUI schreiben GUICtrlSetData($cActor, $sName[0]) ;actorname in GUI schreiben $sImageUrl = _StringBetween($sSource, $sImageLeft, '"') ;teil des links für das bild auslesen If @error Then Return If FileExists($dir & $sName[0]) Then Return DirCreate($dir & $sName[0]) InetGet($sImageLeft & $sImageUrl[0], $dir & $sName[0] & $sFileName,0,1) ;lade bild in den dateispeicherort EndFunc ;~ Speicherort festlegen Func Folder() Do $dir=FileSelectFolder("Choose a folder.", "",1) ;This will repeat untill a valid folder is chosen Until StringInStr(FileGetAttrib($dir),"D") IniWrite($sFile, "Data", "Folder", $dir) GUICtrlCreateButton("OK", 25, 55, 60) ;ok button erstellen GUICtrlSetOnEvent(-1, "Start") ;start event freigeben $dir &= "\" EndFunc ;~ mach das fenster zu es zieht Func CLOSEClicked() ;geht nur wenn keine andere funktion arbeitet Exit EndFunc comments in both scripts are NOT actualized.... now after that i`ll try to make a linereader which reads the lines in a txtfile, searches google for matching pictures and downloads one of them. i have to look how can i automate the download of the best matching picture. when i stuck, i know where i can ask :-D Edited July 16, 2010 by Maximus1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now