|
Post by alexfish on Oct 24, 2022 4:49:24 GMT 1
Finally
OPTION PARSE FALSE
PRAGMA INCLUDE <libsoup/soup.h> PRAGMA INCLUDE <glib/gstdio.h> PRAGMA OPTIONS `pkg-config --cflags libsoup-2.4` PRAGMA LDFLAGS `pkg-config --libs libsoup-2.4`
SUB SOUP2FILE(STRING MODE$,STRING URL$,STRING destination$) LOCAL session TYPE SoupSession * LOCAL msg TYPE SoupMessage * session = soup_session_new() msg = soup_message_new (MODE$, URL$) soup_session_send_message (session, msg) LOCAL pFile TYPE FILE* pFile = fopen (destination$, "wb") fwrite(msg->response_body->data,1,msg->response_body->length, pFile) fclose(pFile) g_object_unref(msg) END SUB
HOME$ = GETENVIRON$("HOME") dest$ = HOME$ & "/test.png" SOUP2FILE ("GET", "http://www.basic-converter.org/linux.png",dest$)
PRINT "DONE"
Whole site
dest$ = HOME$ & "/test.html" SOUP2FILE ("GET", "https://www.basic-converter.org",dest$)
BR Alex
|
|
|
Post by vovchik on Oct 24, 2022 12:38:08 GMT 1
Dear Alex,
It works like a charm - so many thanks....
With kind regards, vovchik
|
|
|
Post by alexfish on Oct 24, 2022 22:26:24 GMT 1
Hi vovchik Thank you for the kind words To All for Reference ,one should install libsoup docs if have libsoup for a howto then use docs libsoup2.4-doc BR Alex Attachments:
|
|
|
Post by vovchik on Oct 24, 2022 23:03:57 GMT 1
Dear Alex, Thanks for the docs link. I enjoy seeing dillo in action, too. With kind regards, vovchik
|
|
|
Post by alexfish on Dec 15, 2022 4:22:40 GMT 1
Hi All
Setting USER_AGENT
SUB SOUP2FILE(STRING MODE$,STRING URL$,STRING destination$) LOCAL session TYPE SoupSession * LOCAL msg TYPE SoupMessage * session = soup_session_new() g_object_set(session,"user-agent","libsoup-2.4",NULL) msg = soup_message_new (MODE$, URL$) soup_session_send_message (session, msg) LOCAL pFile TYPE FILE*
pFile = fopen (destination$, "wb") IF pFile THEN fwrite(msg->response_body->data,1,msg->response_body->length, pFile) fclose(pFile) g_object_unref(msg) ELSE PRINT "NoWrite£" g_object_unref(msg) END IF
END SUB
BR Alex
|
|
|
Post by alexfish on May 23, 2023 15:20:58 GMT 1
Hi All
This code was intended for hug imager so to soupget.bac it is used as stand alone app hence is call much the same as terminal wget ,curl
retrieve images as well
BR Alex
/* soupget.bac TODO READ THIS `pkg-config --cflags --libs libsoup-2.4` file sourcs dest if not destiontion default save = HOME/index.halm end if alexfish @ basic-converter-forum - https://basic-converter.proboards.com/ */ REM ------------------------------------------------------------------------------------------------------------- /* The MIT License
Copyright (c) 2009-2023 Peter van Eerten
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
REM ----------------------------------------------------------------------------------------------------------------------- OPTION PARSE FALSE REM ----------------------------------------------------------------------------------------------------------------------- PRAGMA INCLUDE <libsoup/soup.h> PRAGMA INCLUDE <glib/gstdio.h> PRAGMA OPTIONS `pkg-config --cflags libsoup-2.4` PRAGMA LDFLAGS `pkg-config --libs libsoup-2.4` HOME$= GETENVIRON$("HOME") REM -----------------------------------------------------------------------------------------------------------------------
help$ = "help" & NL$ & NL$ & "Print this help" & NL$ & "http://source destination.html" & NL$ & "if not destination" & NL$ & "default save = " \ & HOME$ & "/index.html"
REM ----------------------------------------------------------------------------------------------------------------------- SUB SOUP2FILE(STRING MODE$,STRING URL$,STRING destination$) LOCAL session TYPE SoupSession * LOCAL msg TYPE SoupMessage * session = soup_session_new() g_object_set(session,"user-agent","libsoup-2.4",NULL) msg = soup_message_new (MODE$, URL$) soup_session_send_message (session, msg) LOCAL pFile TYPE FILE*
pFile = fopen (destination$, "wb") IF pFile THEN fwrite(msg->response_body->data,1,msg->response_body->length, pFile) fclose(pFile) g_object_unref(msg) PRINT "saved as ", dest$ ELSE PRINT "Data Error" g_object_unref(msg) END IF
END SUB REM ----------------------------------------------------------------------------------------------------------------------- LOCAL check$
IF argc =1 THEN PRINT ERROR PRINT "Error: No Args" PRINT PRINT help$ END ENDIF
A$ = argv[1] IF A$ = "help" THEN
PRINT help$ END END IF
check$ = LEFT$(A$,4) IF check$ != "http" THEN PRINT A$ , " Not http" PRINT PRINT help$ END END IF
HOME$ = GETENVIRON$("HOME") dest$ = HOME$ & "/index.html" IF argc = 3 THEN dest$ = argv[2] END IF SOUP2FILE ("GET",A$,dest$)
REM -------- END ----------------------------------------------------------------------------------------------------------
NEXT POST Will be My Youtube Parser : was also intended for same
|
|
|
Post by alexfish on May 23, 2023 15:28:45 GMT 1
The Youtube Parser READ read all esp The SUB get this cmd$ = "/home/pi/HUG352/soupget https://www.youtube.com/results?search_query=" & search$ & CHR$(32) & HOME$ & "/you5.html"
need your HOME$ @ ' /home/pi/HUG352' :: that points to your soupgetas regards the arguments in soupget.bac Have Fun + BR Alex 'youtube.bac html parser INCLUDE "hug.bac"
HOME$= GETENVIRON$("HOME")
SUB get
search$ = CHOP$(GRAB$(ent)) search$=REPLACE$(search$," ","+") LOCAL html TYPE STRING LOCAL res$ cmd$ = "/home/pi/HUG352/soupget https://www.youtube.com/results?search_query=" & search$ & CHR$(32) & HOME$ & "/you5.html"
res$ = EXEC$(cmd$) TEXT(ed, res$ & NL$)
html$ = LOAD$(HOME$ & "/you5.html")
A$ = html$ A$ = REPLACE$(A$,"</div>","</div>" & NL$) A$ = REPLACE$(A$,"<div>","<div>" & NL$) A$ = REPLACE$(A$,"}","}" & NL$) A$ = REPLACE$(A$,"{", NL$ & "}") A$ = REPLACE$(A$,"<", NL$ & "<") A$ = REPLACE$(A$,"</script>","</script>" & NL$)
SPLIT A$ BY NL$ TO arg$ SIZE dim FOR t = 0 TO dim -1
view$ = CHOP$(arg$[t]) view2$ = CHOP$(arg$[t]) IF LEN(view$) > 1 AND LEN(view$) < 200 THEN view$ = REPLACE$(view$,CHR$(34),"") view$ = REPLACE$(view$,"{"," ") view$ = REPLACE$(view$,"}"," ") IF LEFT$(view$,1) = "," THEN view$ = REPLACE$(view$,","," ") END IF IF INSTR(view$,"label:") THEN view$ = REPLACE$(view$,"label:","") view$ = NL$ & "↠ " & CHOP$(view$) END IF IF INSTR(view$,"watch?v=") OR INSTR(view$,"view") THEN IF INSTR(view$,"watch?v=") THEN view$ = UNESCAPE$(view$) view$ = MID$(view$,1,INSTR(view$,"&")-1)
IF INSTR(view$,"/watch?v=") THEN view$ = REPLACE$(view$," url:","") view$ = REPLACE$(view$,"/watch?v=",NL$ & " ↠ https://youtube.com/watch?v=") END IF
TEXT(ed,view$ & NL$) ELSE TEXT(ed,view$ & NL$) END IF
END IF
END IF NEXT
END SUB
SUB Clear TEXT(ed,"") END SUB
win = WINDOW("YouTubed",906,606) ed = EDIT(900,568) ATTACH(win,ed,3,33)
ent = ENTRY("music",200,25) ATTACH(win,ent,3,3) CALLBACK(ent,get)
but = BUTTON("Clear",100,25) ATTACH(win,but,210,3) CALLBACK(but,Clear)
DISPLAY
Time wise On pi4 half a second UPDATED View SeePick Attachments:
|
|