4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2016-2023 Game Maker 2k - https://github.com/GameMaker2k
13 Copyright 2016-2023 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
15 $FileInfo: pywwwget-dl.py - Last Update: 10/5/2023 Ver. 2.0.2 RC 1 - Author: cooldude2k $
18 from __future__
import division
, absolute_import
, print_function
;
19 import re
, os
, sys
, pywwwget
, argparse
;
20 import logging
as log
;
22 __project__
= pywwwget
.__project
__;
23 __program_name__
= pywwwget
.__program
_name
__;
24 __project_url__
= pywwwget
.__project
_url
__;
25 __version_info__
= pywwwget
.__version
_info
__;
26 __version_date_info__
= pywwwget
.__version
_date
_info
__;
27 __version_date__
= pywwwget
.__version
_date
__;
28 __version_date_plusrc__
= pywwwget
.__version
_date
_plusrc
__
29 __version__
= pywwwget
.__version
__;
30 __version_date_plusrc__
= pywwwget
.__version
_date
_plusrc
__;
32 geturls_cj
= pywwwget
.geturls_cj
;
33 geturls_ua
= pywwwget
.geturls_ua
;
34 geturls_ua_firefox_windows7
= pywwwget
.geturls_ua_firefox_windows7
;
35 geturls_ua_seamonkey_windows7
= pywwwget
.geturls_ua_seamonkey_windows7
;
36 geturls_ua_chrome_windows7
= pywwwget
.geturls_ua_chrome_windows7
;
37 geturls_ua_chromium_windows7
= pywwwget
.geturls_ua_chromium_windows7
;
38 geturls_ua_palemoon_windows7
= pywwwget
.geturls_ua_palemoon_windows7
;
39 geturls_ua_opera_windows7
= pywwwget
.geturls_ua_opera_windows7
;
40 geturls_ua_vivaldi_windows7
= pywwwget
.geturls_ua_chromium_windows7
;
41 geturls_ua_internet_explorer_windows7
= pywwwget
.geturls_ua_internet_explorer_windows7
;
42 geturls_ua_microsoft_edge_windows7
= pywwwget
.geturls_ua_microsoft_edge_windows7
;
43 geturls_ua_pywwwget_python
= pywwwget
.geturls_ua_pywwwget_python
;
44 geturls_ua_pywwwget_python_alt
= pywwwget
.geturls_ua_pywwwget_python_alt
;
45 geturls_ua_googlebot_google
= pywwwget
.geturls_ua_googlebot_google
;
46 geturls_ua_googlebot_google_old
= pywwwget
.geturls_ua_googlebot_google_old
;
47 geturls_headers
= pywwwget
.geturls_headers
;
48 geturls_headers_firefox_windows7
= pywwwget
.geturls_headers_firefox_windows7
;
49 geturls_headers_seamonkey_windows7
= pywwwget
.geturls_headers_seamonkey_windows7
;
50 geturls_headers_chrome_windows7
= pywwwget
.geturls_headers_chrome_windows7
;
51 geturls_headers_chromium_windows7
= pywwwget
.geturls_headers_chromium_windows7
;
52 geturls_headers_palemoon_windows7
= pywwwget
.geturls_headers_palemoon_windows7
;
53 geturls_headers_opera_windows7
= pywwwget
.geturls_headers_opera_windows7
;
54 geturls_headers_vivaldi_windows7
= pywwwget
.geturls_headers_vivaldi_windows7
;
55 geturls_headers_internet_explorer_windows7
= pywwwget
.geturls_headers_internet_explorer_windows7
;
56 geturls_headers_microsoft_edge_windows7
= pywwwget
.geturls_headers_microsoft_edge_windows7
;
57 geturls_headers_pywwwget_python
= pywwwget
.geturls_headers_pywwwget_python
;
58 geturls_headers_pywwwget_python_alt
= pywwwget
.geturls_headers_pywwwget_python_alt
;
59 geturls_headers_googlebot_google
= pywwwget
.geturls_headers_googlebot_google
;
60 geturls_headers_googlebot_google_old
= pywwwget
.geturls_headers_googlebot_google_old
;
61 geturls_download_sleep
= pywwwget
.geturls_download_sleep
;
63 parser
= argparse
.ArgumentParser(description
="Python libary/module to download files.", conflict_handler
="resolve", add_help
=True);
64 parser
.add_argument("url", help="enter a url");
65 parser
.add_argument("-V", "--version", action
="version", version
=__program_name__
+" "+__version__
);
66 parser
.add_argument("-u", "--update", action
="store_true", help="update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)");
67 parser
.add_argument("-d", "--dump-user-agent", action
="store_true", help="display the current browser identification");
68 parser
.add_argument("-u", "--user-agent", default
=geturls_ua_firefox_windows7
, help="specify a custom user agent");
69 parser
.add_argument("-r", "--referer", default
="https://www.google.com/", help="specify a custom referer, use if the video access");
70 parser
.add_argument("-O", "--output-document", default
="-", help="specify a file name for output");
71 parser
.add_argument("-o", "--output-directory", default
=os
.path
.realpath(os
.getcwd()), help="specify a directory to output file to");
72 parser
.add_argument("-l", "--use-httplib", default
="urllib", help="select library to download file can be urllib or requests or mechanize");
73 parser
.add_argument("-b", "--set-buffersize", default
=524288, type=int, help="set how big buffersize is in bytes. how much it will download");
74 parser
.add_argument("-t", "--timeout", default
=10, type=int, help="set timeout time for http request");
75 parser
.add_argument("-s", "--sleep", default
=10, type=int, help="set sleep time for request");
76 parser
.add_argument("-v", "--verbose", action
="store_true", help="print various debugging information");
77 getargs
= parser
.parse_args();
79 if(not pywwwget
.check_httplib_support(getargs
.use_httplib
)):
80 getargs
.use_httplib
= "urllib";
82 getargs_cj
= geturls_cj
;
83 getargs_headers
= {'Referer': getargs
.referer
, 'User-Agent': getargs
.user_agent
, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
85 getargs
.output_directory
= os
.path
.realpath(getargs
.output_directory
);
87 if(getargs
.verbose
==True):
88 log
.basicConfig(format
="%(levelname)s: %(message)s", level
=log
.DEBUG
);
90 if(getargs
.dump_user_agent
==True):
91 print(getargs
.user_agent
);
94 if(getargs
.output_document
=="-"):
95 if(sys
.version
[0]=="2"):
96 precontstr
= pywwwget
.download_from_url_to_file(getargs
.url
, getargs_headers
, getargs
.user_agent
, getargs
.referer
, geturls_cj
, httplibuse
=getargs
.use_httplib
, buffersize
=[getargs
.set_buffersize
, getargs
.set_buffersize
], outfile
=getargs
.output_document
, outpath
=os
.getcwd(), sleep
=getargs
.sleep
, timeout
=getargs
.timeout
);
97 print(precontstr
['Content']);
98 if(sys
.version
[0]>="3"):
99 precontstr
= pywwwget
.download_from_url_to_file(getargs
.url
, getargs_headers
, getargs
.user_agent
, getargs
.referer
, geturls_cj
, httplibuse
=getargs
.use_httplib
, buffersize
=[getargs
.set_buffersize
, getargs
.set_buffersize
], outfile
=getargs
.output_document
, outpath
=os
.getcwd(), sleep
=getargs
.sleep
, timeout
=getargs
.timeout
);
100 print(precontstr
['Content'].decode('ascii', 'replace'));
102 if(getargs
.output_document
!="-"):
103 pywwwget
.download_from_url_to_file(getargs
.url
, getargs_headers
, getargs
.user_agent
, getargs
.referer
, geturls_cj
, httplibuse
=getargs
.use_httplib
, buffersize
=[getargs
.set_buffersize
, getargs
.set_buffersize
], outfile
=getargs
.output_document
, outpath
=getargs
.output_directory
, sleep
=getargs
.sleep
, timeout
=getargs
.timeout
);