aboutsummaryrefslogtreecommitdiff
path: root/src/wikiget/dl.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/wikiget/dl.py')
-rw-r--r--src/wikiget/dl.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/wikiget/dl.py b/src/wikiget/dl.py
index 8f32218..9850ce8 100644
--- a/src/wikiget/dl.py
+++ b/src/wikiget/dl.py
@@ -24,8 +24,8 @@ from mwclient import APIError, InvalidResponse, LoginError, Site
from requests import ConnectionError, HTTPError
from tqdm import tqdm
-from . import CHUNKSIZE, DEFAULT_SITE, USER_AGENT
-from .validations import valid_file, verify_hash
+import wikiget
+from wikiget.validations import valid_file, verify_hash
def download(dl, args):
@@ -34,7 +34,7 @@ def download(dl, args):
if url.netloc:
filename = url.path
site_name = url.netloc
- if args.site is not DEFAULT_SITE:
+ if args.site is not wikiget.DEFAULT_SITE:
# this will work even if the user specifies 'commons.wikimedia.org'
logging.warning("target is a URL, "
"ignoring site specified with --site")
@@ -57,12 +57,12 @@ def download(dl, args):
dest = args.output or filename
- logging.debug(f"User agent: {USER_AGENT}")
+ logging.debug(f"User agent: {wikiget.USER_AGENT}")
# connect to site and identify ourselves
logging.info(f"Site name: {site_name}")
try:
- site = Site(site_name, path=args.path, clients_useragent=USER_AGENT)
+ site = Site(site_name, path=args.path, clients_useragent=wikiget.USER_AGENT)
if args.username and args.password:
site.login(args.username, args.password)
except ConnectionError as e:
@@ -119,24 +119,28 @@ def download(dl, args):
else:
try:
fd = open(dest, "wb")
- except IOError as e:
+ except OSError as e:
logging.error("File could not be written. "
"The following error was encountered:")
logging.error(e)
sys.exit(1)
else:
# download the file(s)
- if args.verbose >= 1:
+ if args.verbose >= wikiget.STD_VERBOSE:
leave_bars = True
else:
leave_bars = False
- with tqdm(leave=leave_bars, total=file_size,
- unit="B", unit_scale=True,
- unit_divisor=CHUNKSIZE) as progress_bar:
+ with tqdm(
+ leave=leave_bars,
+ total=file_size,
+ unit="B",
+ unit_scale=True,
+ unit_divisor=wikiget.CHUNKSIZE,
+ ) as progress_bar:
with fd:
res = site.connection.get(file_url, stream=True)
progress_bar.set_postfix(file=dest, refresh=False)
- for chunk in res.iter_content(CHUNKSIZE):
+ for chunk in res.iter_content(wikiget.CHUNKSIZE):
fd.write(chunk)
progress_bar.update(len(chunk))