Hi,

This patch displays the expected total download size of files when called with 
--spider. Its quite useful if you have a list of links (eg: wget --spider -i 
<file>) to be dowloaded and would like to know the total size. Please let me 
know of any changes/comments etc.  

Thanks,
Rohit
From 4636973b9efea5267a388f2ad821e5ecdd93d79d Mon Sep 17 00:00:00 2001
From: Rohit Mathulla <[email protected]>
Date: Sat, 5 Apr 2014 05:40:51 +1100
Subject: [PATCH] Print expected total download size in spider mode

---
 src/http.c |    1 +
 src/http.h |    1 +
 src/main.c |    4 ++++
 3 files changed, 6 insertions(+)

diff --git a/src/http.c b/src/http.c
index 8bba70d..aedce56 100644
--- a/src/http.c
+++ b/src/http.c
@@ -2787,6 +2787,7 @@ read_header:
           if (contlen != -1)
             {
               logputs (LOG_VERBOSE, number_to_static_string (contlen + contrange));
+              total_download_size += contlen;
               if (contlen + contrange >= 1024)
                 logprintf (LOG_VERBOSE, " (%s)",
                            human_readable (contlen + contrange));
diff --git a/src/http.h b/src/http.h
index 21f1ed5..4b83f16 100644
--- a/src/http.h
+++ b/src/http.h
@@ -44,6 +44,7 @@ typedef struct {
   const char *b, *e;
 } param_token;
 bool extract_param (const char **, param_token *, param_token *, char, bool *);
+SUM_SIZE_INT total_download_size;
 
 
 #endif /* HTTP_H */
diff --git a/src/main.c b/src/main.c
index 39fcff4..039d3f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -988,6 +988,7 @@ main (int argc, char **argv)
   bool append_to_log = false;
 
   total_downloaded_bytes = 0;
+  total_download_size = 0;
 
   program_name = argv[0];
 
@@ -1722,6 +1723,9 @@ outputting to a regular file.\n"));
                    human_readable (opt.quota));
     }
 
+  if (total_downloaded_bytes == 0 && total_download_size != 0)
+    logprintf (LOG_NOTQUIET, _("Total download size: %s\n"), human_readable (total_download_size));
+
   if (opt.cookies_output)
     save_cookies ();
 
-- 
1.7.9.5

Reply via email to