Hallo!
Ich nehme hier schon länger passiv am Forum teil und mir wurde mit der Boardsuche immer gut geholfen. Bis jetzt...
Ich habe einen Gallery Downloader für Imagefap geschrieben und scheitere an einer Sache.
Wahrscheinlich ist der Code für viele verwirrend. Es geht jetzt auch nur darum das es mal jemand testet und vielleicht spaß dran hat.
Hier erstmal der Code:
Spoiler anzeigen
#include <GUIConstants.au3>
#include <inet.au3>
#include <string.au3>
#include <array.au3>
#include <guilistview.au3>
#include <file.au3>
#include <http.au3>
Opt("trayicondebug", 1)
[/autoit] [autoit][/autoit] [autoit]Global $f
Global $getzaehler = 0
Global $end
$save = @WorkingDir & "\save.dbi"
[/autoit] [autoit][/autoit] [autoit]#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 403, 309, 193, 115)
$ListView1 = GUICtrlCreateListView("ID|Name|Bilder", 8, 8, 386, 174)
GUICtrlSendMsg(-1, 0x101E, 0, 70)
GUICtrlSendMsg(-1, 0x101E, 1, 250)
GUICtrlSendMsg(-1, 0x101E, 2, 50)
$Start = GUICtrlCreateButton("Start", 8, 184, 59, 17, 0)
$Stop = GUICtrlCreateButton("Stop", 72, 184, 59, 17, 0)
$Loeschen = GUICtrlCreateButton("Loeschen", 136, 184, 67, 17, 0)
$ClipGet = GUICtrlCreateCheckbox("ClipGet", 88, 280, 97, 17)
GUICtrlCreateGroup("", 8, 208, 137, 65)
$Input1 = GUICtrlCreateInput("", 16, 224, 121, 21)
$add = GUICtrlCreateButton("add", 32, 248, 83, 17, $BS_DEFPUSHBUTTON)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Progress1 = GUICtrlCreateProgress(208, 184, 190, 16, $PBS_SMOOTH)
$Progress2 = GUICtrlCreateProgress(152, 232, 246, 16, $PBS_SMOOTH)
$Label1 = GUICtrlCreateLabel("", 296, 208, 100, 17)
$Label2 = GUICtrlCreateLabel("", 296, 256, 36, 17)
$Optionen = GUICtrlCreateButton("Optionen", 8, 280, 67, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetState($Stop, $GUI_DISABLE)
Dim $saves
[/autoit] [autoit][/autoit] [autoit]If _FileReadToArray($save, $saves) = 1 Then
For $h = 1 To $saves[0] - 1
If $saves[$h] <> "||" Then GUICtrlCreateListViewItem($saves[$h], $ListView1)
Next
EndIf
While 1
[/autoit] [autoit][/autoit] [autoit]$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
FileDelete($save)
For $o = 1 To _GUICtrlListViewGetItemCount($ListView1)
If _GUICtrlListViewGetItemText($ListView1, $o - 1) <> "||" Then
FileWriteLine($save, _GUICtrlListViewGetItemText($ListView1, $o - 1))
EndIf
Next
Exit
Case $Loeschen
_GUICtrlListViewDeleteItem($ListView1, _GUICtrlListViewGetCurSel($ListView1))
Case $add
_add()
Case $Start
GUICtrlSetState($Stop, $GUI_ENABLE)
GUICtrlSetState($Start, $GUI_DISABLE)
AdlibEnable("proc1", 1000)
Case $Stop
ende()
EndSwitch
If GUICtrlRead($ClipGet) = 1 Then zwischenablage()
Sleep(33)
WEnd
Func proc1()
$itemcount = _GUICtrlListViewGetItemCount($ListView1)
Global $getzaehler = 0
If $itemcount >= 1 Then
$getitemsplit = StringSplit(_GUICtrlListViewGetItemText($ListView1, 0), "|")
_GUICtrlListViewSetItemSelState($ListView1, 0)
For $g = 0 To 20
$ret = proc2($getitemsplit[1], $g)
If $ret = 1 Then
ende()
ExitLoop
EndIf
Next
If $ret = 0 Then _GUICtrlListViewDeleteItem($ListView1, 0)
FileDelete($save)
For $o = 1 To _GUICtrlListViewGetItemCount($ListView1)
If _GUICtrlListViewGetItemText($ListView1, $o - 1) <> "||" Then
FileWriteLine($save, _GUICtrlListViewGetItemText($ListView1, $o - 1))
EndIf
Next
_GUICtrlListViewDeleteAllItems($ListView1)
If _FileReadToArray($save, $saves) = 1 Then
For $h = 1 To $saves[0] - 1
If $saves[$h] <> "||" Then GUICtrlCreateListViewItem($saves[$h], $ListView1)
Next
EndIf
EndIf
ende()
EndFunc ;==>proc1
Func proc2($gal, $page) ;------------------------------------------------------------------------------------------------------------------
$break = 0
$source = _INetGetSource("http://www.imagefap.com/gallery.php?pgid=&gid=" & $gal & "&page=" & $page)
If StringInStr($source, "Could not find gallery") = 0 Then
$split = StringSplit($source, @CRLF)
$strings = ""
For $a = 1 To $split[0]
If StringInStr($split[$a], "image.php?id=") Then
$b = _StringBetween($split[$a], "src='", "'></a>", -1, 1)
$strings &= $b[0] & "-"
EndIf
Next
$stringsp = StringSplit($strings, "-")
If StringLen($strings) > 3 Then DirCreate(@WorkingDir & "\" & $gal)
For $c = 1 To $stringsp[0] - 1
$stringrep = StringReplace($stringsp[$c], "http://images.imagefap.com/images/thumb", "")
$ssplit = StringSplit($stringrep, "/")
Do
$getzaehler += 1
$chk = 0
$ctrl = 0
Sleep(80)
GUICtrlSetData($Label1, $ssplit[4])
InetGet("http://images1.imagefap.com/full/getimg.php?img=" & $ssplit[4], @WorkingDir & "/" & $gal & "/" & $getzaehler & "-" & $ssplit[4], 0, 1)
While @InetGetActive
GUICtrlSetData($Progress1, (100 / 80) * $ctrl)
Sleep(40)
If GUIGetMsg() = $Stop Then
$break = 1
ElseIf GUIGetMsg() = $add Then
_add()
EndIf
zwischenablage()
If @InetGetBytesRead = -1 Then
InetGet("")
EndIf
$ctrl += 1
If $ctrl >= 80 Then InetGet("")
If $break = 1 Then ExitLoop
WEnd
GUICtrlSetData($Progress1, 100)
$size = FileGetSize(@WorkingDir & "/" & $gal & "/" & $getzaehler & "-" & $ssplit[4])
If $size < 100 Then
FileDelete(@WorkingDir & "/" & $gal & "/" & $getzaehler & "-" & $ssplit[4])
$getzaehler -= 1
EndIf
Until $size > 100 Or $getzaehler >= 40 Or $break = 1
If $break = 1 Then
Return $break
ExitLoop
EndIf
Next
Else
EndIf
EndFunc ;==>proc2
Func _add()
If StringLen(GUICtrlRead($Input1)) >= 5 Then
If _GUICtrlListViewFindItem($ListView1, GUICtrlRead($Input1)) = -1 Then
$src = _INetGetSource("http://www.imagefap.com/gallery.php?gid=" & GUICtrlRead($Input1))
$str = _StringBetween($src, "white size=4><b>", @CRLF, -1, 1)
$2 = _StringBetween($src, "page=", ">", -1, 1)
_ArrayPop($2)
$seiten = StringReplace(_ArrayPop($2), '"', '')
If $seiten = "9" Then
$mehr = "<"
Else
$mehr = ">"
EndIf
If StringInStr($src, "Could not find gallery") Then
GUICtrlSetBkColor($Input1, 0xAA3333)
Else
GUICtrlSetBkColor($Input1, 0xFFFFFF)
GUICtrlCreateListViewItem(GUICtrlRead($Input1) & "|" & $str[0] & "|" & $mehr & ($seiten + 1) * 24, $ListView1)
FileWriteLine($save, GUICtrlRead($Input1) & "|" & $str[0] & "|" & $mehr & ($seiten + 1) * 24)
GUICtrlSetData($Input1, "")
EndIf
EndIf
EndIf
EndFunc ;==>_add
Func zwischenablage()
If StringInStr(ClipGet(), "gallery.php") Then
If StringInStr(ClipGet(), "&gen=") = 0 Then
$endstring = ClipGet() & "&gen="
Else
$endstring = ClipGet()
EndIf
$muell = _StringBetween($endstring, "gid=", "&gen", -1, 1)
If _GUICtrlListViewFindItem($ListView1, $muell[0]) = -1 Then
$src = _INetGetSource("http://www.imagefap.com/gallery.php?gid=" & $muell[0])
$str = _StringBetween($src, "white size=4><b>", @CRLF, -1, 1)
;----------Seitenanzahl--------------
$2 = _StringBetween($src, "page=", ">", -1, 1)
_ArrayPop($2)
$seiten = StringReplace(_ArrayPop($2), '"', '')
If $seiten = "9" Then
$mehr = "<"
Else
$mehr = ">"
EndIf
GUICtrlCreateListViewItem($muell[0] & "|" & $str[0] & "|" & $mehr & ($seiten + 1) * 24, $ListView1)
EndIf
EndIf
EndFunc ;==>zwischenablage
Func ende()
InetGet("")
GUICtrlSetState($Start, $GUI_ENABLE)
GUICtrlSetData($Label1, "")
GUICtrlSetData($Progress1, 0)
GUICtrlSetState($Stop, $GUI_DISABLE)
AdlibDisable()
GUICtrlSetData($Progress1, 0)
EndFunc ;==>ende
Für alle die Imagefap nicht kennen, einfach in dem Inputfeld eine 6-stellige Zahl bis 780000 eingeben.
Das Problem ist folgendes:
Je nach dem wie die Imagefap-Server ausgelastet sind, kann die Anfrage
"http://images1.imagefap.com/full/getimg.php?img=" + Bildname.jpg auch mal unbeantwortet bleiben.
D.h. die Inetget Funktion hängt sich auf und der im Hintergrund laufende Prozess lässt sich scheinbar nur durch einen Neustart des Rechners wieder reseten.
Die Prozessorauslastung ist in der Laufzeit des Programmes bei 100%.
Inetget("abort") bzw. Inetget("") haben keine einfluss auf den Hintergrundprozess von inetget.mfg
Edit BugFix: Bitte bei längeren Code-Passagen immer Spoiler setzen.