Interactive Script for WGET?

Discuss Programming

Interactive Script for WGET?

Postby agent007 » Thu May 01, 2003 11:20 pm

hi all,

Wget get is a g8 tool, but it can be quite a hassle at times to remember all the parameters. So, I was thinking of creating an interactive script of some sort. Something like this:-

---------------------------
Wget Downloader
---------------------------
1) Wget single file
2) Wget MIRROR a site
3) Wget all pdf's

Enter ur selection to continue: 3

$wget -r -l1 --no-parent -A.pdf (http://www.someserver.com/dir )



The script will show the first three options (functions for each option will have to be defined) and then ask for the number of the option that is to be processed. After the number is inputed (in this case option 3), the first part will be automatically put into the prompt and all that is to be done is paste the URL part...(which I've shown in brackets)

It would be really cool to get this thing working! What do u think guys? Is anyone using something like this already?

thanks,
007
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby X11 » Tue May 13, 2003 4:12 am

I could write one in c with curses.

If you already know the command line commands to whatever you could easily modify my "cmenu" that i wrote download it from my website
http://users.tpg.com.au/irulz0r/warez.html
X11
guru
guru
 
Posts: 674
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia

Postby agent007 » Wed May 14, 2003 1:13 am

hello X11,

Thanks! This is just the thing I was searching for. I've made a couple of changes. However, once selected, lets say option "2", wget -2 should be put into the prompt so that the URL can be pasted....Can that be done? What do u think?

thanks.

void menu()
{
char option;
cprintw("Wget Interactive Downloading!",3);

mvprintw(5,0,"Please select the type of download\n\n
Num Description\n");
printw("1 Download a normal file\n");
printw("2 Mirror Website\n");
printw("3 Mirror Website (2 Levels)\n");
printw("4 Mirror Website (3 Levels)\n");
printw("5 Mirror Website (4 Levels)\n");
printw("6 Download files, specified by *.ext\n");
printw("7 Download files, specified by by *.ext (alternative method)\n");
printw("8 Continue unfinished download\n");
printw("x Exit\n");
option = getch();

switch (option)
{
case '1':
system("wget");
break;

case '2':
system("wget -r");
break;

case '3':
system("wget -r -l2");
break;

case '4':
system("wget -r -l3");
break;

case '5':
system("wget -r -l4");
break;

case '6':
system("wget");
break;

case '7':
system("wget -r -l1 --no-parent -A.gif");
break;

case '8':
system("wget -nc -r");
break;

case 'x':
reallyexit();
break;
}


agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby X11 » Wed May 14, 2003 3:49 am

This should work (not sure in other words)
Code: Select all
#include <stdlib.h>
#include <curses.h>
#include <string.h>

void menu()
{
char option;
char url[512];
char command[512]="wget";
cprintw("Wget Interactive Downloading!",3);

mvprintw(5,0,"Please select the type of download\n\n
Num Description\n");
printw("1 Download a normal file\n");
printw("2 Mirror Website\n");
printw("3 Mirror Website (2 Levels)\n");
printw("4 Mirror Website (3 Levels)\n");
printw("5 Mirror Website (4 Levels)\n");
printw("6 Download files, specified by *.ext\n");
printw("7 Download files, specified by by *.ext (alternative method)\n");
printw("8 Continue unfinished download\n");
printw("x Exit\n");
option = getch();

scanw(url);
switch (option)
{
case '1':
strcat(command,url);
system(command);
break;

case '2':
strcat(command," -r");
system(command);
break;

case '3':
strcat(command," -r -l2");
strcat(command,url);
system(command);
break;

case '4':
strcat(command," -r -l3");
break;

case '5':
strcat(command,url);
strcat(command," -r -l4");
break;

case '6':
strcat(command,url);
system(command);
break;

case '7':
strcat(command,url);
strcat(command,"-r -l1 --no-parent -A.gif");
break;

case '8':
strcat(command,url);
strcat(command,"wget -nc -r");
break;

case 'x':
reallyexit();
break;
}

X11
guru
guru
 
Posts: 674
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia

Postby agent007 » Wed May 14, 2003 5:13 am

No luck compiling..Could it be because of the changed header file? Instead of stdlib.h the previous one used ncursors.h.... Heres the o/p:-


gcc -o new new1.c -lncurses
new1.c: In function `reallyexit':
new1.c:24: too few arguments to function `exit'
new1.c:39:14: warning: multi-line string literals are deprecated
new1.c: In function `main':
new1.c:105: warning: return type of `main' is not `int'




#include <stdlib.h>
#include <curses.h>
#include <string.h>

void cprintw(char text[80],int line)
{
int row;
int col;
getmaxyx(stdscr,row,col);
mvprintw(line,(col-strlen(text))/2,text);
}

void reallyexit()
{
char option;
printw("Are you sure you want to exit Y/N [n]\n");
option = getch();

switch(option)
{
case 'y':
case 'Y':
endwin();
exit();
break;
}
}


void menu()
{
char option;
char url[512];
char command[512]="wget";
cprintw("Wget Interactive Download Script",3);

mvprintw(5,0,"Please select the type of download\n\n
Num Description\n");
printw("1 Download a normal file\n");
printw("2 Mirror Website\n");
printw("3 Mirror Website (2 Levels)\n");
printw("4 Mirror Website (3 Levels)\n");
printw("5 Mirror Website (4 Levels)\n");
printw("6 Download files, specified by *.ext\n");
printw("7 Download files, specified by by *.ext (alternative method)\n");
printw("8 Continue unfinished download\n");
printw("x Exit\n");
option = getch();

scanw(url);
switch (option)
{
case '1':
strcat(command,url);
system(command);
break;

case '2':
strcat(command," -r");
system(command);
break;

case '3':
strcat(command," -r -l2");
strcat(command,url);
system(command);
break;

case '4':
strcat(command," -r -l3");
break;

case '5':
strcat(command,url);
strcat(command," -r -l4");
break;

case '6':
strcat(command,url);
system(command);
break;

case '7':
strcat(command,url);
strcat(command,"-r -l1 --no-parent -A.gif");
break;

case '8':
strcat(command,url);
strcat(command,"wget -nc -r");
break;

case 'x':
reallyexit();
break;
}
printw("press any key to continue");
clear();

}

void main()
{
WINDOW *mywindow;
mywindow = initscr();
noecho();
printw("Press any key to continue");
getch();
clear();
while(1)
menu();
}

agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby X11 » Sat May 17, 2003 2:43 am

It was a dirty hack, its most likly missing some things.
X11
guru
guru
 
Posts: 674
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests