Add proxy parameter to res download function
parent
f887f5fd84
commit
3a7ffaef6d
|
@ -5,14 +5,15 @@ import zipfile
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import lokrez.characters_ssbu as characters_ssbu
|
from .characters_ssbu import EVERYONE
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def download_file(url, with_progressbar = True):
|
def download_file(url, with_progressbar = True, proxy = None):
|
||||||
|
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
url,
|
url,
|
||||||
stream = with_progressbar,
|
stream = with_progressbar,
|
||||||
|
proxies = { "https": proxy, "http": proxy },
|
||||||
)
|
)
|
||||||
|
|
||||||
if not with_progressbar:
|
if not with_progressbar:
|
||||||
|
@ -44,7 +45,7 @@ def download_file(url, with_progressbar = True):
|
||||||
return f
|
return f
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def download_res_ssbu(dstdir, log=None):
|
def download_res_ssbu(dstdir, proxy = None, log=None):
|
||||||
"""Downloads SSBU resources from spriters and rename them according to
|
"""Downloads SSBU resources from spriters and rename them according to
|
||||||
lokrez expectations"""
|
lokrez expectations"""
|
||||||
|
|
||||||
|
@ -53,11 +54,11 @@ def download_res_ssbu(dstdir, log=None):
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# Download stock icons
|
# Download stock icons
|
||||||
log.info("Downloading stock icons...")
|
log.info("Downloading stock icons...")
|
||||||
fstocks = download_file(stock_icons_url)
|
fstocks = download_file(stock_icons_url, proxy = proxy)
|
||||||
zfstocks = zipfile.ZipFile(fstocks)
|
zfstocks = zipfile.ZipFile(fstocks)
|
||||||
|
|
||||||
# Iter over each character
|
# Iter over each character
|
||||||
for character in characters_ssbu.EVERYONE:
|
for character in EVERYONE:
|
||||||
log.info("Downloading images for {}...".format(character.name))
|
log.info("Downloading images for {}...".format(character.name))
|
||||||
|
|
||||||
# Create directory for this character
|
# Create directory for this character
|
||||||
|
@ -82,7 +83,7 @@ def download_res_ssbu(dstdir, log=None):
|
||||||
|
|
||||||
# Download urls & write image files
|
# Download urls & write image files
|
||||||
for url in character.spritersurls:
|
for url in character.spritersurls:
|
||||||
f = download_file(url)
|
f = download_file(url, proxy = proxy)
|
||||||
with zipfile.ZipFile(f) as zfchar:
|
with zipfile.ZipFile(f) as zfchar:
|
||||||
for zf in [zfchar,zfstocks]:
|
for zf in [zfchar,zfstocks]:
|
||||||
for source_filename in zf.namelist():
|
for source_filename in zf.namelist():
|
||||||
|
|
Loading…
Reference in New Issue