#include <Json.au3>
DirCreate("Download")
HotKeySet('{Esc}', '_Exit')
InetGet("https://agdl.ru/jsonGoods.py?id=New",@ScriptDir & "\1.json",1)
$Json = FileRead(FileOpen(@ScriptDir & "\1.json"))
$Json = Json_Decode($Json)
$Count = UBound(Json_ObjGet($json, 'goods'))
For $i = 0 To $Count - 1
$Id = Json_Get($json, '[goods]['&$i&'][Id]')
$Name = Json_Get($json, '[goods]['&$i&'][T]')
;MsgBox(0,$Id,$Name)
InetGet("https://agdl.ru/jsonWO.py?id="&$Id,@ScriptDir & "\2.json",1)
$JsonPic = FileRead(FileOpen(@ScriptDir & "\2.json"))
$JsonPic = Json_Decode($JsonPic)
$CountPic = UBound(Json_ObjGet($JsonPic, 'images'))
For $p = 0 To $CountPic - 1
$Pic = Json_Get($JsonPic, '[images]['&$p&']')
;ConsoleWrite($Id&" - " & $Name & ":"& "https://agdl.ru/"&$Pic & @CRLF)
;MsgBox(0,"","https://agdl.ru/"&$Pic)
;ShellExecute("https://agdl.ru/"&$Pic)
DirCreate(@ScriptDir & "\Download\" & $Id)
InetGet("https://agdl.ru/"&$Pic, @ScriptDir & "\Download\" & $Id & "\" & _GetValidFileName($Pic),1)
sleep(100)
Next
Next
Func _Exit()
Exit
EndFunc
Func _GetValidFileName($sString, $sPattern = '[*?\\/|:<>"]', $sReplace = '_')
If StringStripWS($sString, 8) = '' Then
Return $sString
EndIf
If StringLen($sString) > 200 Then
$sString = StringLeft($sString, 98) & '...' & StringRight($sString, 99)
EndIf
$sString = StringRegExpReplace($sString, $sPattern, $sReplace)
Return SetExtended(@extended, StringRegExpReplace($sString, '(' & $sReplace & '+)', $sReplace))
EndFunc