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 absolute_import
, division
, print_function
, unicode_literals
, generators
, with_statement
, nested_scopes
26 __project__
= pywwwget
.__project
__
27 __program_name__
= pywwwget
.__program
_name
__
28 __project_url__
= pywwwget
.__project
_url
__
29 __version_info__
= pywwwget
.__version
_info
__
30 __version_date_info__
= pywwwget
.__version
_date
_info
__
31 __version_date__
= pywwwget
.__version
_date
__
32 __version_date_plusrc__
= pywwwget
.__version
_date
_plusrc
__
33 __version__
= pywwwget
.__version
__
34 __version_date_plusrc__
= pywwwget
.__version
_date
_plusrc
__
36 geturls_cj
= pywwwget
.geturls_cj
37 geturls_ua
= pywwwget
.geturls_ua
38 geturls_ua_firefox_windows7
= pywwwget
.geturls_ua_firefox_windows7
39 geturls_ua_seamonkey_windows7
= pywwwget
.geturls_ua_seamonkey_windows7
40 geturls_ua_chrome_windows7
= pywwwget
.geturls_ua_chrome_windows7
41 geturls_ua_chromium_windows7
= pywwwget
.geturls_ua_chromium_windows7
42 geturls_ua_palemoon_windows7
= pywwwget
.geturls_ua_palemoon_windows7
43 geturls_ua_opera_windows7
= pywwwget
.geturls_ua_opera_windows7
44 geturls_ua_vivaldi_windows7
= pywwwget
.geturls_ua_chromium_windows7
45 geturls_ua_internet_explorer_windows7
= pywwwget
.geturls_ua_internet_explorer_windows7
46 geturls_ua_microsoft_edge_windows7
= pywwwget
.geturls_ua_microsoft_edge_windows7
47 geturls_ua_pywwwget_python
= pywwwget
.geturls_ua_pywwwget_python
48 geturls_ua_pywwwget_python_alt
= pywwwget
.geturls_ua_pywwwget_python_alt
49 geturls_ua_googlebot_google
= pywwwget
.geturls_ua_googlebot_google
50 geturls_ua_googlebot_google_old
= pywwwget
.geturls_ua_googlebot_google_old
51 geturls_headers
= pywwwget
.geturls_headers
52 geturls_headers_firefox_windows7
= pywwwget
.geturls_headers_firefox_windows7
53 geturls_headers_seamonkey_windows7
= pywwwget
.geturls_headers_seamonkey_windows7
54 geturls_headers_chrome_windows7
= pywwwget
.geturls_headers_chrome_windows7
55 geturls_headers_chromium_windows7
= pywwwget
.geturls_headers_chromium_windows7
56 geturls_headers_palemoon_windows7
= pywwwget
.geturls_headers_palemoon_windows7
57 geturls_headers_opera_windows7
= pywwwget
.geturls_headers_opera_windows7
58 geturls_headers_vivaldi_windows7
= pywwwget
.geturls_headers_vivaldi_windows7
59 geturls_headers_internet_explorer_windows7
= pywwwget
.geturls_headers_internet_explorer_windows7
60 geturls_headers_microsoft_edge_windows7
= pywwwget
.geturls_headers_microsoft_edge_windows7
61 geturls_headers_pywwwget_python
= pywwwget
.geturls_headers_pywwwget_python
62 geturls_headers_pywwwget_python_alt
= pywwwget
.geturls_headers_pywwwget_python_alt
63 geturls_headers_googlebot_google
= pywwwget
.geturls_headers_googlebot_google
64 geturls_headers_googlebot_google_old
= pywwwget
.geturls_headers_googlebot_google_old
65 geturls_download_sleep
= pywwwget
.geturls_download_sleep
67 parser
= argparse
.ArgumentParser(
68 description
="Python libary/module to download files.", conflict_handler
="resolve", add_help
=True)
69 parser
.add_argument("url", help="enter a url")
70 parser
.add_argument("-V", "--version", action
="version",
71 version
=__program_name__
+" "+__version__
)
72 parser
.add_argument("-u", "--update", action
="store_true",
73 help="update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)")
74 parser
.add_argument("-d", "--dump-user-agent", action
="store_true",
75 help="display the current browser identification")
76 parser
.add_argument("-u", "--user-agent", default
=geturls_ua_firefox_windows7
,
77 help="specify a custom user agent")
78 parser
.add_argument("-r", "--referer", default
="https://www.google.com/",
79 help="specify a custom referer, use if the video access")
80 parser
.add_argument("-O", "--output-document", default
="-",
81 help="specify a file name for output")
82 parser
.add_argument("-o", "--output-directory", default
=os
.path
.realpath(
83 os
.getcwd()), help="specify a directory to output file to")
84 parser
.add_argument("-l", "--use-httplib", default
="urllib",
85 help="select library to download file can be urllib or requests or mechanize")
86 parser
.add_argument("-b", "--set-buffersize", default
=524288, type=int,
87 help="set how big buffersize is in bytes. how much it will download")
88 parser
.add_argument("-t", "--timeout", default
=10, type=int,
89 help="set timeout time for http request")
90 parser
.add_argument("-s", "--sleep", default
=10, type=int,
91 help="set sleep time for request")
92 parser
.add_argument("-v", "--verbose", action
="store_true",
93 help="print various debugging information")
94 getargs
= parser
.parse_args()
96 if(not pywwwget
.check_httplib_support(getargs
.use_httplib
)):
97 getargs
.use_httplib
= "urllib"
99 getargs_cj
= geturls_cj
100 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",
101 '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"}
103 getargs
.output_directory
= os
.path
.realpath(getargs
.output_directory
)
105 if(getargs
.verbose
== True):
106 log
.basicConfig(format
="%(levelname)s: %(message)s", level
=log
.DEBUG
)
108 if(getargs
.dump_user_agent
== True):
109 print(getargs
.user_agent
)
112 if(getargs
.output_document
== "-"):
113 if(sys
.version
[0] == "2"):
114 precontstr
= pywwwget
.download_from_url_to_file(getargs
.url
, getargs_headers
, getargs
.user_agent
, getargs
.referer
, geturls_cj
, httplibuse
=getargs
.use_httplib
, buffersize
=[
115 getargs
.set_buffersize
, getargs
.set_buffersize
], outfile
=getargs
.output_document
, outpath
=os
.getcwd(), sleep
=getargs
.sleep
, timeout
=getargs
.timeout
)
116 print(precontstr
['Content'])
117 if(sys
.version
[0] >= "3"):
118 precontstr
= pywwwget
.download_from_url_to_file(getargs
.url
, getargs_headers
, getargs
.user_agent
, getargs
.referer
, geturls_cj
, httplibuse
=getargs
.use_httplib
, buffersize
=[
119 getargs
.set_buffersize
, getargs
.set_buffersize
], outfile
=getargs
.output_document
, outpath
=os
.getcwd(), sleep
=getargs
.sleep
, timeout
=getargs
.timeout
)
120 print(precontstr
['Content'].decode('ascii', 'replace'))
122 if(getargs
.output_document
!= "-"):
123 pywwwget
.download_from_url_to_file(getargs
.url
, getargs_headers
, getargs
.user_agent
, getargs
.referer
, geturls_cj
, httplibuse
=getargs
.use_httplib
, buffersize
=[
124 getargs
.set_buffersize
, getargs
.set_buffersize
], outfile
=getargs
.output_document
, outpath
=getargs
.output_directory
, sleep
=getargs
.sleep
, timeout
=getargs
.timeout
)