diff --git a/Makefile b/Makefile index 3787dd1..a7da963 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ prefix=/usr/local bindir=$(prefix)${exec_prefix}/bin DESTDIR= FLAGS=$(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBSSL=1 -DHAVE_LIBCRYPTO=1 -OBJ=containerfiles.o outputfiles.o common.o ehow.o ign.o youtube.o servicetypes.o extract_text.o download.o display.o selectformat.o +OBJ=common.o settings.o containerfiles.o outputfiles.o servicetypes.o extract_text.o download.o display.o selectformat.o ehow.o ign.o youtube.o all: $(OBJ) @cd libUseful-2.6; $(MAKE) @@ -16,15 +16,18 @@ all: $(OBJ) clean: @rm -f movgrab *.o libUseful-2.6/*.o libUseful-2.6/*.a libUseful-2.6/*.so +common.o: common.c common.h + $(CC) $(FLAGS) -c common.c + +settings.o: settings.c settings.h + $(CC) $(FLAGS) -c settings.c + containerfiles.o: containerfiles.c containerfiles.h $(CC) $(FLAGS) -c containerfiles.c outputfiles.o: outputfiles.c outputfiles.h $(CC) $(FLAGS) -c outputfiles.c -common.o: common.c common.h - $(CC) $(FLAGS) -c common.c - ehow.o: ehow.c ehow.h $(CC) $(FLAGS) -c ehow.c diff --git a/Makefile.in b/Makefile.in index 0a1ed13..e99ff5d 100755 --- a/Makefile.in +++ b/Makefile.in @@ -7,7 +7,7 @@ prefix=@prefix@ bindir=$(prefix)@bindir@ DESTDIR= FLAGS=$(CFLAGS) @DEFS@ -OBJ=containerfiles.o outputfiles.o common.o ehow.o ign.o youtube.o servicetypes.o extract_text.o download.o display.o selectformat.o +OBJ=common.o settings.o containerfiles.o outputfiles.o servicetypes.o extract_text.o download.o display.o selectformat.o ehow.o ign.o youtube.o all: $(OBJ) @cd libUseful-2.6; $(MAKE) @@ -16,15 +16,18 @@ all: $(OBJ) clean: @rm -f movgrab *.o libUseful-2.6/*.o libUseful-2.6/*.a libUseful-2.6/*.so +common.o: common.c common.h + $(CC) $(FLAGS) -c common.c + +settings.o: settings.c settings.h + $(CC) $(FLAGS) -c settings.c + containerfiles.o: containerfiles.c containerfiles.h $(CC) $(FLAGS) -c containerfiles.c outputfiles.o: outputfiles.c outputfiles.h $(CC) $(FLAGS) -c outputfiles.c -common.o: common.c common.h - $(CC) $(FLAGS) -c common.c - ehow.o: ehow.c ehow.h $(CC) $(FLAGS) -c ehow.c diff --git a/common.c b/common.c index 63ff64c..0f1b643 100755 --- a/common.c +++ b/common.c @@ -4,6 +4,14 @@ char *FileTypes[]={".flv",".mp3",".mp4",".mov",".wma",".m4a",".m4v",".wmv",".web char *ItemSelectionArg=NULL; char *NowPlayingFile=NULL; char *FormatPreference=NULL; +char *Username=NULL, *Password=NULL; +char *Proxy=NULL; +char *ProgName=NULL, *CmdLine=NULL, *UserAgent=NULL; +int STREAMTimeout=3000; + + + + char *FileTypeFromURL(char *URL) { diff --git a/common.h b/common.h index b7f6803..b6f6f86 100755 --- a/common.h +++ b/common.h @@ -2,7 +2,7 @@ #ifndef MOVGRAB_COMMON #define MOVGRAB_COMMON //This is doable through autoconf, but I'm sick of fighting with it -#define Version "2.1.0" +#define Version "3.0.0" #include "libUseful-2.6/libUseful.h" #include @@ -36,6 +36,10 @@ extern char *FileTypes[]; extern char *ItemSelectionArg; extern char *NowPlayingFile; extern char *FormatPreference; +extern char *Username, *Password; +extern char *Proxy; +extern char *ProgName, *CmdLine, *UserAgent; +extern int STREAMTimeout; char *FileTypeFromURL(char *URL); char *ItemCodeFromFileExtension(char *RetBuf, const char *Default, const char *URL); diff --git a/containerfiles.c b/containerfiles.c index a6aff99..e50a193 100755 --- a/containerfiles.c +++ b/containerfiles.c @@ -129,7 +129,7 @@ Segments=ListCreate(); ptr=strrchr(URL, '/'); if (ptr) { -BasePath=CopyStrLen(BasePath, URL, ptr - URL); + BasePath=CopyStrLen(BasePath, URL, ptr - URL); Line=STREAMReadLine(Line,ManifestCon); while (Line) { diff --git a/libUseful-2.6/config.log b/libUseful-2.6/config.log index 129a539..1315106 100755 --- a/libUseful-2.6/config.log +++ b/libUseful-2.6/config.log @@ -278,7 +278,7 @@ configure:3706: $? = 0 configure:3715: result: yes configure:3731: checking for OpenSSL_add_all_algorithms configure:3731: gcc -o conftest -g -O2 conftest.c -lcrypto -lssl -lc >&5 -/tmp/ccQx0Pjv.o: In function `main': +/tmp/ccmrexWp.o: In function `main': /home/metacosm89/Movgrab/libUseful-2.6/conftest.c:59: undefined reference to `OpenSSL_add_all_algorithms' collect2: error: ld returned 1 exit status configure:3731: $? = 1 @@ -360,7 +360,7 @@ configure:3731: $? = 0 configure:3731: result: yes configure:3731: checking for EVP_rc5_32_12_16_cbc configure:3731: gcc -o conftest -g -O2 conftest.c -lcrypto -lssl -lc >&5 -/tmp/cc6WIzAl.o: In function `main': +/tmp/cc4C2m4g.o: In function `main': /home/metacosm89/Movgrab/libUseful-2.6/conftest.c:62: undefined reference to `EVP_rc5_32_12_16_cbc' collect2: error: ld returned 1 exit status configure:3731: $? = 1 diff --git a/main.c b/main.c index 83b8a67..df7970f 100755 --- a/main.c +++ b/main.c @@ -30,12 +30,8 @@ int Flags=0; -char *ProgName=NULL, *CmdLine=NULL; ListNode *DownloadQueue=NULL; STREAM *StdIn=NULL; -char *Username=NULL, *Password=NULL; -char *Proxy=NULL; -int STREAMTimeout=3000; int Type=TYPE_NONE; int CheckForKeyboardInput() @@ -116,219 +112,6 @@ return(RetVal); -void PrintVersion() -{ -fprintf(stdout,"\nMovgrab: version %s\n",Version); -} - - -void PrintUsage() -{ -int i; - -PrintVersion(); -fprintf(stdout,"Author: Colum Paget\n"); -fprintf(stdout,"Email: colums.projects@gmail.com\n"); -fprintf(stdout,"Blog: http://idratherhack.blogspot.com \n"); -fprintf(stdout,"\n"); -fprintf(stdout,"Usage: movgrab [-t ] -a [:] [-p http://username:password@x.x.x.x:80 ] [-r] [-b] [-x] [-q] [-st ] [-f ] [-v] [-P] [-Pp] [-o ] [+o ] url\n"); -fprintf(stdout," movgrab -test-sites\n"); -fprintf(stdout,"\n'-v' increases verbosity/debug level\n"); -fprintf(stdout,"'-v -v' prints out all webpages encountered\n"); -fprintf(stdout,"'-v -v -v' maximum debugging\n"); -fprintf(stdout,"'-version' Program version\n"); -fprintf(stdout,"'--version' Program version\n"); -fprintf(stdout,"'-T' Test mode, don't do final download\n"); -fprintf(stdout,"'-P ' Player program (e.g. \"mplayer\")\n"); -fprintf(stdout,"'-Pp' Percent download to launch player at (default 25%)\n"); -fprintf(stdout,"'-a' Authentication info in Username:Password format.\n"); -fprintf(stdout,"'-q' QUIET. No progress/informative output.\n"); -fprintf(stdout,"'-b' Background. Fork into background and nohup\n"); -fprintf(stdout,"'-p' address of http/https/sstunnel proxy server in URL format.\n"); -fprintf(stdout,"'-proxy' address of http/https/socks4/socks5/sstunnel proxy server in URL format.\n"); -fprintf(stdout,"'-w' Wait for addresses to be entered on stdin.\n"); -fprintf(stdout,"'-st' Connection inactivity timeout in seconds. Set high for sites that 'throttle'\n"); -fprintf(stdout,"'-tw ' Set max width of item title in progress display (Default 50 chars)\n"); -fprintf(stdout,"'-np ' File to write current title to. Useful as 'now plaing' for internet radio streams\n"); -fprintf(stdout,"'-t' specifies website type.\n"); -fprintf(stdout,"'-r' Resume download (only works when writing a single file, not with +o).\n"); -fprintf(stdout,"'-f' specifies preferred video/audio formats for sites that offer more than one\n"); -fprintf(stdout," example: flv:640x480,flv,mp4,mp3\n"); -fprintf(stdout," Use -T to get a list of formats the site offers\n"); -fprintf(stdout," Use * to mean 'any format' (the default)\n"); -fprintf(stdout," example: flv:640x480,mp4:640x480,*\n"); -fprintf(stdout,"'-o' specifies output file ( '-' for stdout)\n"); -fprintf(stdout,"'+o' add an output file to list of output files ( '-' for stdout)\n"); -fprintf(stdout,"'-x' try to avoid 'family filter' on some sites\n"); -fprintf(stdout,"'-n' For pages with multiple movies (not movie formats, but movies) specifes item selection for download. Argument has the form:\n"); -fprintf(stdout," -n all Download all\n"); -fprintf(stdout," -n 2 Download 2nd item\n"); -fprintf(stdout," -n 2-5 Download 2nd to 5th item\n"); -fprintf(stdout," -n 2- Download from 2nd item onwards\n"); -fprintf(stdout," -n -8 Download from 1st to 8th item\n"); -fprintf(stdout,"-test-sites Test downloading from each supported website"); -fprintf(stdout,"\nThe '-t' argument is optional, Movgrab will try to guess the download type from the provided url.\n\n"); - -fprintf(stdout,"The url should be that of the page that the movie would normally appear on. Movgrab examines the page for embed tags and other information that would normally cause the movie to play on that page.\n"); - -fprintf(stdout,"\nDownload types are:\n"); -for (i=1; DownloadTypes[i] !=NULL; i++) fprintf(stdout,"%-20s %s\n",DownloadTypes[i],DownloadNames[i]); - -fprintf(stdout,"\nThe -proxy argument has the form ::@:. So, for example socks4:192.168.1.1:8080 or socks5:user1:secret@192.168.1.1:5050\n"); - -fprintf(stdout,"\nIf a website is not in the list, try 'movgrab -t generic '\n"); -fprintf(stdout,"\nMovgrab can also be used to stream from internet radio and pipe it into a player. E.g.'\n movgrab -o - -q -proxy ssltunnel://guest:s3cr3t@sshserver:1022 http://schizoid.in/schizoid-psy.pls | mpg123 -\n"); -fprintf(stdout,"\nFeel free to email me and tell me if you've used this software!\n"); - -fprintf(stdout,"\nThanks for bug reports go to: Philip Pi, Mark Gamar, Rich Kcsa, 'Rampant Badger', 'nibbles', 'deeice', Omair Eshkenazi, Matthias B, Ashish Disawal, Timo Juhani Lindfors, Abhisek Sanyal and others.\n"); -fprintf(stdout,"\nSpecial thanks to:\n"); -fprintf(stdout," 'legatvs' for clive (http://clive.sourceforge.net) another downloader into whose code I had to look to figure out how to get youtube and daily motion working again.\n"); -fprintf(stdout," Robert Crowley (http://oldcoder.org/) For all sorts of bug reports and advice.\n"); -} - - -int ParseType(char *Type) -{ -int i, result=TYPE_NONE; - -for (i=0; DownloadTypes[i] !=NULL; i++) -{ - if (strcasecmp(Type,DownloadTypes[i])==0) result=i; -} -return(result); -} - - -void ParseCommandLine(int argc, char *argv[], ListNode *DL_List, int *OverrideType) -{ -int i,j, DebugLevel=0; -char *ptr; - -ProgName=CopyStr(ProgName,argv[0]); -CmdLine=argv[0]; - - -for (i=1; i < argc; i++) -{ - if (strcmp(argv[i],"-p")==0) Proxy=CopyStr(Proxy,argv[++i]); - else if (strcmp(argv[i],"-proxy")==0) Proxy=CopyStr(Proxy,argv[++i]); - else if (strcmp(argv[i],"-a")==0) - { - ptr=GetToken(argv[++i],":",&Username,0); - ptr=GetToken(ptr,":",&Password,0); - } - else if (strcmp(argv[i],"-v")==0) - { - DebugLevel++; - } - else if (strcmp(argv[i],"-o")==0) - { - i++; - AddOutputFile(argv[i], TRUE); - if (strcmp(argv[i],"-")==0) Flags |= FLAG_STDOUT; - } - else if (strcmp(argv[i],"+o")==0) - { - i++; - AddOutputFile(argv[i], FALSE); - if (strcmp(argv[i],"-")==0) Flags |= FLAG_STDOUT; - } - else if (strcmp(argv[i],"-n")==0) - { - ItemSelectionArg=CopyStr(ItemSelectionArg,argv[++i]); - } - else if (strcmp(argv[i],"-t")==0) *OverrideType=ParseType(argv[++i]); - else if (strcmp(argv[i],"-f")==0) FormatPreference=CopyStr(FormatPreference,argv[++i]); - else if (strcmp(argv[i],"-q")==0) Flags |= FLAG_QUIET; - else if (strcmp(argv[i],"-b")==0) Flags |= FLAG_BACKGROUND; - else if (strcmp(argv[i],"-r")==0) Flags |= FLAG_RESUME; - else if (strcmp(argv[i],"-x")==0) Flags |= FLAG_PORN; - else if (strcmp(argv[i],"-T")==0) Flags |= FLAG_TEST; - else if (strcmp(argv[i],"-w")==0) Flags |= FLAG_STDIN; - else if (strcmp(argv[i],"-dt")==0) DisplayTitleWidth=atoi(argv[++i]); - else if (strcmp(argv[i],"-np")==0) NowPlayingFile=CopyStr(NowPlayingFile, argv[++i]); - else if (strcmp(argv[i],"-st")==0) STREAMTimeout=atoi(argv[++i]); - else if (strcmp(argv[i],"-P")==0) Player=CopyStr(Player,argv[++i]); - else if (strcmp(argv[i],"-Pp")==0) PlayerLaunchPercent=atoi(argv[++i]); - else if (strcmp(argv[i],"-?")==0) Flags |= FLAG_PRINT_USAGE; - else if (strcmp(argv[i],"-h")==0) Flags |= FLAG_PRINT_USAGE; - else if (strcmp(argv[i],"-help")==0) Flags |= FLAG_PRINT_USAGE; - else if (strcmp(argv[i],"--help")==0) Flags |= FLAG_PRINT_USAGE; - else if (strcmp(argv[i],"-version")==0) Flags |= FLAG_PRINT_VERSION; - else if (strcmp(argv[i],"--version")==0) Flags |= FLAG_PRINT_VERSION; - else if (strcmp(argv[i],"-test-sites")==0) - { - Flags |= FLAG_TEST_SITES | FLAG_QUIET; - for (j=1; TestLinks[j] !=NULL; j++) - { - if (StrLen(TestLinks[j])) ListAddNamedItem(DL_List,DownloadTypes[j],CopyStr(NULL,TestLinks[j])); - - } - ItemSelectionArg=CopyStr(ItemSelectionArg,"0"); - } - else - { - ListAddItem(DL_List,CopyStr(NULL,argv[i])); - } - -} - - -if (Flags & FLAG_BACKGROUND) -{ -Flags |= FLAG_QUIET; -demonize(); -} - -if (Flags & FLAG_QUIET) DebugLevel=0; - -if (DebugLevel==1) Flags |= FLAG_DEBUG1; -if (DebugLevel==2) Flags |= FLAG_DEBUG2; -if (DebugLevel > 2) Flags |= FLAG_DEBUG3; -} - -void CheckSettings() -{ -char *Token=NULL, *ptr; -int i; - -if ((! isatty(1)) && (! (Flags & FLAG_STDOUT))) -{ -fprintf(stderr,"\nWARNING: Stdout does not seem to be a terminal, so it could be a pipe to another program. But you've not used '-o -' or '+o -' to redirect output into a pipe. Hence output will be written to a file. If you're piping into a player app, and there's no sound/video, then you need to add '-o -'\n\n"); -} - -DestroyString(Token); -} - - -void ParseEnvironmentVariables() -{ -char *Tempstr=NULL; - -Tempstr=CopyStr(Tempstr,getenv("http_proxy")); -if (StrLen(Tempstr)) -{ - if ( - (strncasecmp(Tempstr,"http:",5) !=0) && - (strncasecmp(Tempstr,"https:",6) !=0) - ) Proxy=MCopyStr(Proxy,"http:",Tempstr,NULL); - else Proxy=CopyStr(Proxy,Tempstr); -} -else -{ - Tempstr=CopyStr(Tempstr,getenv("ssh_tunnel")); - if (StrLen(Tempstr)) - { - if (strncasecmp(Tempstr,"sshtunnel:",10)==0) Proxy=CopyStr(Proxy,Tempstr); - else if (strncasecmp(Tempstr,"ssh:",4)==0) Proxy=MCopyStr(Proxy,"sshtunnel:",Tempstr+4,NULL); - else Proxy=MCopyStr(Proxy,"sshtunnel:",Tempstr,NULL); - } -} - -DestroyString(Tempstr); -} - - main(int argc, char *argv[]) { @@ -341,10 +124,9 @@ int result; StdIn=STREAMFromFD(0); STREAMSetTimeout(StdIn,0); ParseEnvironmentVariables(); +UserAgent=MCopyStr(UserAgent,"Movgrab ",Version,NULL); DownloadQueue=ListCreate(); -Tempstr=MCopyStr(Tempstr,"Movgrab ",Version,NULL); -HTTPSetUserAgent(Tempstr); FormatPreference=CopyStr(FormatPreference,"mp4,flv,webm,m4v,mov,mpg,mpeg,wmv,avi,3gp,mp3,m4a,wma,m3u8,m3u8-stream,reference"); AddOutputFile("", TRUE); @@ -359,6 +141,7 @@ if (StrLen(Proxy)) } } +HTTPSetUserAgent(UserAgent); if (Flags & FLAG_PRINT_USAGE) PrintUsage(); diff --git a/settings.c b/settings.c new file mode 100644 index 0000000..69c27cf --- /dev/null +++ b/settings.c @@ -0,0 +1,218 @@ +#include "settings.h" +#include "servicetypes.h" +#include "display.h" +#include "download.h" + +void PrintVersion() +{ +fprintf(stdout,"\nMovgrab: version %s\n",Version); +} + + +void PrintUsage() +{ +int i; + +PrintVersion(); +fprintf(stdout,"Author: Colum Paget\n"); +fprintf(stdout,"Email: colums.projects@gmail.com\n"); +fprintf(stdout,"\n"); +fprintf(stdout,"Usage: movgrab [-t ] -a [:] [-p ://:@: ] [-r] [-b] [-x] [-q] [-st ] [-f ] [-v] [-P] [-Pp] [-U ] [-o ] [+o ] url\n"); +fprintf(stdout," movgrab -test-sites\n"); +fprintf(stdout,"\n'-v' increases verbosity/debug level\n"); +fprintf(stdout,"'-v -v' prints out all webpages encountered\n"); +fprintf(stdout,"'-v -v -v' maximum debugging\n"); +fprintf(stdout,"'-version' Program version\n"); +fprintf(stdout,"'--version' Program version\n"); +fprintf(stdout,"'-T' Test mode, don't do final download\n"); +fprintf(stdout,"'-P ' Player program (e.g. \"mplayer\")\n"); +fprintf(stdout,"'-Pp' Percent download to launch player at (default 25%)\n"); +fprintf(stdout,"'-U' User-agent string\n"); +fprintf(stdout,"'-a' Authentication info in Username:Password format.\n"); +fprintf(stdout,"'-q' QUIET. No progress/informative output.\n"); +fprintf(stdout,"'-b' Background. Fork into background and nohup\n"); +fprintf(stdout,"'-p' address of http/https/socks4/socks5/sshtunnel proxy server in URL format.\n"); +fprintf(stdout,"'-proxy' address of http/https/socks4/socks5/sstunnel proxy server in URL format.\n"); +fprintf(stdout,"'-w' Wait for addresses to be entered on stdin.\n"); +fprintf(stdout,"'-st' Connection inactivity timeout in seconds. Set high for sites that 'throttle'\n"); +fprintf(stdout,"'-tw ' Set max width of item title in progress display (Default 50 chars)\n"); +fprintf(stdout,"'-np ' File to write current title to. Useful as 'now playing' for internet radio streams\n"); +fprintf(stdout,"'-t' specifies website type.\n"); +fprintf(stdout,"'-r' Resume download (only works when writing a single file, not with +o).\n"); +fprintf(stdout,"'-f' specifies preferred video/audio formats for sites that offer more than one\n"); +fprintf(stdout," example: flv:640x480,flv,mp4,mp3\n"); +fprintf(stdout," Use -T to get a list of formats the site offers\n"); +fprintf(stdout," Use * to mean 'any format' (the default)\n"); +fprintf(stdout," example: flv:640x480,mp4:640x480,*\n"); +fprintf(stdout,"'-o' specifies output file ( '-' for stdout)\n"); +fprintf(stdout,"'+o' add an output file to list of output files ( '-' for stdout)\n"); +fprintf(stdout,"'-x' try to avoid 'family filter' on some sites\n"); +fprintf(stdout,"'-n' For pages with multiple movies (not movie formats, but movies) specifes item selection for download. Argument has the form:\n"); +fprintf(stdout," -n all Download all\n"); +fprintf(stdout," -n 2 Download 2nd item\n"); +fprintf(stdout," -n 2-5 Download 2nd to 5th item\n"); +fprintf(stdout," -n 2- Download from 2nd item onwards\n"); +fprintf(stdout," -n -8 Download from 1st to 8th item\n"); +fprintf(stdout,"-test-sites Test downloading from each supported website"); +fprintf(stdout,"\nThe '-t' argument is optional, Movgrab will try to guess the download type from the provided url.\n\n"); + +fprintf(stdout,"The url should be that of the page that the movie would normally appear on. Movgrab examines the page for embed tags and other information that would normally cause the movie to play on that page.\n"); + +fprintf(stdout,"\nDownload types are:\n"); +for (i=1; DownloadTypes[i] !=NULL; i++) fprintf(stdout,"%-20s %s\n",DownloadTypes[i],DownloadNames[i]); + +fprintf(stdout,"\nThe -proxy argument has the form ::@:. So, for example socks4:192.168.1.1:8080 or socks5:user1:secret@192.168.1.1:5050\n"); + +fprintf(stdout,"\nIf a website is not in the list, try 'movgrab -t generic '\n"); +fprintf(stdout,"\nMovgrab can also be used to stream from internet radio and pipe it into a player. E.g.'\n movgrab -o - -q -proxy ssltunnel://guest:s3cr3t@sshserver:1022 http://schizoid.in/schizoid-psy.pls | mpg123 -\n"); +fprintf(stdout,"\nFeel free to email me and tell me if you've used this software!\n"); + +fprintf(stdout,"\nThanks for bug reports go to: Philip Pi, Mark Gamar, Rich Kcsa, 'Rampant Badger', 'nibbles', 'deeice', Omair Eshkenazi, Matthias B, Ashish Disawal, Timo Juhani Lindfors, Abhisek Sanyal and others.\n"); +fprintf(stdout,"\nSpecial thanks to:\n"); +fprintf(stdout," 'legatvs' for clive (http://clive.sourceforge.net) another downloader into whose code I had to look to figure out how to get youtube and daily motion working again.\n"); +fprintf(stdout," Robert Crowley (http://oldcoder.org/) For all sorts of bug reports and advice.\n"); +} + + +int ParseType(char *Type) +{ +int i, result=TYPE_NONE; + +for (i=0; DownloadTypes[i] !=NULL; i++) +{ + if (strcasecmp(Type,DownloadTypes[i])==0) result=i; +} +return(result); +} + + +void ParseCommandLine(int argc, char *argv[], ListNode *DL_List, int *OverrideType) +{ +int i,j, DebugLevel=0; +char *ptr; + +ProgName=CopyStr(ProgName,argv[0]); +CmdLine=argv[0]; + + +for (i=1; i < argc; i++) +{ + if (strcmp(argv[i],"-p")==0) Proxy=CopyStr(Proxy,argv[++i]); + else if (strcmp(argv[i],"-proxy")==0) Proxy=CopyStr(Proxy,argv[++i]); + else if (strcmp(argv[i],"-a")==0) + { + ptr=GetToken(argv[++i],":",&Username,0); + ptr=GetToken(ptr,":",&Password,0); + } + else if (strcmp(argv[i],"-v")==0) + { + DebugLevel++; + } + else if (strcmp(argv[i],"-o")==0) + { + i++; + AddOutputFile(argv[i], TRUE); + if (strcmp(argv[i],"-")==0) Flags |= FLAG_STDOUT; + } + else if (strcmp(argv[i],"+o")==0) + { + i++; + AddOutputFile(argv[i], FALSE); + if (strcmp(argv[i],"-")==0) Flags |= FLAG_STDOUT; + } + else if (strcmp(argv[i],"-n")==0) + { + ItemSelectionArg=CopyStr(ItemSelectionArg,argv[++i]); + } + else if (strcmp(argv[i],"-t")==0) *OverrideType=ParseType(argv[++i]); + else if (strcmp(argv[i],"-f")==0) FormatPreference=CopyStr(FormatPreference,argv[++i]); + else if (strcmp(argv[i],"-q")==0) Flags |= FLAG_QUIET; + else if (strcmp(argv[i],"-b")==0) Flags |= FLAG_BACKGROUND; + else if (strcmp(argv[i],"-r")==0) Flags |= FLAG_RESUME; + else if (strcmp(argv[i],"-x")==0) Flags |= FLAG_PORN; + else if (strcmp(argv[i],"-T")==0) Flags |= FLAG_TEST; + else if (strcmp(argv[i],"-w")==0) Flags |= FLAG_STDIN; + else if (strcmp(argv[i],"-dt")==0) DisplayTitleWidth=atoi(argv[++i]); + else if (strcmp(argv[i],"-np")==0) NowPlayingFile=CopyStr(NowPlayingFile, argv[++i]); + else if (strcmp(argv[i],"-st")==0) STREAMTimeout=atoi(argv[++i]); + else if (strcmp(argv[i],"-P")==0) Player=CopyStr(Player,argv[++i]); + else if (strcmp(argv[i],"-Pp")==0) PlayerLaunchPercent=atoi(argv[++i]); + else if (strcmp(argv[i],"-U")==0) UserAgent=CopyStr(UserAgent, argv[++i]); + else if (strcmp(argv[i],"-?")==0) Flags |= FLAG_PRINT_USAGE; + else if (strcmp(argv[i],"-h")==0) Flags |= FLAG_PRINT_USAGE; + else if (strcmp(argv[i],"-help")==0) Flags |= FLAG_PRINT_USAGE; + else if (strcmp(argv[i],"--help")==0) Flags |= FLAG_PRINT_USAGE; + else if (strcmp(argv[i],"-version")==0) Flags |= FLAG_PRINT_VERSION; + else if (strcmp(argv[i],"--version")==0) Flags |= FLAG_PRINT_VERSION; + else if (strcmp(argv[i],"-test-sites")==0) + { + Flags |= FLAG_TEST_SITES | FLAG_QUIET; + for (j=1; TestLinks[j] !=NULL; j++) + { + if (StrLen(TestLinks[j])) ListAddNamedItem(DL_List,DownloadTypes[j],CopyStr(NULL,TestLinks[j])); + + } + ItemSelectionArg=CopyStr(ItemSelectionArg,"0"); + } + else + { + ListAddItem(DL_List,CopyStr(NULL,argv[i])); + } + +} + + +if (Flags & FLAG_BACKGROUND) +{ +Flags |= FLAG_QUIET; +demonize(); +} + +if (Flags & FLAG_QUIET) DebugLevel=0; + +if (DebugLevel==1) Flags |= FLAG_DEBUG1; +if (DebugLevel==2) Flags |= FLAG_DEBUG2; +if (DebugLevel > 2) Flags |= FLAG_DEBUG3; +} + +void CheckSettings() +{ +char *Token=NULL, *ptr; +int i; + +if ((! isatty(1)) && (! (Flags & FLAG_STDOUT))) +{ +fprintf(stderr,"\nWARNING: Stdout does not seem to be a terminal, so it could be a pipe to another program. But you've not used '-o -' or '+o -' to redirect output into a pipe. Hence output will be written to a file. If you're piping into a player app, and there's no sound/video, then you need to add '-o -'\n\n"); +} + +DestroyString(Token); +} + + +void ParseEnvironmentVariables() +{ +char *Tempstr=NULL; + +Tempstr=CopyStr(Tempstr,getenv("http_proxy")); +if (StrLen(Tempstr)) +{ + if ( + (strncasecmp(Tempstr,"http:",5) !=0) && + (strncasecmp(Tempstr,"https:",6) !=0) + ) Proxy=MCopyStr(Proxy,"http:",Tempstr,NULL); + else Proxy=CopyStr(Proxy,Tempstr); +} +else +{ + Tempstr=CopyStr(Tempstr,getenv("ssh_tunnel")); + if (StrLen(Tempstr)) + { + if (strncasecmp(Tempstr,"sshtunnel:",10)==0) Proxy=CopyStr(Proxy,Tempstr); + else if (strncasecmp(Tempstr,"ssh:",4)==0) Proxy=MCopyStr(Proxy,"sshtunnel:",Tempstr+4,NULL); + else Proxy=MCopyStr(Proxy,"sshtunnel:",Tempstr,NULL); + } +} + +DestroyString(Tempstr); +} + diff --git a/settings.h b/settings.h new file mode 100644 index 0000000..ab9cd57 --- /dev/null +++ b/settings.h @@ -0,0 +1,14 @@ +#ifndef MOVGRAB_SETTINGS +#define MOVGRAB_SETTINGS + +#include "common.h" + +void PrintVersion(); +void PrintUsage(); +int ParseType(char *Type); +void ParseCommandLine(int argc, char *argv[], ListNode *DL_List, int *OverrideType); +void CheckSettings(); +void ParseEnvironmentVariables(); + +#endif +