feat: allow setting of downloaddir
This commit is contained in:
@@ -25,6 +25,7 @@ class GBConvert():
|
|||||||
url:str,
|
url:str,
|
||||||
author:str = None,
|
author:str = None,
|
||||||
title:str = None,
|
title:str = None,
|
||||||
|
downloaddir = './',
|
||||||
showprogress:bool = False,
|
showprogress:bool = False,
|
||||||
):
|
):
|
||||||
# NOTE move non-code files to data folder
|
# NOTE move non-code files to data folder
|
||||||
@@ -32,8 +33,10 @@ class GBConvert():
|
|||||||
with open(pkg_resources.files('epub2go').joinpath('blocklist.txt')) as blocklist:
|
with open(pkg_resources.files('epub2go').joinpath('blocklist.txt')) as blocklist:
|
||||||
self.blocklist = blocklist.read().splitlines()
|
self.blocklist = blocklist.read().splitlines()
|
||||||
self.tocpage = os.path.dirname(url) # ToC website url
|
self.tocpage = os.path.dirname(url) # ToC website url
|
||||||
self.url = urlparse(self.tocpage)
|
url = urlparse(self.tocpage)
|
||||||
self.output = self.url.netloc + self.url.path # directories created by wget recreating the URL
|
self.dir_download = downloaddir
|
||||||
|
self.dir_output = os.path.join(self.dir_download, url.netloc + url.path )# directories created by wget recreating the URL
|
||||||
|
logger.debug('Downloading in %s, expecting files in in %s', self.dir_download, self.dir_output)
|
||||||
self.showprogress = showprogress
|
self.showprogress = showprogress
|
||||||
self.author = author
|
self.author = author
|
||||||
self.title = title
|
self.title = title
|
||||||
@@ -87,7 +90,7 @@ class GBConvert():
|
|||||||
--metadata author="{self.author}" \
|
--metadata author="{self.author}" \
|
||||||
--epub-title-page=false \
|
--epub-title-page=false \
|
||||||
{" ".join(self.chapters)} '''
|
{" ".join(self.chapters)} '''
|
||||||
return subprocess.Popen(shlex.split(command), cwd=self.output).returncode
|
return subprocess.run(shlex.split(command), cwd=self.dir_output).returncode
|
||||||
|
|
||||||
def save_page(self, url):
|
def save_page(self, url):
|
||||||
logger.debug('Saving page at %s', url)
|
logger.debug('Saving page at %s', url)
|
||||||
@@ -99,7 +102,7 @@ class GBConvert():
|
|||||||
--tries=5 \
|
--tries=5 \
|
||||||
--quiet \
|
--quiet \
|
||||||
{url}'''
|
{url}'''
|
||||||
os.system(command)
|
return subprocess.run(shlex.split(command), cwd=self.dir_download).returncode
|
||||||
def run(self):
|
def run(self):
|
||||||
#TODO include images flag
|
#TODO include images flag
|
||||||
|
|
||||||
@@ -107,7 +110,7 @@ class GBConvert():
|
|||||||
for item in (tqdm(self.toc) if self.showprogress else self.toc):
|
for item in (tqdm(self.toc) if self.showprogress else self.toc):
|
||||||
item_url = self.parse_toc_entry(item)
|
item_url = self.parse_toc_entry(item)
|
||||||
parsed_url = urlparse(item_url)
|
parsed_url = urlparse(item_url)
|
||||||
filepath = parsed_url.netloc + parsed_url.path
|
filepath = os.path.join(self.dir_download, parsed_url.netloc + parsed_url.path)
|
||||||
self.parse_page(filepath)
|
self.parse_page(filepath)
|
||||||
self.chapters.append(os.path.basename(item_url))
|
self.chapters.append(os.path.basename(item_url))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user