WeeChat DevCenter

URL transfer in API

URL transfer has been added in API for plugins and scripts (using libcurl).

A new function has been added: "hook_process_hashtable". Behaviour is the same as "hook_process", but with an extra "options" (a hashtable). To download URL content (html page or file), the syntax is (example is python):

weechat.hook_process_hashtable('url:http://weechat.org/download/',
                               { 'file_out': '/tmp/url.txt' },
                               10000, 'my_process_cb', '')

This code will download URL in file "/tmp/url.txt" and call function "my_process_cb" when done, with return code:

  • 0: transfer ok
  • 1: invalid URL
  • 2: transfer error
  • 3: not enough memory
  • 4: error with a file

It is possible to download URL without any option, then the output is on standard output of process (received as "out" in callback, possibly in many chunks, depending on page size):

weechat.hook_process('url:http://weechat.org/download/', 10000, 'my_process_cb', '')