help for replace curl to hurl

Find quick help here to get you started with Hollywood
Post Reply
TearsOfMe
Posts: 15
Joined: Fri Apr 24, 2020 2:15 pm

help for replace curl to hurl

Post 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
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: help for replace curl to hurl

Post 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"})
TearsOfMe
Posts: 15
Joined: Fri Apr 24, 2020 2:15 pm

Re: help for replace curl to hurl

Post 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)
TearsOfMe
Posts: 15
Joined: Fri Apr 24, 2020 2:15 pm

Re: help for replace curl to hurl

Post 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?
TearsOfMe
Posts: 15
Joined: Fri Apr 24, 2020 2:15 pm

Re: help for replace curl to hurl

Post 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
TearsOfMe
Posts: 15
Joined: Fri Apr 24, 2020 2:15 pm

Re: help for replace curl to hurl

Post 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
TearsOfMe
Posts: 15
Joined: Fri Apr 24, 2020 2:15 pm

Re: help for replace curl to hurl

Post by TearsOfMe »

Inserting

Code: Select all

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