Fixed some issues and cleaned up some code
This commit is contained in:
parent
4c6d31d5e4
commit
8826de2cf2
@ -47,9 +47,9 @@ class CalibreTools:
|
||||
return str(span.text).split('of')[1].strip()
|
||||
|
||||
@staticmethod
|
||||
def downloadBooks(ip_port, library_name, max=None, update=False, format=None, dlthread=1):
|
||||
def downloadBooks(ip_port, library_name, max=None, update=False, file_format=None, dlthread=1):
|
||||
downloaded_books = 0
|
||||
CalibreTools.getBooksLink(ip_port, library_name, 25, max, update, format)
|
||||
CalibreTools.getBooksLink(ip_port, library_name, 25, max, update, file_format)
|
||||
total_book_links = sum(1 for line in open(ip_port + " " + library_name + " links.txt"))
|
||||
directory_ip = "'"
|
||||
if re.match('^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d+$', ip_port):
|
||||
@ -77,7 +77,7 @@ class CalibreTools:
|
||||
TerminalInterface.runInterfaceSchedule()
|
||||
|
||||
@staticmethod
|
||||
def getBooksLink(ip_port, library_name, multiple, max, update, format):
|
||||
def getBooksLink(ip_port, library_name, multiple, max, update, file_format):
|
||||
n_books = int(CalibreTools.getTotalBooks(ip_port, library_name))
|
||||
if max is not None:
|
||||
n_books = max
|
||||
@ -93,8 +93,8 @@ class CalibreTools:
|
||||
request = requests.get(f'http://{ip_port}/mobile?sort=timestamp&library_id={library_name}&num={n_books}&order=descending&start={start}')
|
||||
soup = BeautifulSoup(request.text, features='html.parser')
|
||||
links_soup = soup.findAll('a', attrs={'href': re.compile('\\.epub|\\.pdf|\\.mobi|\\.cbr')})
|
||||
if format != None:
|
||||
links_soup = soup.findAll('a', attrs={'href': re.compile(format)})
|
||||
if file_format is not None:
|
||||
links_soup = soup.findAll('a', attrs={'href': re.compile(file_format)})
|
||||
for link in links_soup:
|
||||
download_link = f'http://{ip_port}{link.get("href")}'
|
||||
with open((ip_port + " " + library_name + " links.txt"), "a") as f:
|
||||
|
16
main.py
16
main.py
@ -16,14 +16,12 @@ def validateArgs(parser, args):
|
||||
def calibre_implementation(ip_port):
|
||||
printInfo("Checking if server is accessible")
|
||||
if not CalibreTools.checkServer(ip_port):
|
||||
printError("Server requires authentication.")
|
||||
printError("Server requires authentication. Or is not accessible")
|
||||
exit(0)
|
||||
printSuccess("Server is accessible")
|
||||
printInfo("Getting Libraries")
|
||||
libraries = []
|
||||
thr = 1
|
||||
if args.lib is None:
|
||||
# TODO: Export to a txt file to free up ram once completed
|
||||
libraries = CalibreTools.getLibraries(ip_port)
|
||||
if len(libraries) == 0:
|
||||
printError("Could not find any libraries")
|
||||
@ -31,30 +29,26 @@ def calibre_implementation(ip_port):
|
||||
printSuccess(f'Found {len(libraries)} libraries')
|
||||
else:
|
||||
libraries.append(args.lib)
|
||||
if args.thread is not None:
|
||||
thr = args.thread
|
||||
for library in libraries:
|
||||
printInfo(f'Counting books from library: {library}')
|
||||
CalibreTools.downloadBooks(ip_port, library, None, update, format, thr)
|
||||
CalibreTools.downloadBooks(ip_port, library, None, args.update, args.file_format, args.thread)
|
||||
printSuccess("Download Complete!")
|
||||
exit(0)
|
||||
|
||||
# TODO: Add support to specify what format you want to download.
|
||||
# Ex. -f epub,pdf
|
||||
# -f epub
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser("Calibre Dumper")
|
||||
parser.add_argument('-c', '--calibre-host', type=str, dest='ip_port', action='store', help='Provide ip and port of calibre server, Format ip:port')
|
||||
parser.add_argument('-l', '--library', type=str, dest='lib', action='store', help='Specify which library to download')
|
||||
parser.add_argument('-t', '--threads', type=int, dest='thread', action='store', help='Specify how many download threads to use')
|
||||
parser.add_argument('-f', '--format', type=str, dest='format', action='store', help='Specify what format youd like to download. Ex. \\.epub|\\.mobi|\\.pdf')
|
||||
parser.add_argument('-f', '--format', type=str, dest='file_format', action='store', help='Specify what format youd like to download. Ex. \\.epub|\\.mobi|\\.pdf')
|
||||
parser.add_argument('-u', '--update', type=bool, dest='update', action='store', help='Force Scraper to get updated list of books')
|
||||
parser.usage = '''
|
||||
CALIBRE DUMPER
|
||||
1. Download all books from all libraries of calibre server using --calibre-host <IP:PORT> or -c <IP:PORT>
|
||||
2. Specify library using --library <LIBRARY NAME> or -l <LIBRARY NAME>
|
||||
4. Specify what format youd like to download. Ex -f Ex. \\.epub|\\.mobi|\\.pdf
|
||||
3. Specify how many download threads to use --threads <NUMBER> or -t <NUMBER>
|
||||
4. Specify what format youd like to download. Ex -f Ex. \\.epub|\\.mobi|\\.pdf
|
||||
5. Whether you'd like to update the list of download links
|
||||
'''
|
||||
args = parser.parse_args()
|
||||
validateArgs(parser, args)
|
||||
|
Loading…
Reference in New Issue
Block a user