Page 1 of 1

help for replace curl to hurl

Posted: Mon Jan 17, 2022 11:21 am
by TearsOfMe
Hello.
I am not good anough to understand the docs from hurl.
Is it possible to replace this curl download with the hurl plugin?

Code: Select all

fileattr$="-s -f -u \"demo:ce544b6ea52a5621fb9d55f8b542d14d\"  -o \"t:Seite"..page.."-"..sub..".jpg\" -F \"output_format=jpg\" -F \"url=https://www.ard-text.de/index.php?page="..page.."&sub="..sub.."\" https://api.pdfcrowd.com/convert/20.10/"
page is a number, like 100.

Thanks
Tears

Re: help for replace curl to hurl

Posted: Sun Jan 23, 2022 2:00 pm
by airsoftsoftwair
Actually, with Hollywood 9 and hURL 1.2 it's not even necessary to use hURL's API directly but you can just use DownloadFile() and it will be redirected through hURL. Have you tried something like this?

Code: Select all

@REQUIRE "hurl"
url$ = "demo:ce544b6ea52a5621fb9d55f8b542d14d@https://www.ard-text.de/index.php?page="..page.."&sub="..sub.."\" https://api.pdfcrowd.com/convert/20.10/"
DownloadFile(url$, {File = "test", Adapter = "hurl"})

Re: help for replace curl to hurl

Posted: Sun Jan 23, 2022 3:27 pm
by TearsOfMe
Ah thank you.
In the meanwhile i have come self to a solution, but will try yours also.

Here is mine:

Code: Select all

Function p_WriteData(data$)
	WriteBytes(1, data$)
EndFunction

Function p_downloadpage()

OpenFile(1, "ram:test.png", #MODE_WRITE)
e = hurl.Easy({URL = "http://api.pdfcrowd.com/convert/20.10/", WriteFunction = p_WriteData})
f = hurl.Form()
e:SetOpt_UserName("demo")
e:SetOpt_Password("ce544b6ea52a5621fb9d55f8b542d14d")
f:AddContent("output_format", "png")
f:AddContent("use_print_media", "true")
f:AddContent("screenshot_height", "600")
f:AddContent("screenshot_width", "500")
f:AddContent("url", "http://www.ard-text.de/index.php?page=100")
e:SetOpt_HTTPPost(f)
;e:SetOpt_WriteFunction(p_Dump)
e:Perform()
e:Close()
CloseFile(1)

Re: help for replace curl to hurl

Posted: Sun Jan 23, 2022 4:15 pm
by TearsOfMe
Try your idea but get it not to work.
My solution works but halt the programm while download the file.
So the busybar not working/showing that i use to show that the program loads.

Is there a way to asynchron the download?

Re: help for replace curl to hurl

Posted: Sun Jan 23, 2022 6:34 pm
by TearsOfMe
Okay i found

Code: Select all

easy:SetOpt_ProgressFunction(progress_callback[, userdata])
that should do what i need, but now i dont understand how this work...pff

Re: help for replace curl to hurl

Posted: Mon Jan 24, 2022 11:32 am
by TearsOfMe
Here is my actual code.
the call is okay but will only be eroded once, so no showing of the busybar.
How can i do this right?

Code: Select all

Function p_Progress(bytesToRecieve, currentBytesReceived, bytesToSend, currentBytesSent, meinParameter)
	debugprint("callprogress")
	moai.DoMethod("busybar", "move")
EndFunction

Function p_loader()
file$="t:Seite"..page..".png"
if subpage=1 then file$="t:Seite"..page.."-"..sub..".png"
	OpenFile(1, file$, #MODE_WRITE)
		e = hurl.Easy({URL = "http://api.pdfcrowd.com/convert/20.10/", WriteFunction = p_WriteData})
		f = hurl.Form()
		e:SetOpt_UserName("demo")
		e:SetOpt_Password("ce544b6ea52a5621fb9d55f8b542d14d")
		f:AddContent("output_format", "png")
		f:AddContent("use_print_media", "true")
		f:AddContent("screenshot_height", "600")
		f:AddContent("screenshot_width", "500")
		f:AddContent("url", url$)
		e:SetOpt_HTTPPost(f)
	e:SetOpt_ProgressFunction(p_Progress,p_Progress(bytesToRecieve, currentBytesReceived, bytesToSend, currentBytesSent))
		e:Perform()
		e:Close()
	CloseFile(1)
 p_loadbrush()
EndFunction

Re: help for replace curl to hurl

Posted: Mon Jan 24, 2022 12:47 pm
by TearsOfMe
Inserting

Code: Select all

e:SetOpt_NoProgress(0)
solved my problem. :D